Jolt Transform条件转换问题:按Geometry类型处理Coordinates
修正后的Jolt Transform Spec
针对你的需求,调整后的Jolt Spec如下,解决了层级引用问题,同时适配两种Geometry类型的输出格式:
[ { "operation": "shift", "spec": { "features": { "*": { "geometry": { "type": { "Polygon": { "@(2,coordinates[0])": "[&5].coordinates" }, "Point": { "@(2,coordinates[0])": "[&5].x", "@(2,coordinates[1])": "[&5].y", "@(2,coordinates[2])": "[&5].z" } } } } } } } ]
关键修正点说明
1. 层级引用错误修复
你之前使用的&4指向的是geometry节点,而我们需要将结果映射到features数组的当前元素上,因此需要改用&5(从当前Polygon/Point节点往上数5层,正好定位到features的数组项*)。
更推荐用@(2,coordinates)这种相对引用方式:@(2,xxx)表示向上跳2级(从Polygon/Point节点跳到geometry节点),直接引用同级的coordinates字段,避免手动数层级出错。
2. Polygon类型的coordinates格式适配
输入中Polygon的coordinates是三层数组([[[x,y],...]]),而预期输出是两层数组([[x,y],...]),因此通过coordinates[0]直接取最外层数组的第一个元素,匹配预期格式。
测试验证
针对Polygon类型输入
输入:
{ "features": [ { "geometry": { "type": "Polygon", "coordinates": [ [ [11.1,111.1], [22.2,222.2], [33.3,333.3] ] ] } } ] }
输出:
[ { "coordinates" : [ [ 11.1, 111.1 ], [ 22.2, 222.2 ], [ 33.3, 333.3 ] ] } ]
针对Point类型输入
输入:
{ "features": [ { "geometry": { "type": "Point", "coordinates": [1.1,2.2,3.3] } } ] }
输出:
[ { "x" : 1.1, "y" : 2.2, "z" : 3.3 } ]
内容的提问来源于stack exchange,提问作者con
相关产品推荐
相关产品推荐

