我有以下geojson文件:
{
"type": "FeatureCollection",
"features": [{
"type": "Feature",
"properties": {
"LINE": "RED",
"STATION": "Harvard"
},
"geometry": {
"type": "Point",
"coordinates": [-71.118906072378209, 42.37402923068516]
}
},
{
"type": "Feature",
"properties": {
"LINE": "RED",
"STATION": "Ashmont"
},
"geometry": {
"type": "Point",
"coordinates": [-71.063430144389983, 42.283883546225319]
}
}
]
}
我想将“功能”数组内的第二个对象附加到它的末尾,创建总共3个对象。使用以下代码段错误,将“数组([{“ type”:“ F ...)和对象({” type“:” Fe ...)添加在一起”。有没有办法做到这一点使用JQ没有硬编码的关键是:值对,看到这里?
cat red_line_nodes.json | jq '.features |= . + .[length-1]' > red_line_nodes_2.json
简短的jq
解决方案:
jq '.features |= . + [.[-1]]' red_line_nodes.json
输出:
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {
"LINE": "RED",
"STATION": "Harvard"
},
"geometry": {
"type": "Point",
"coordinates": [
-71.11890607237821,
42.37402923068516
]
}
},
{
"type": "Feature",
"properties": {
"LINE": "RED",
"STATION": "Ashmont"
},
"geometry": {
"type": "Point",
"coordinates": [
-71.06343014438998,
42.28388354622532
]
}
},
{
"type": "Feature",
"properties": {
"LINE": "RED",
"STATION": "Ashmont"
},
"geometry": {
"type": "Point",
"coordinates": [
-71.06343014438998,
42.28388354622532
]
}
}
]
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句