4

I am trying to run the following code to perform a geocode using the geopy package.

    import geopandas as gpd
    import pandas as pd
    import os
    from time import sleep
    from geopy.geocoders import Nominatim

    end = pd.read_csv ('/home/hammer/transfer/coord.csv', sep=';')
from geopy.exc import GeocoderTimedOut

    def do_geocode(coor):
    try:
        return geopy.geocode(coor)
    except GeocoderTimedOut:
        return do_geocode(coor)

    coor = gpd.tools.geocode(end["address"], 
    provider = "nominatim", user_agent="gis", country_bias="Brazil", timeout=5)

I'd like to do the geocode of 90.000 addresses, though I'm having the timeout problem. Even after using this function above it was a user's suggestion here from the community.

An alternative I thought was to create a container docker from the nominatim. That way I could accomplish as many geocodes as I needed, without suffering from the limitations of the public API.

To create the docker I used this peterevans/nominatim image, available here (https://hub.docker.com/r/peterevans/nominatim/). However I have not found anywhere how I should change in my script to do the geocode from my container. When I try to change the provider parameters, it gives error and says that I can only use the parameters of the package.

Can someone help me with this? Or point me to another possible solution?

Heavy Hammer
  • 291
  • 3
  • 11

1 Answers1

2

I ended up finding the answer in another forum. I'll share the code here:

from geopy.geocoders import Nominatim

nom = Nominatim(domain='xxx.xxx.xx.xx:xxxx', scheme='http', timeout=3) #tried with different timeouts

end["coor"]=end["address"].apply(nom.geocode)

I created a docker / container on my server, opened a port and put it as domain.

Now I can do unlimited geocodes and the limit is the capacity of my server.

Heavy Hammer
  • 291
  • 3
  • 11
  • I found https://github.com/mediagis/nominatim-docker/tree/master/4.0 but I'm confused about how to get it running. Could you explain? – XiB Jul 28 '22 at 14:55