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?
Thank you.
--
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?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
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) break |
--
Edit: Without knowing what I was doing, I found how to extract that part:
1 |
print (location.raw[ 'address' ][ 'town' ]) |