pythonreverse-geocoding

Reverse geocoding with Python Nominatim limitations & improvement geopy.geocoders


I need to fetch address for 10000 based on latitude & longitude & I used geopy.geocoders for that. However, the first limitation is that there's a limitation in terms of the number of cordinates you can reverse geocode in day.

from geopy.geocoders import Nominatim
from geopy.extra.rate_limiter import RateLimiter
geolocator = Nominatim(user_agent="specify_your_app_name_here",timeout=None)

rectangles_df=df["LatLong"].head(2)

location=rectangles_df.apply(geolocator.reverse)

& secondly this just prints the address without the coordinates when applied on a dataframe for multiple coordinates which makes it difficult to map to the original dataset. Also it doesn't give the output in English I also tried the following :

test=rectangles_df.apply(geolocator.reverse(language='en'))

But this obviously does not work because it expects the coordinates as a mandatory parameter.

What can be done.


Solution

  • First, according to Nominatim usage policy the only limit is one request/second. I don't see any daily limit beyond the 86400 requests per day (1second6060*24) derived from the one request limit https://operations.osmfoundation.org/policies/nominatim/

    The easiest way to guarantee you don't make more than one request per second is

      time.sleep(1)
    

    while iterating through the requests, before making a request.

    Second, the location object keeps both coordinates and address as properties:

    print(location.latitude, location.longitude, location.adress)
    

    Third, with geopy you can declare the language. It's false by default

    reverse(query, exactly_one=True, timeout=DEFAULT_SENTINEL, language=False,  addressdetails=True)
    

    Check geopy docs concerning Nominatim: https://geopy.readthedocs.io/en/stable/#nominatim