BBBikeDownloader.download_subregion_data

BBBikeDownloader.download_subregion_data(subregion_name, download_dir=None, update=False, confirmation_required=True, interval=None, verify_download_dir=True, verbose=False, ret_download_path=False, **kwargs)

Download OSM data of all available formats for a geographic (sub)region.

Parameters:
  • subregion_name (str) – name of a (sub)region available on BBBike free download server

  • download_dir (str or None) – directory where the downloaded file is saved, defaults to None

  • 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 or float or 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 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

  • kwargs – optional parameters of pyhelpers.ops.download_file_from_url()

Returns:

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

Return type:

list or str

Examples:

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

>>> bbd = BBBikeDownloader()

>>> # Download the BBBike OSM data of Birmingham (to the default download directory)
>>> subrgn_name = 'birmingham'

>>> bbd.download_subregion_data(subrgn_name, verbose=True)
To download all available BBBike OSM data of Birmingham
? [No]|Yes: yes
Downloading:
    Birmingham.osm.pbf ... Done.
    Birmingham.osm.gz ... Done.
    Birmingham.osm.shp.zip ... Done.
    Birmingham.osm.garmin-onroad-latin1.zip ... Done.
    Birmingham.osm.garmin-osm.zip ... Done.
    Birmingham.osm.garmin-ontrail-latin1.zip ... Done.
    Birmingham.osm.geojson.xz ... Done.
    Birmingham.osm.svg-osm.zip ... Done.
    Birmingham.osm.mapsforge-osm.zip ... Done.
    Birmingham.osm.garmin-opentopo-latin1.zip ... Done.
    Birmingham.osm.mbtiles-openmaptiles.zip ... Done.
    Birmingham.osm.csv.xz ... Done.
    Birmingham.poly ... Done.
    CHECKSUM.txt ... Done.
Check out the downloaded OSM data at "osm_data\bbbike\birmingham\".

>>> len(bbd.data_paths)
14
>>> os.path.relpath(os.path.commonpath(bbd.data_paths))
'osm_data\bbbike\birmingham'
>>> os.path.relpath(bbd.download_dir)
'osm_data\bbbike'
>>> bham_dwnld_dir = os.path.dirname(bbd.download_dir)

>>> # Download the BBBike OSM data of Leeds (to a given download directory)
>>> subrgn_name = 'leeds'
>>> dwnld_dir = "tests\osm_data"

>>> dwnld_paths = bbd.download_subregion_data(
...     subrgn_name, download_dir=dwnld_dir, verbose=True, ret_download_path=True)
To download all available BBBike OSM data of Leeds
? [No]|Yes: yes
Downloading:
    Leeds.osm.pbf ... Done.
    Leeds.osm.gz ... Done.
    Leeds.osm.shp.zip ... Done.
    Leeds.osm.garmin-onroad-latin1.zip ... Done.
    Leeds.osm.garmin-osm.zip ... Done.
    Leeds.osm.garmin-ontrail-latin1.zip ... Done.
    Leeds.osm.geojson.xz ... Done.
    Leeds.osm.svg-osm.zip ... Done.
    Leeds.osm.mapsforge-osm.zip ... Done.
    Leeds.osm.garmin-opentopo-latin1.zip ... Done.
    Leeds.osm.mbtiles-openmaptiles.zip ... Done.
    Leeds.osm.csv.xz ... Done.
    Leeds.poly ... Done.
    CHECKSUM.txt ... Done.
Check out the downloaded OSM data at "tests\osm_data\leeds\".

>>> # Now the variable `.download_dir` has changed to `dwnld_dir`
>>> leeds_dwnld_dir = bbd.download_dir
>>> os.path.relpath(leeds_dwnld_dir) == dwnld_dir
True

>>> len(dwnld_paths)
14
>>> len(bbd.data_paths)  # New pathnames have been added to `.data_paths`
28
>>> os.path.relpath(os.path.commonpath(dwnld_paths))
'tests\osm_data\leeds'

>>> # Delete the download directories
>>> delete_dir([bham_dwnld_dir, leeds_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.