jq

jqコマンドでGeoJSONから特定のプロパティを削除する

More than 3 years have passed since last update.

GeoJSONを生成してから「あのプロパティいらんかったなー。あれだけ削除したいなー」ってときに使う。

cat example.geojson | jq "del(.features[].properties.<消したいkey>)" > example2.geojson 


サンプル

下記GeoJSONデータからnameを削除する


input

{

"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
0,
0
]
},
"properties": {
"label": "hoge",
"name": "hoge", //これ削除したい
"address": "tokyo"
}
},
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
10,
10
]
},
"properties": {
"label": "test",
"name": "test", //これ削除したい
"address": "takasaki"
}
},
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
20,
20
]
},
"properties": {
"label": "foo",
"name": "foo", //これ削除したい
"address": "tokyo"
}
}
]
}


jqを使ってnameプロパティを削除する

cat input.geojson | jq "del(.features[].properties.name)" > output.geojson

実行結果


output

{

"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
0,
0
]
},
"properties": {
"label": "hoge",
"address": "tokyo"
}
},
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
10,
10
]
},
"properties": {
"label": "test",
"address": "takasaki"
}
},
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
20,
20
]
},
"properties": {
"label": "foo",
"address": "tokyo"
}
}
]
}