I am writing a Python script that passes a latitude and longitude to a module and performs a reverse geocode function to return the address of the location. I have been using Google's PyGeoCoder to do this, but it requires access to the Internet. I am needing something similar to PyGeoCoder but open sourced and completely offline.
Asked
Active
Viewed 8,793 times
2 Answers
11
I created a module to do exactly that: https://github.com/richardpenman/reverse_geocode
>>> import reverse_geocode
>>> coordinates = (-37.81, 144.96), (31.76, 35.21)
>>> reverse_geocode.search(coordinates)
[{'city': 'Melbourne', 'code': 'AU', 'country': 'Australia'},
{'city': 'Jerusalem', 'code': 'IL', 'country': 'Israel'}]
Internally it uses locations from the geonames database and a k-d tree to find the nearest neighbour.

hoju
- 28,392
- 37
- 134
- 178
-
1How do you search for only one coordinate? I tried `coordinates = (-37.81, 144.96)` and then `reverse_geocode.search(coordinates)`, but I get an error saying: `TypeError: 'int' object is not iterable`. – stackoverflowuser2010 Feb 08 '18 at 00:24
-
Can you also add the US state, e.g. Texas, Florida, in the result? – stackoverflowuser2010 Feb 08 '18 at 00:29
-
The "search" method expects a list. Can use "get "method" for a single data point. – hoju Feb 09 '18 at 03:03
-
3An improved version of this library is available at https://github.com/thampiman/reverse-geocoder – Motin Nov 09 '19 at 09:19
6
Have you considered using OpenStreetMap? You can download the whole database (the "planet") or one of the extracts if you just need a specific area. Afterwards you can filter out all addresses and use the resulting data for your geocoding. There are several search engines for OSM available, the most popular one is Nominatim. It is used on the main website and can do both geocoding and reverse-geocoding. So it might be a good starting point for your task.

scai
- 20,297
- 4
- 56
- 72