gboeing / osmnx-examples

Gallery of OSMnx tutorials, usage examples, and feature demonstations.
https://osmnx.readthedocs.io
MIT License
1.5k stars 519 forks source link

Extracting boundaries with specified administrative level is not working correctly #48

Closed GvdDool closed 2 years ago

GvdDool commented 2 years ago

Hi Geoff, I have read the documentation, and searched on the internet (https://stackoverflow.com/) for solutions, but until now I didn't find any hint about how administrative boundaries are handled in osmnx. To give an example, I am trying to run this code: ''' tags = {"boundary":"administrative","admin_level":"4" } gdf =ox.geometries.geometries_from_bbox(51.5, 51.0, 11.7, 11.2, tags) gdf.shape ''' The bounding box seems to be used as a polygon to create an intersection with all the boundaries in the OSM database, the first tag is working because only administrative boundaries are returned, but the filter on level is ignored (checking with gdf["admin_level"].head() shows level 6).

I would like to understand what I am doing wrong, and how I can use this package better; it seems like a very useful library, and could submit a working example, if I have made a mistake in my code and have a map with the correct levels. Thanks, Gijs

gboeing commented 2 years ago

See the documentation:

tags (dict) – Dict of tags used for finding objects in the selected area. Results returned are the union, not intersection of each individual tag. Each result matches at least one given tag. The dict keys should be OSM tags, (e.g., building, landuse, highway, etc) and the dict values should be either True to retrieve all items with the given tag, or a string to get a single tag-value combination, or a list of strings to get multiple values for the given tag. For example, tags = {‘building’: True} would return all building footprints in the area. tags = {‘amenity’:True, ‘landuse’:[‘retail’,’commercial’], ‘highway’:’bus_stop’} would return all amenities, landuse=retail, landuse=commercial, and highway=bus_stop.

For package usage questions, please ask on StackOverflow per the contributing guidelines. Thanks!

GvdDool commented 2 years ago

OK, rereading the section again made me realise that osmnx is using [OR] statements and not [AND] statements as I was presuming; removing the boundary request from the query is indeed giving only admin_level:4 results. Thank you for redirecting me to the documentation.