[PYTHON] Geocoding with japanese-addresses

Introduction

The address data and the latitude and longitude of the representative point have been released in "Geolonia Address Data | japanese-addresses".

Reference: [Can be used for free "address master data" release, unification of notation and conversion to latitude and longitude --INTERNET Watch](https://internet.watch.impress.co.jp/docs/news/1271/298 /index.html)

Using this data, I made a command for address ⇔ latitude / longitude conversion, so I will introduce it. Requires Python 3.8.

Installation & configuration

First, download CSV (latest.csv) from "Download" on the above site. The downloaded path is " /path/to/latest.csv ". Execute the following command.

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

The second command creates an "address list, KDTree, and latitude / longitude dictionary with addresses as keys" from CSV and saves it in the installation destination with pickle.

How to use

Address → Latitude / Longitude

simple-geocoding 1-chome, Marunouchi, Chiyoda-ku, Tokyo
>>>
(35.68156, 139.767201)

When there is one argument, it is regarded as an address and converted to latitude and longitude. It simply returns the latitude and longitude with the address as the key. For simplicity, even if there are multiple latitudes and longitudes for the same address, only one is returned.

Latitude / longitude → address

simple-geocoding 35.68156 139.7672
>>>
1-chome Marunouchi, Chiyoda-ku, Tokyo

When there are two arguments, it is regarded as latitude and longitude and converted to an address. It asks for the nearest registration point in KD-Tree.

Supplement

By using a data structure called KD-Tree, it is possible to efficiently manage points that exist unevenly. Also, in Python, KD-Tree is included in scipy, so it is easy to use.

reference -[Kd tree-Wikipedia](https://ja.wikipedia.org/wiki/Kd tree)

Recommended Posts

Geocoding with japanese-addresses
Sonic geocoding with Python geocoder 1.4.0