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
; whendata_dir=None
, it refers to the methodcdd()
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 >>> # Specify a download directory >>> dwnld_dir = "tests\osm_data" >>> gfd = GeofabrikDownloader(download_dir=dwnld_dir) >>> subregion_name = 'london' >>> osm_file_format = ".pbf" >>> # Download the PBF data of London (to the default directory) >>> gfd.download_osm_data(subregion_name, osm_file_format, verbose=True) To download .osm.pbf data of the following geographic (sub)region(s): Greater London ? [No]|Yes: yes Downloading "greater-london-latest.osm.pbf" to "tests\osm_data\europe\great-britain\england\greater-london\"...Done. >>> # Check whether the PBF data file exists; `ret_file_path` is by default `False` >>> pbf_exists = gfd.file_exists(subregion_name, osm_file_format) >>> pbf_exists # If the data file exists at the default directory True >>> # Set `ret_file_path=True` >>> path_to_pbf = gfd.file_exists(subregion_name, osm_file_format, ret_file_path=True) >>> os.path.relpath(path_to_pbf) # If the data file exists at the default directory 'tests\osm_data\europe\great-britain\england\greater-london\greater-londo...' >>> # Remove the download directory: >>> delete_dir(dwnld_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