The geolocator.reverse()
method is expecting a Point
obejct or a tuple with two coordinates. However, you are passing redshape
, which is a fiona.collection.Collection
object with all the features in your shapefile. You have to iterate through the collection, extract the coordinates and then call the geolocator. Here is an example:
import fiona
from geopy.geocoders import Nominatim
redshape = fiona.open("murt.shp")
geolocator = Nominatim(user_agent="my-ride")
for feature in redshape:
coords = feature['geometry']['coordinates'] # here is the x, y pair of coordinates
location = geolocator.reverse(coords)
print(location.address)
As have you already pointed out, the order of the coordinates for the geolocator.reverse()
method is y,x and not x,y as I initially thought. Keeping this in mind, you can unpack the x and y values individually and pass them in a specific order. Note that they are still passed inside a tuple.
x, y = feature['geometry']['coordinates']
location = geolocator.reverse((y, x))