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.

  • 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 the method cdd()

  • 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


whether the requested data file exists; or the path to the data file

Return type:

bool | str


>>> 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

>>> # 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):
? [No]|Yes: yes
Downloading "Birmingham.osm.pbf"
    to "tests\osm_data\birmingham\" ... Done.

>>> bbd.file_exists(subrgn_name, file_format, dwnld_dir)

>>> # Set `ret_file_path=True`
>>> pbf_pathname = bbd.file_exists(subrgn_name, file_format, ret_file_path=True)
>>> os.path.relpath(pbf_pathname)

>>> os.path.relpath(dwnld_dir) == os.path.relpath(bbd.download_dir)

>>> # 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)