数组中的坐标在多个GeoJSON MultiLineString结构之间划分。我想合并所有坐标,将它们保存在自己的数组中,放在一个单一的MultiLineString结构下。如何使用jq实现这一点?
这是原始文件(出于示例目的而修改)
{
"type": "FeatureCollection",
"crs": {
"type": "name",
"properties": {
"name": "urn:ogc:def:crs:OGC:1.3:CRS84"
}
},
"features": [{
"type": "Feature",
"geometry": {
"type": "MultiLineString",
"coordinates": [
[
[-82.619152670413143, 29.568340757283536, 0.0],
[-82.619147188198966, 29.568355832670516, 0.0],
[-82.607558975018591, 29.580299204829011, 0.0]
]
]
}
},
{
"type": "Feature",
"geometry": {
"type": "MultiLineString",
"coordinates": [
[
[-82.619152670413513, 29.568340757283536, 0.0],
[-82.619490683489488, 29.568318912277654, 0.0],
[-82.629348688631055, 29.569000553128618, 0.0]
]
]
}
},
{
"type": "Feature",
"geometry": {
"type": "MultiLineString",
"coordinates": [
[
[-82.629348688631055, 29.569000553128618, 0.0],
[-82.62943243076478, 29.568922074598046, 0.0],
[-82.623065167913538, 29.56611193045412, 0.0]
]
]
}
},
{
"type": "Feature",
"geometry": {
"type": "MultiLineString",
"coordinates": [
[
[-82.618039923193663, 29.563657436904819, 0.0],
[-82.618306111861301, 29.565336028000189, 0.0],
[-82.619152670413669, 29.568340757283639, 0.0]
]
]
}
},
{
"type": "Feature",
"geometry": {
"type": "MultiLineString",
"coordinates": [
[
[-82.62306516791385, 29.566111930454156, 0.0],
[-82.618758856449034, 29.563742939021793, 0.0],
[-82.618212862210015, 29.563577318475456, 0.0]
]
]
}
}
]
}我想要实现的是:
{
"type": "FeatureCollection",
"crs": {
"type": "name",
"properties": {
"name": "urn:ogc:def:crs:OGC:1.3:CRS84"
}
},
"features": [{
"type": "Feature",
"geometry": {
"type": "MultiLineString",
"coordinates": [
[
[-82.619152670413143, 29.568340757283536, 0.0],
[-82.619147188198966, 29.568355832670516, 0.0],
[-82.607558975018591, 29.580299204829011, 0.0]
],
[
[-82.619152670413513, 29.568340757283536, 0.0],
[-82.619490683489488, 29.568318912277654, 0.0],
[-82.629348688631055, 29.569000553128618, 0.0]
],
[
[-82.629348688631055, 29.569000553128618, 0.0],
[-82.62943243076478, 29.568922074598046, 0.0],
[-82.623065167913538, 29.56611193045412, 0.0]
],
[
[-82.618039923193663, 29.563657436904819, 0.0],
[-82.618306111861301, 29.565336028000189, 0.0],
[-82.619152670413669, 29.568340757283639, 0.0]
],
[
[-82.62306516791385, 29.566111930454156, 0.0],
[-82.618758856449034, 29.563742939021793, 0.0],
[-82.618212862210015, 29.563577318475456, 0.0]
]
]
}
}
]
}发布于 2018-08-21 23:50:57
简单解决方案的关键是认识到组合的“坐标”数组可以由过滤器计算:
[.features[] | .geometry | .coordinates[]] 它可以缩写为:
[.features[].geometry.coordinates[]] 让我们将此数组命名为$combined。然后可以通过更新.features获得解决方案,如下所示:
.features = [.features[0] | (.geometry.coordinates = $combined)]一个完整的解决方案是:
[.features[].geometry.coordinates[]] as $combined
| .features = [.features[0] | (.geometry.coordinates = $combined)]这可以使用|=运算符进一步简化:
[.features[].geometry.coordinates[]] as $combined
| .features |= [.[0] | (.geometry.coordinates = $combined)]https://stackoverflow.com/questions/51951847
复制相似问题