我想编写一个颠簸变换,如果类型是“多边形”,则将坐标值放入单个数组“坐标”中;如果类型是“点”,则将坐标值放入属性“x”、“y”、“z”中。我认为我接近当前的规格,但除了在 & 之后尝试不同的值之外,我不确定。
输入Json1
{
"features": [
{
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
11.1,
111.1
],
[
22.2,
222.2
],
[
33.3,
333.3
]
]
]
}
}
]
}
输入Json2
{
"features": [
{
"geometry": {
"type": "Point",
"coordinates": [
1.1,
2.2,
3.3
]
}
}
]
}
规格
[
{
"operation": "shift",
"spec": {
"features": {
"*": {
"geometry": {
"type": {
"Polygon": {
"coordinates": {
"*": "[&4].coordinates"
}
},
"Point": {
"coordinates": {
"0": "[&4].x",
"1": "[&4].y",
"2": "[&4].z"
}
}
}
}
}
}
}
}
]
预期输出:点
[ {
"x" : 1.1,
"y" : 2.2,
"z" : 3.3
} ]
预期输出:多边形
[ {
"coordinates" : [ [ 11.1, 111.1 ], [ 22.2, 222.2 ], [ 33.3, 333.3 ] ]
} ]
我尝试了上述规范,并期望得到显示坐标对象或 x、y、z 的输出。当我用
[&4]
替换 [&3]
并删除条件套管时,我可以让它单独处理每种情况,但有了它,我知道有一些我没有正确处理的复杂关卡。
您需要引用回类型键值之后的坐标值,该值是向上 2 级的 @(2,坐标) :
[
{
"operation": "shift",
"spec": {
"features": {
"*": {
"geometry": {
"type": {// level 2 where coordinates is located
"Polygon": {
"@(2,coordinates)": {
"*": "[&5].coordinates"
}
},
"Point": { //level 1
"@(2,coordinates)": { // level 0
"0": "[&5].x",
"1": "[&5].y",
"2": "[&5].z"
}
}
}
}
}
}
}
}
]