11
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

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

Posted at

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"
      }
    }
  ]
}

11
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?