複数の GeoJSON ファイルをマージ(jq 利用)


こんにちは。
複数の GeoJSON ファイルのデータをマージ(合体、連結)させて一つのファイルを作りました(jq コマンドを利用、対象ファイル例は *geo.json)。

$ jq '.features[]' *geo.json | jq -s '{"type":"FeatureCollection", "features":.}' > merged_geo.json
  • また条件抽出も加えてみました(この例は properties.name != "" )。
$ jq '.features[]' *geo.json | jq -s -c 'map(select(.properties.name != ""))[] ' | jq -s '{"type":"FeatureCollection", "features":.}' > merged_geo.json 

GeoJSONL(cat コマンド利用)

なお Newline-delimited GeoJSON (GeoJSONL) ファイルならばcatコマンドで実現できます(対象ファイル例は *geo.jsonl)。

$ cat *geo.jsonl > merged_geo.jsonl
  • また条件抽出も加えてみました(この例は properties.name != "" )。
$ cat *geo.jsonl | jq -s -c 'map(select(.properties.name != ""))[] ' > merged_geo.jsonl