2

Is it possible to query OpenStreetMap via the Python library OSMnx to retrieve the (lat,long) coordinates for a city? The documentation seems to suggest attribute data should be accessible but I've not yet seen a pathway to retrieving the coordinates of a city's center. Using the OSMnx geocoder for a city of interest led to a poor result.

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
Chris
  • 3,109
  • 7
  • 29
  • 39

1 Answers1

2

You may want to try to work with centroids - It's clearly not the city center in a colloquial definition, but it gives you the the center of the city boundaries:

gdf = ox.geocode_to_gdf('London').centroid
>>> POINT (-0.10942 51.50050

London's city center would be in ... erm ... Woolwich, but you can try "City of London"

gdf = ox.geocode_to_gdf('city of London')
>>> POINT (-0.09244 51.51441)

which gives you a location between Bank and St Paul's in... erm... "Trump Street"

Not what you are looking for I guess for various reasons, but it is the "center".

https://geopandas.org/en/stable/docs/reference/api/geopandas.GeoSeries.centroid.html