BBBikeDownloader.download_osm_data(subregion_names, osm_file_format, download_dir=None, update=False, confirmation_required=True, interval=None, verify_download_dir=True, verbose=False, ret_download_path=False, **kwargs)[source]

Download OSM data (of a specific file format) of one (or multiple) geographic (sub)region(s).

  • subregion_names (str | list) – name of a geographic (sub)region (or names of multiple geographic (sub)regions) available on BBBike free download server

  • osm_file_format (str) – file format/extension of the OSM data available on the download server

  • download_dir (str | None) – directory for saving the downloaded file(s), defaults to None; when download_dir=None, it refers to the method cdd()

  • update (bool) – whether to update the data if it already exists, defaults to False

  • confirmation_required (bool) – whether asking for confirmation to proceed, defaults to True

  • interval (int | float | None) – interval (in second) between downloading two subregions, defaults to None

  • verify_download_dir (bool) – whether to verify the pathname of the current download directory, defaults to True

  • verbose (bool | int) – whether to print relevant information in console, defaults to False

  • ret_download_path (bool) – whether to return the path(s) to the downloaded file(s), defaults to False


the path(s) to the downloaded file(s) when ret_download_path is True

Return type:

list | str


>>> from pydriosm.downloader import BBBikeDownloader
>>> from pyhelpers.dirs import delete_dir
>>> import os

>>> bbd = BBBikeDownloader()

>>> # Download BBBike PBF data of London
>>> subrgn_name = 'London'
>>> file_format = "pbf"

>>> bbd.download_osm_data(subrgn_name, file_format, verbose=True)
To download .pbf data of the following geographic (sub)region(s):
? [No]|Yes: yes
Downloading "London.osm.pbf"
    to "osm_data\bbbike\london\" ... Done.

>>> len(bbd.data_paths)
>>> os.path.relpath(bbd.data_paths[0])

>>> london_dwnld_dir = os.path.relpath(bbd.download_dir)
>>> london_dwnld_dir

>>> # Download PBF data of Leeds and Birmingham to a given directory
>>> subrgn_names = ['leeds', 'birmingham']
>>> dwnld_dir = "tests\osm_data"

>>> dwnld_paths = bbd.download_osm_data(
...     subrgn_names, file_format, dwnld_dir, verbose=True, ret_download_path=True)
To download .pbf data of the following geographic (sub)region(s):
? [No]|Yes: yes
Downloading "Leeds.osm.pbf"
    to "tests\osm_data\leeds\" ... Done.
Downloading "Birmingham.osm.pbf"
    to "tests\osm_data\birmingham\" ... Done.
>>> len(dwnld_paths)
>>> len(bbd.data_paths)
>>> os.path.relpath(bbd.download_dir) == os.path.relpath(dwnld_dir)
>>> os.path.relpath(os.path.commonpath(dwnld_paths))

>>> # Delete the above download directories
>>> delete_dir([os.path.dirname(london_dwnld_dir), dwnld_dir], verbose=True)
To delete the following directories:
    "osm_data\" (Not empty)
    "tests\osm_data\" (Not empty)
? [No]|Yes: yes
Deleting "osm_data\" ... Done.
Deleting "tests\osm_data\" ... Done.