GeofabrikReader.get_file_path
- GeofabrikReader.get_file_path(subregion_name, osm_file_format, data_dir=None)[source]
Get the local path to an OSM data file of a geographic (sub)region.
- Parameters:
subregion_name (str) – name of a geographic (sub)region (case-insensitive) that is available on Geofabrik free download server
osm_file_format (str) – file format of the OSM data available on the free download server
data_dir (str | None) – directory where the data file of the
subregion_name
is located/saved; ifNone
(default), the default local directory
- Returns:
path to PBF (.osm.pbf) file
- Return type:
str | None
Examples:
>>> from pydriosm.reader import GeofabrikReader >>> from pyhelpers.dirs import delete_dir >>> import os >>> gfr = GeofabrikReader() >>> subrgn_name = 'rutland' >>> file_format = ".pbf" >>> dat_dir = "tests\osm_data" >>> path_to_rutland_pbf = gfr.get_file_path(subrgn_name, file_format, data_dir=dat_dir) >>> # When "rutland-latest.osm.pbf" is unavailable at the package data directory >>> os.path.isfile(path_to_rutland_pbf) False >>> # Download the PBF data file of Rutland to "tests\osm_data\" >>> gfr.downloader.download_osm_data(subrgn_name, file_format, dat_dir, verbose=True) To download .osm.pbf data of the following geographic (sub)region(s): Rutland ? [No]|Yes: yes Downloading "rutland-latest.osm.pbf" to "tests\osm_data\rutland\" ... Done. >>> # Check again >>> path_to_rutland_pbf = gfr.get_file_path(subrgn_name, file_format, data_dir=dat_dir) >>> os.path.relpath(path_to_rutland_pbf) 'tests\osm_data\rutland\rutland-latest.osm.pbf' >>> os.path.isfile(path_to_rutland_pbf) True >>> # Delete the test data directory >>> delete_dir(dat_dir, verbose=True) To delete the directory "tests\osm_data\" (Not empty) ? [No]|Yes: yes Deleting "tests\osm_data\" ... Done.