GeofabrikDownloader.file_exists

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

Check whether a 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 Geofabrik 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_geofabrik().

  • 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 GeofabrikDownloader
>>> from pyhelpers.dirs import delete_dir
>>> import os
>>> gfd = GeofabrikDownloader(download_dir="tests/osm_data")
>>> # Download the PBF data of London (to the default directory)
>>> subregion_name = 'london'
>>> osm_file_format = ".geopackage"
>>> gfd.download_data(subregion_name, osm_file_format, verbose=True)
Proceed to download data in the format '.gpkg.zip' for the following geographic (su...
    "Greater London"
  to "./tests/osm_data/europe/united-kingdom/england/greater-london/"
? [No]|Yes: yes
Downloading "greater-london-latest-free.gpkg.zip" 100%|██████████| 206M/206M ...
  Saving "greater-london-latest-free.gpkg.zip" to "./tests/osm_data/europe/united-k...
>>> # Check whether the PBF data file exists; `ret_file_path` is by default `False`
>>> gpkg_exists = gfd.file_exists(subregion_name, osm_file_format)
>>> gpkg_exists  # If the data file exists at the default directory
True
>>> # Set `ret_file_path=True`
>>> path_to_gpkg = gfd.file_exists(
...     subregion_name, osm_file_format, ret_file_path=True)
>>> os.path.relpath(path_to_gpkg)  # If the data file exists at the default directory
'tests\osm_data\europe\united-kingdom\england\greater-london\greater-london-l...
>>> # Remove the download directory:
>>> delete_dir(gfd.download_dir, verbose=True)
To delete the directory "./tests/osm_data/" (Not empty)
? [No]|Yes: yes
Deleting "./tests/osm_data/" ... Done.
>>> # Check if the data file still exists at the specified download directory
>>> gfd.file_exists(subregion_name, osm_file_format)
False