BBBikeDownloader.download_data

BBBikeDownloader.download_data(subregion_names, osm_file_formats, 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).

Parameters:
  • 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_formats (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 cdd_bbbike().

  • 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

Returns:

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

Return type:

list | str

Examples:

>>> from pydriosm.downloader import BBBikeDownloader
>>> from pyhelpers.dirs import delete_dir
>>> import os
>>> bbd = BBBikeDownloader()
>>> # Download BBBike PBF data of London
>>> subregion_name = 'London'
>>> osm_file_format = "pbf"
>>> bbd.download_data(subregion_name, osm_file_format, verbose=True)
Proceed to download data in the format '.pbf' for the following geographic (sub)reg...
    "London"
  to "./osm_data/bbbike/london/"
? [No]|Yes: yes
Downloading "London.osm.pbf" 100%|██████████| 188M/188M | 1.06MB/s | ETA: 00:00
  Saving "London.osm.pbf" to "./osm_data/bbbike/london/" ... Done.
>>> len(bbd.data_paths)
1
>>> os.path.relpath(bbd.data_paths[0])  # (on Windows)
'osm_data\bbbike\london\London.osm.pbf'
>>> london_download_dir = os.path.relpath(bbd.download_dir)
>>> london_download_dir  # (on Windows)
'osm_data\bbbike'

>>> # Download PBF data of Leeds and Birmingham to a given directory
>>> subregion_names = ['Leeds', 'Birmingham']
>>> osm_file_format = ['shp', 'pbf']
>>> download_dir = "tests/osm_data"
>>> download_paths = bbd.download_data(
...     subregion_names, osm_file_format, download_dir, verbose=2,
...     ret_download_path=True)
Proceed to download data in the formats ('.shp.zip', '.pbf') for the following geog...
    "Birmingham"
    "Leeds"
  to "./tests/osm_data/"
? [No]|Yes: yes
Downloading "Leeds.osm.shp.zip" to "./tests/osm_data/leeds/" ... Done.
Downloading "Leeds.osm.pbf" to "./tests/osm_data/leeds/" ... Done.
Downloading "Birmingham.osm.shp.zip" to "./tests/osm_data/birmingham/" ... Done.
Downloading "Birmingham.osm.pbf" to "./tests/osm_data/birmingham/" ... Done.
>>> len(download_paths)
4
>>> len(bbd.data_paths)
5
>>> os.path.relpath(bbd.download_dir) == os.path.relpath(download_dir)
True
>>> os.path.relpath(os.path.commonpath(download_paths))  # (on Windows)
'tests\osm_data'

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