BBBikeDownloader.download_osm_data¶
-
BBBikeDownloader.
download_osm_data
(subregion_names, osm_file_format, download_dir=None, update=False, confirmation_required=True, interval=None, verbose=False, ret_download_path=False, **kwargs)¶ Download OSM data (in a specific file format) of one (or multiple) geographic region(s).
- Parameters
subregion_names (str or list) – name of a geographic region (or names of multiple geographic regions) available on BBBike 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), the default directory created by the packageupdate (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 None) – interval (in second) between downloading two subregions, defaults to
None
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
isTrue
- 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() >>> region_names = 'London' >>> file_format = 'pbf' >>> bbbike_downloader.download_osm_data(region_names, file_format, verbose=True) To download .pbf data of the following geographic region(s): London ? [No]|Yes: yes Downloading "London.osm.pbf" to "osm_bbbike\London\" ... Done. >>> # Delete the created directory "osm_bbbike" >>> delete_dir(cd_dat_bbbike(), verbose=True) The directory "osm_bbbike\" is not empty. Confirmed to delete it? [No]|Yes: yes Deleting "osm_bbbike\" ... Done. >>> region_names = ['leeds', 'birmingham'] >>> dwnld_dir = "tests" >>> dwnld_paths = bbbike_downloader.download_osm_data(region_names, file_format, ... dwnld_dir, verbose=True, ... ret_download_path=True) 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)