Author: Geoff Boeing
More info:
This notebook provides a quick tour of using OSMnx to download any geospatial entites/objects from OpenStreetMap as a geopandas GeoDataFrame.
import osmnx as ox
%matplotlib inline
ox.__version__
Use the geometries
module to download entities, such as grocery stores, transit stops, points of interest, or building footprints, and turn them into a GeoDataFrame: see docs.
To query, pass a tags
dict where keys are OSM tags. The dict's values can be either:
True
to retrieve all OSM objects with this tag, regardless of its valuePass multiple dict key:value pairs to retrieve the union (not intersection) of these pairs.
# get all building footprints in some neighborhood
# `True` means retrieve any object with this tag, regardless of value
place = "Bunker Hill, Los Angeles, California"
tags = {"building": True}
gdf = ox.geometries_from_place(place, tags)
gdf.shape
fig, ax = ox.plot_footprints(gdf, figsize=(3, 3))
# get all the parks in some neighborhood
# constrain acceptable `leisure` tag values to `park`
tags = {"leisure": "park"}
gdf = ox.geometries_from_place(place, tags)
gdf.shape
# get everything tagged amenity,
# and everything tagged landuse = retail or commercial,
# and everything tagged highway = bus_stop
tags = {"amenity": True, "landuse": ["retail", "commercial"], "highway": "bus_stop"}
gdf = ox.geometries_from_place("Piedmont, California, USA", tags)
gdf.shape
# view just the banks
gdf[gdf["amenity"] == "bank"].dropna(axis=1, how="any")
# view just the bus stops
gdf[gdf["highway"] == "bus_stop"].dropna(axis=1, how="any").head()