I am using OSMnx in Python to get the geometries of states (e.g. for Austria). However, OSMnx sometimes chooses the wrong OSM-object as place. Can I specify the OSM-object using its ID?
Example:
I get the names of the states in Austria using OverpassAPI:
(area["ISO3166-1"="{country}"];rel(area)[admin_level="{adminLevel}"];);
out center meta;
This give me the list of states:
@id @lat @lon name
35183 47.2199394 14.8675619 Steiermark
52343 47.1971981 11.5319171 Tirol
52345 46.7517868 13.8605291 Kärnten
74942 47.2184818 9.8839555 Vorarlberg
76909 47.4746574 16.5785134 Burgenland
77189 48.2213684 15.7607387 Niederösterreich
86539 47.4926636 13.0361103 Salzburg
102303 48.1168383 13.8707061 Oberösterreich
109166 48.2202874 16.3796721 Wien
But when I use OSMnx to get the geometry of "Salzburg", I get a point instead a polygon.
>>> outline = osmnx.gdf_from_place("Salzburg")
geometry place_name
POINT (13.0464806 7.7981346) Salzburg, 5020, Austria
Since "Salzburg" is a city as well as a state I would like put the OSM ID into the query to make it unambiguous. Is there a way to do this?
OSMnx does not take an OSM ID, but you can specify if you want the city or the state (or even which_result):
import osmnx as ox
outline_city = ox.gdf_from_place({'city':'Salzburg'})
outline_state = ox.gdf_from_place({'state':'Salzburg'})
EDIT: note that as of OSMnx v0.15.0, the gdf_from_place and gdf_from_places functions have been deprecated and replaced by the geocode_to_gdf function. See the docs for details.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With