2

I am using geopy with nominatim to get cities names from geographic coordinates. I am using the below code :

for index,row in data.iterrows():
    georeverse = geolocator.reverse
    locationdep = georeverse(row[3],language='fr-FR',exactly_one=True)
    address = location.raw['address']
    state=address.get('state','')
    town=address.get('town','')

My problem is that it throws a time out error after treating 256 rows and my data frame contain over 100 000 rows. So how would I handle this to avoid the timeout error?

  • Hey, welcome to GIS SE! Can you share the code youi are using to create a geopy.geocoders.Nominatim instance? – Marcelo Villa May 04 '20 at 16:27
  • this is the code I used from geopy.geocoders import Nominatim geolocator = Nominatim(user_agent="class-app") @MarceloVilla-Piñeros – Nour elhouda Khettache May 04 '20 at 18:03
  • What happens if you specify a timeout? For example, Nominatim(user_agent="class-app", timeout=10). Furthermore, you could add a try/except clause to skip the rows where a time out happens. – Marcelo Villa May 04 '20 at 18:45
  • On another note, where are your cities located? If they are not all over the world, a better approach might be downloading a shapefile with the cities geometries and doing an intersection or a nearest neighbour analysis. – Marcelo Villa May 04 '20 at 18:49
  • Yes my cities are located in one country which is Algeria. Can you please explain more for me from where could I download a shape file ? and how can I apply the nearest neighbor analysis approach I have been looking for something like that and I couldn't find it. Thank you for helping me @MarceloVilla-Piñeros – Nour elhouda Khettache May 04 '20 at 20:13
  • You can download the administrative areas (with different level of subdivisions) for different countries either here or here. These are polygons you can use to intersect your coordinates with. If these polygons do not meet your requirements, you can download a shapefile with populated places (i.e. cities) in Algeria and follow one of the approaches proposed in this question. – Marcelo Villa May 05 '20 at 14:43
  • Nominatim is free thus it has very low rate limits. RateLimiter might help: https://stackoverflow.com/a/51573613 , or you can consider using another (paid) geocoding service with more quota. – KostyaEsmukov May 08 '20 at 23:58

0 Answers0