pyrosm.get_data_by_bbox

pyrosm.get_data_by_bbox#

pyrosm.get_data_by_bbox(bbox, crop=True, download=True, update=False, directory=None, output_path=None)#

Download (and by default crop) the OSM data covering a bounding box.

Finds the smallest Geofabrik extract whose extent fully covers bbox, downloads it, and – by default – crops it to bbox before returning the cropped file path.

Parameters:
  • bbox (list | tuple | numpy.ndarray | shapely geometry | GeoDataFrame | GeoSeries) – The area of interest as [minx, miny, maxx, maxy] in lon/lat, a Shapely geometry (its bounding box is used), or a GeoDataFrame/GeoSeries (its total bounds are used).

  • crop (bool) – When True (default), crop the downloaded extract to bbox and return the cropped file, named bbox_<minx>_<miny>_<maxx>_<maxy>.osm.pbf. When False, return the full downloaded extract.

  • download (bool) – When True (default), download the covering extract. When False, skip the download and return the covering extract’s PBF URL instead.

  • update (bool) – When True, re-download the extract even if it already exists locally.

  • directory (str, optional) – Directory to download into / write the cropped file to. None (default) uses a pyrosm temp directory.

  • output_path (str, optional) – Path for the cropped file when crop=True (overrides the automatic name). Ignored when crop=False or download=False.

Returns:

The cropped file path (default), the full extract path (crop=False), or the covering extract’s PBF URL (download=False).

Return type:

str

Raises:

ValueError – If no single extract fully covers bbox.