#author("2020-07-30T17:50:17+09:00","default:nobuoki","nobuoki") #author("2020-07-30T17:53:45+09:00","default:nobuoki","nobuoki") * はじめに [#cbe3e566] データ変換のためだけにQGIS使うのが辛いのでCLIをよく使います なるべくOSの環境を変えないで済むよう(いつもの通り)コンテナにします 今回は shp2json, dbf2json です それぞれ shpファイル、dbfファイルをGeoJSONに変換するコマンドです - [[mbostock/shapefile: A cross-platform streaming parser for the ESRI Shapefile spatial data format.>https://github.com/mbostock/shapefile#command-line-reference]] この辺でさらっと紹介されてます - [[バイナリベクトルタイルを作ってみた - 水戸地図>https://cieloazul310.github.io/2017/08/cook-binary-vector-tiles/]] - [[TopoJSON v2, v3 チュートリアルその1 - Qiita>https://qiita.com/cieloazul310/items/9d0e3f67f60d791726dc]] * コンテナイメージをビルドする [#l5b35c1c] #prism(bash){{{ podman build https://gist.github.com/kemasoft-gist/bc28dce9906bf230b5757f03a22b2b91/raw -t kemasoft/shapefile }}} 参考:Dockerfile #gist(kemasoft-gist/bc28dce9906bf230b5757f03a22b2b91) 参考にさせて頂いたページ - [[DockerfileでPATHを通す時はRUNではなくENVを使おう - Qiita>https://qiita.com/TakashiOshikawa/items/2b8974c242a7054e0be5]] - [[Alpine Linux で軽量な Docker イメージを作る - Qiita>https://qiita.com/pottava/items/970d7b5cda565b995fe7]] - [[最小のNode.jsのDockerイメージを目指すスレ - Qiita>https://qiita.com/shibukawa/items/f7076cf4b181ee141bcd]] * 使いやすいようにaliasを切る [#n5f1494e] #prism(bash){{{ alias shp2json='podman run --rm -i -v .:/mnt kemasoft/shapefile shp2json' alias dbf2json='podman run --rm -i -v .:/mnt kemasoft/shapefile dbf2json' }}} * 使用例 [#k621f729] 国土地理院のデータを使う時は --encoding Shift_JIS を忘れないようにしましょう ** shp2json [#ef4bd76c] #prism(bash){{{ $ ls *.dbf 20200401-行政区画.dbf 20200401-行政区画界線.dbf 20200401-行政区画代表点.dbf 20200401-町字の代表点.dbf 20200401-町字界線.dbf $ shp2json --encoding Shift-JIS 20200401-行政区画代表点.shp | jq . | head -n20 { "type": "FeatureCollection", "bbox": [ 138.632616034, 35.75000175, 139.998345505, 36.331040108 ], "features": [ { "type": "Feature", "properties": { "id": "K6_5013013062_1", "fid": "50130-13062-i-1029", "整備データ": 20171204, "整備デーA": 0, "整備完了日": "20200307", "orgGILvl": "25000", "orgMDId": null, "表示区分": "非表示", }}} ** dbf2json [#n3ae6553] #prism(bash){{{ $ ls *.dbf 20200401-行政区画.dbf 20200401-行政区画界線.dbf 20200401-行政区画代表点.dbf 20200401-町字の代表点.dbf 20200401-町字界線.dbf $ dbf2json --encoding Shift-JIS 20200401-行政区画代表点.dbf | jq . | head -n20 [ { "id": "K6_5013013062_1", "fid": "50130-13062-i-1029", "整備データ": 20171204, "整備デーA": 0, "整備完了日": "20200307", "orgGILvl": "25000", "orgMDId": null, "表示区分": "非表示", "種別": "郡市・東京都の区", "名称": "伊勢崎市", "行政コード": "10204" }, { "id": "K6_5013613050_1", "fid": "50136-13050-i-2033", "整備データ": 20191223, "整備デーA": 0, "整備完了日": "20200307", }}}