BBBikeDownloader.download_osm_data

BBBikeDownloader.download_osm_data(subregion_names, osm_file_format, download_dir=None, update=False, confirmation_required=True, interval_sec=1, verbose=False, ret_download_path=False)[source]

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

Parameters
  • subregion_names (str or list) – name(s) of one (or multiple) geographic region(s) available on BBBike’s free download server

  • osm_file_format (str) – format (file extension) of an OSM data

  • download_dir (str or None) – directory where downloaded OSM file is saved; if None (default), package data directory

  • update (bool) – whether to check on update and proceed to update the package data, defaults to False

  • confirmation_required (bool) – whether to prompt a message for confirmation to proceed, defaults to True

  • interval_sec (int) – interval (in sec) between downloading two subregions, defaults to 1

  • verbose (bool or 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=True

Return type

list or str

Examples:

>>> import os
>>> from pyhelpers.dir import delete_dir
>>> from pydriosm.downloader import BBBikeDownloader, cd_dat_bbbike

>>> bbbike_downloader = BBBikeDownloader()

>>> sr_names = 'London'
>>> file_fmt = 'pbf'

>>> bbbike_downloader.download_osm_data(sr_names, file_fmt, verbose=True)
Confirmed to download .pbf data of the following geographic region(s):
    London
? [No]|Yes: yes
Downloading "London.osm.pbf" to "\dat_BBBike\London" ...
Done.

>>> # Delete the directory generated above
>>> delete_dir(cd_dat_bbbike(), verbose=True)
The directory "\dat_BBBike" is not empty.
Confirmed to delete it? [No]|Yes: yes
Deleting "\dat_BBBike" ... Done.

>>> sr_names = ['leeds', 'birmingham']
>>> dwnld_dir = "tests"

>>> dwnld_paths = bbbike_downloader.download_osm_data(sr_names, file_fmt,
...                                                   dwnld_dir, verbose=True,
...                                                   ret_download_path=True)
Confirmed to download .pbf data of the following geographic region(s):
    Leeds
    Birmingham
? [No]|Yes: yes
Downloading "Leeds.osm.pbf" to "\tests" ...
Done.
Downloading "Birmingham.osm.pbf" to "\tests" ...
Done.

>>> for dwnld_path in dwnld_paths:
...     print(os.path.relpath(dwnld_path))
tests\Leeds.osm.pbf
tests\Birmingham.osm.pbf

>>> # Delete the above downloaded data files
>>> for dwnld_path in dwnld_paths:
...     os.remove(dwnld_path)