L
L
LakeForest2021-01-14 11:39:45
Python
LakeForest, 2021-01-14 11:39:45

Geopy doesn't find an address based on a string that it provided based on latitude and longitude. Why?

def get_place(name, lat, long):
    geolocator = Nominatim(user_agent='rir7m')
# for index, row in norm_df.iterrows():
    coord = "{}, {}".format(lat, long)
    location = geolocator.reverse(coord)
    try:
     
     addr_location = geolocator.geocode(location.address)
     return addr_location.raw[name]
    except Exception as e:
     print(location.raw)
     print(e)
    
    #location.raw['class']

norm_df['TypePlace'] = norm_df.apply(lambda x: get_place('type', x['Широта'], x['Долгота']), axis=1)

Detsky Mir, 9, Peterburgskaya Street, Staro-Tatarskaya Sloboda, Vakhitovsky District, Kazan City District, Tatarstan, Privolzhsky Federal District, 420107, Russia
{'place_id': 106787876, 'licence': 'Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright', 'osm_type': 'way', 'osm_id': 79073538, 'lat': '55.7852654', 'lon': '49.12655876972477', 'display_name': 'Children's world, 9, Peterburgskaya street, Staro-Tatarskaya Sloboda, Vakhitovsky District, Kazan City District, Tatarstan, Privolzhsky Federal District, 420107, Russia', 'address': {'shop': 'Children's World', 'house_number': '9', 'road': 'Peterburgskaya street', ' suburb': 'Staro-Tatarskaya Sloboda', 'city_district': 'Vakhitovsky District', 'city': 'Kazan City District', 'state': 'Tatarstan', 'region': 'Volga Federal District', 'postcode' : '420107', 'country': 'Russia', 'country_code': 'en'}, 'boundingbox': ['55.7848491', '55.7858024', '49.1257845', '49.1271768']}

Error:
'NoneType' object has no attribute 'raw'

I would like to fetch by latitude and longitude the type, class and importance of the site in order to create new features.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2021-01-14
@SoreMix

It looks like cropping elements makes some sense.

addr_location = geolocator.geocode(location.address[:-6])

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question