简体   繁体   中英

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.

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 (1second*60*60*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 interacting 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM