Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add city name attribute to urban extents based on OSM #1

Open
andresfchamorro opened this issue Jul 23, 2021 · 1 comment
Open

add city name attribute to urban extents based on OSM #1

andresfchamorro opened this issue Jul 23, 2021 · 1 comment
Labels
enhancement New feature or request

Comments

@andresfchamorro
Copy link
Contributor

andresfchamorro commented Jul 23, 2021

Leaving this as a quick solution to add OSM attributes to the urban extents output, using the Nominatim geocoder from geopy. I can add it as a notebook example or to the source code.

from geopy.geocoders import Nominatim
urban_extents.loc[:, "centroid"] = urban_extents.geometry.apply(lambda ext: ext.centroid)
extents_geocode = {}
for idx, row in urban_extents.iterrows():
    res = geolocator.reverse(query = (row.centroid.y, row.centroid.x), language = "en", zoom = 10)
    extents_geocode[idx] = res
addresses = [l.raw['address'] for l in list(extents_geocode.values())]
cities = [a['city'] if 'city' in a.keys() else "" for a in addresses]
counties = [a['county'] if 'county' in a.keys() else "" for a in addresses]
states = [a['state'] if 'state' in a.keys() else "" for a in addresses]

urban_extents.loc[:, "city"] = cities
urban_extents.loc[:, "county"] = counties
urban_extents.loc[:, "state"] = states
@andresfchamorro andresfchamorro added the enhancement New feature or request label Jul 23, 2021
@Charlesfox1
Copy link

Charlesfox1 commented Jul 23, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants