BBBikeDownloader.file_exists¶
-
BBBikeDownloader.
file_exists
(subregion_name, osm_file_format, data_dir=None, update=False, verbose=False, ret_file_path=False)¶ Check if a requested data file of a geographic region already exists locally, given its default filename.
- Parameters
subregion_name (str) – name of a geographic region available on BBBike free download server
osm_file_format (str) – file format of the OSM data available on the free download server
data_dir (str or None) – directory for saving the downloaded file(s); if
None
(default), the default directory created by the packageupdate (bool) – whether to (check on and) update the data, defaults to
False
verbose (bool or int) – whether to print relevant information in console, defaults to
False
ret_file_path (bool) – whether to return the path to the data file (if it exists), defaults to
False
- Returns
whether or not the requested data file exists; or the path to the data file
- Return type
bool or str
Examples:
>>> import os >>> from pyhelpers.dir import delete_dir >>> from pydriosm.downloader import BBBikeDownloader, cd_dat_bbbike >>> bbbike_downloader = BBBikeDownloader() >>> region_name = 'leeds' >>> file_format = ".pbf" >>> # Download the PBF data of London (to the default directory) >>> bbbike_downloader.download_osm_data(region_name, file_format, verbose=True) To download .pbf data of the following geographic region(s): Leeds ? [No]|Yes: yes Downloading "Leeds.osm.pbf" to "osm_bbbike\Leeds\" ... Done. >>> # Check whether the PBF data file exists; `ret_file_path` is by default `False` >>> pbf_exists = bbbike_downloader.file_exists(region_name, file_format) >>> type(pbf_exists) bool >>> # If the data file exists at the default directory created by the package >>> print(pbf_exists) True >>> # Set `ret_file_path` to be `True` >>> path_to_pbf = bbbike_downloader.file_exists( ... subregion_name=region_name, osm_file_format=file_format, ret_file_path=True) >>> # If the data file exists at the default directory created by the package: >>> type(path_to_pbf) str >>> print(os.path.relpath(path_to_pbf)) osm_bbbike\Leeds\Leeds.osm.pbf >>> # Remove the directory or the PBF file and check again: >>> delete_dir(cd_dat_bbbike(), confirmation_required=False, verbose=True) Deleting "osm_bbbike\" ... Done. >>> path_to_pbf = bbbike_downloader.file_exists( ... subregion_name=region_name, osm_file_format=file_format, ret_file_path=True) >>> # Since the data file does not exist at the default directory >>> type(path_to_pbf) bool >>> print(path_to_pbf) False