8
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 3 years have passed since last update.

japanese-addressesを使ったジオコーディング

Last updated at Posted at 2020-08-24

はじめに

Geolonia 住所データ | japanese-addresses」で住所データと代表点の緯度経度が公開されました。

参考: 無料で使える「住所マスターデータ」公開、表記統一や緯度経度への変換に活用可能 - INTERNET Watch

このデータを使って、住所⇔緯度経度変換のコマンドを作ったので紹介します。
Python3.8が必要です。

インストール&設定

まず、上記サイトで「ダウンロード」からCSV(latest.csv)をダウンロードしてください。ダウンロードしたパスを「/path/to/latest.csv」とします。
下記コマンドを実行してください。

pip install simple-geocoding
python -c '__import__("simple_geocoding").Geocoding("/path/to/latest.csv")'

2つ目のコマンドでCSVから「住所リスト、KDTree、住所をキーとした緯度経度の辞書」を作成してインストール先にpickleで保存しています。

使い方

住所→緯度経度

simple-geocoding 東京都千代田区丸の内一丁目
>>>
(35.68156, 139.767201)

引数が1つのときは、住所とみなして、緯度経度に変換します。
これは、単純に住所をキーにした緯度経度を返しています。
なお、単純化のため同一の住所に対して複数の緯度経度が存在しても1つだけ返しています。

緯度経度→住所

simple-geocoding 35.68156 139.7672
>>>
東京都千代田区丸の内一丁目

引数が2つのときは、緯度と経度とみなして、住所に変換します。
これは、KD-Treeで最寄りの登録地点を求めています。

補足

KD-Treeというデータ構造を使うことで、不均一に存在する地点を効率よく管理できます。
また、PythonではKD-Treeがscipyに含まれているので、簡単に利用できます。

参考

8
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
8
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?