enrich_with_osm(info: DataFrame, osm_gdf: GeoDataFrame, *, radius_m: float = 300.0, category_col: str | None = None, prefix: str = 'osm_') -> DataFrame
Count nearby OSM features around each station (Bring Your Own GeoDataFrame).
Reduces any geometry to a representative point, then summarises within radius_m
(total + per-category). Requires the optional [osm] extra (geopandas).
Parameters:
| Name |
Type |
Description |
Default |
osm_gdf
|
GeoDataFrame
|
OSM features you fetched (e.g. osmnx.features_from_point).
|
required
|
category_col
|
str
|
Attribute to break counts down by; if omitted, the first present of
amenity / shop / leisure / highway / railway / public_transport is used.
|
None
|
See Also
station_surroundings : Generic buffer summary.
link_transit_stops : The transit-specific equivalent.
Source code in src/gbfs_toolkit/spatial/osm.py
| def enrich_with_osm(
info: pd.DataFrame,
osm_gdf: gpd.GeoDataFrame,
*,
radius_m: float = 300.0,
category_col: str | None = None,
prefix: str = "osm_",
) -> pd.DataFrame:
"""Count nearby OSM features around each station (Bring Your Own GeoDataFrame).
Reduces any geometry to a representative point, then summarises within ``radius_m``
(total + per-category). Requires the optional ``[osm]`` extra (``geopandas``).
Parameters
----------
osm_gdf : geopandas.GeoDataFrame
OSM features you fetched (e.g. ``osmnx.features_from_point``).
category_col : str, optional
Attribute to break counts down by; if omitted, the first present of
``amenity / shop / leisure / highway / railway / public_transport`` is used.
See Also
--------
[`station_surroundings`][gbfs_toolkit.station_surroundings] : Generic buffer summary.
[`link_transit_stops`][gbfs_toolkit.link_transit_stops] : The transit-specific equivalent.
"""
try:
import geopandas # noqa: F401
except ImportError as e: # pragma: no cover
raise ImportError(
"enrich_with_osm requires geopandas. Install with `pip install gbfs-toolkit[osm]`."
) from e
feats = _gdf_points(osm_gdf)
if category_col is None:
category_col = next((c for c in _OSM_CATEGORY_GUESSES if c in feats.columns), None)
return features_within(info, feats, radius_m=radius_m, category_col=category_col, prefix=prefix)
|