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 (sub)region already exists locally, given its default filename.
- Parameters:
subregion_name (str) – name of a (sub)region available on BBBike free download server
osm_file_format (str) – file format/extension of the OSM data available on the download server
data_dir (str or None) – directory where the data file (or files) is (or are) stored, defaults to
None
; whendata_dir=None
, it refers to the methodcdd()
update (bool) – whether to (check 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 the requested data file exists; or the path to the data file
- Return type:
bool or str
Examples:
>>> from pydriosm.downloader import BBBikeDownloader >>> from pyhelpers.dirs import delete_dir >>> import os >>> bbd = BBBikeDownloader() >>> subrgn_name = 'birmingham' >>> file_format = ".pbf" >>> dwnld_dir = "tests\osm_data" >>> # Check whether the PBF data file exists; `ret_file_path` is by default `False` >>> pbf_exists = bbd.file_exists(subrgn_name, file_format, dwnld_dir) >>> pbf_exists False >>> # Download the PBF data of Birmingham (to the default directory) >>> bbd.download_osm_data(subrgn_name, file_format, dwnld_dir, verbose=True) To download .pbf data of the following geographic (sub)region(s): Birmingham ? [No]|Yes: yes Downloading "Birmingham.osm.pbf" to "tests\osm_data\birmingham\" ... Done. >>> bbd.file_exists(subrgn_name, file_format, dwnld_dir) True >>> # Set `ret_file_path=True` >>> pbf_pathname = bbd.file_exists(subrgn_name, file_format, ret_file_path=True) >>> os.path.relpath(pbf_pathname) 'tests\osm_data\birmingham\Birmingham.osm.pbf' >>> os.path.relpath(dwnld_dir) == os.path.relpath(bbd.download_dir) True >>> # Remove the directory or the PBF file and check again: >>> delete_dir(bbd.download_dir, verbose=True) To delete the directory "tests\osm_data\" (Not empty) ? [No]|Yes: yes Deleting "tests\osm_data\" ... Done. >>> # Since the default download directory has been deleted >>> bbd.file_exists(subrgn_name, file_format, dwnld_dir) False