BBBikeDownloader.file_exists

BBBikeDownloader.file_exists(subregion_name, osm_file_format, data_dir=None, update=False, verbose=False, ret_file_path=False)[source]

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 | None) – directory where the data file (or files) is (or are) stored, defaults to None; when data_dir=None, it refers to cdd_bbbike().

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

  • verbose (bool | 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 | str

Examples:

>>> from pydriosm.downloader import BBBikeDownloader
>>> from pyhelpers.dirs import delete_dir
>>> import os
>>> bbd = BBBikeDownloader()
>>> subregion_name = 'birmingham'
>>> osm_file_format = ".shp"
>>> data_dir = "tests/osm_data"
>>> # Check whether the PBF data file exists; `ret_file_path` is by default `False`
>>> pbf_exists = bbd.file_exists(subregion_name, osm_file_format, data_dir)
>>> pbf_exists
False
>>> # Download the PBF data of Birmingham (to the default directory)
>>> bbd.download_data(subregion_name, osm_file_format, data_dir, verbose=True)
Proceed to download data in the format '.shp.zip' for the following geographic (sub...
    "Birmingham"
  to "./tests/osm_data/birmingham/"
? [No]|Yes: yes
Downloading "Birmingham.osm.shp.zip" 100%|██████████| 79.0M/79.0M | 949kB/s |...
  Saving "Birmingham.osm.shp.zip" to "./tests/osm_data/birmingham/" ... Done.
>>> bbd.file_exists(subregion_name, osm_file_format, data_dir)
True
>>> # Set `ret_file_path=True`
>>> pbf_pathname = bbd.file_exists(subregion_name, osm_file_format, ret_file_path=True)
>>> os.path.relpath(pbf_pathname)
'tests\osm_data\birmingham\Birmingham.osm.pbf'
>>> os.path.relpath(data_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(subregion_name, osm_file_format, data_dir)
False