0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

行政区域ポリゴンをいい感じに簡略化する方法

Last updated at Posted at 2024-06-11

はじめに

国土数値情報からダウンロードできる行政区域ポリゴンは、とても高精細につくられていて、そのままではデータが重すぎて使いにくいことがあります。
GISでポリゴンの簡略化をすると下図のようにすき間ができてしまい、残念な感じになってしまいます。(高価なGISなら、すき間ができない簡略化があるようですが…)

sukima.png

やり方

すき間ができない簡略化は以下の手順で行います。

  • GeoJSONをTopoJSONに変換する
  • TopoJSONで簡略化する
  • GeoJSONに戻す

準備

TopoJSONをインストールする。
※TopoJSONの使い方の詳細については、こちらを参照してください。

> npm install topojson

Windowsの人はMicrosoftストアの公式Ubuntuをインストールして、そこから実行するのがおすすめです

TopoJSONに変換

以下のコマンドでTopoJSONに変換します。

  • geo2topo -q 1e6 [name]=[input] > [output]
    • name :オブジェクト名(なんでもよい)
    • input :入力ファイル名(GeoJSONファイル)
    • output :出力ファイル名(TopoJSONファイル)
    • -q 1e6 : 隣接する二つのポリゴンの座標間に誤差を持つ場合の判定パラメータ
> geo2topo -q 1e6 hoge=input.geojson > output.topojson

簡略化

以下のコマンドでTopoJSONを簡略化します。

  • toposimplify -p [planar] < [input] > [output]
    • planar :単純化の閾値 1.0~0.0までの値、大きい値ほど強く単純化する
    • input :入力ファイル名(TopoJSONファイル)
    • output :出力ファイル名(TopoJSONファイル)
>  toposimplify -p 0.0001 < input.topojson > output.topojson

GeoJSONに戻す

以下のコマンドでGeoJSONに変換します。

  • topo2geo [name]=[output] < [input]
    • name : オブジェクト名(TopoJSONに変換したときの名前)
    • input : 入力ファイル名(TopoJSONファイル)
    • output : 出力ファイル名(GeoJSONファイル)
> topo2geo hoge=output.geojson < input.topojson

ここでは紹介していませんがtopomergeを使用していた場合、PolygonとMultiPolygonが混在したGeoJSONが作成されます。

一括変換

パイプラインでコマンドをつなげて使うのが一般的です。

> geo2topo -q 1e6 hoge=input.geojson | toposimplify -p 0.0001 | topo2geo hoge=output.geojson
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?