Hello,
I use Nominatim to reverse geolocate by providing lat+lon and getting the full adress back.
Before I resort to regex for parsing, is there a better way to extract just the town from the reply?
--
Edit: Without knowing what I was doing, I found how to extract that part:
I use Nominatim to reverse geolocate by providing lat+lon and getting the full adress back.
Before I resort to regex for parsing, is there a better way to extract just the town from the reply?
with open('myfile.geojson') as f: gj = geojson.load(f) for track in gj['features']: print(track['properties']['name']) print(track['properties']['description']) coords = track['geometry']['coordinates'][0] #Flip coords: Nominatim expects lat, lon coords = coords[::-1] #Must look like "lat,lon" location = "{}, {}".format(coords[0], coords[1]) geolocator = Nominatim(user_agent="my-application") location = geolocator.reverse(location) #OK BUT TOO MUCH INFOS print(location.address) #OK BUT HOW TO EXTRACT TOWN? print(location.raw) #BAD city = location.raw['town'] #BAD city = location.items("town") #BAD print(location.city) breakThank you.
--
Edit: Without knowing what I was doing, I found how to extract that part:
print(location.raw['address']['town'])