GeofabrikReader.get_path_to_osm_file¶
-
GeofabrikReader.
get_path_to_osm_file
(subregion_name, osm_file_format, data_dir=None)¶ Get the local path to an OSM data file of a geographic region.
- Parameters
subregion_name (str) – name of a geographic 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 or 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 or None
Example:
>>> import os >>> from pydriosm.reader import GeofabrikReader >>> geofabrik_reader = GeofabrikReader() >>> region_name = 'Rutland' >>> file_format = ".pbf" >>> path_to_rutland_pbf = geofabrik_reader.get_path_to_osm_file( ... region_name, file_format) >>> print(path_to_rutland_pbf) # (if "rutland-latest.osm.pbf" is unavailable at the package data directory) # None >>> # Specify a download directory >>> dwnld_dir = "tests" >>> # Download the PBF data file of Rutland to "tests\" >>> geofabrik_reader.Downloader.download_osm_data( ... region_name, file_format, download_dir=dwnld_dir, verbose=True) To download .osm.pbf data of the following geographic region(s): Rutland ? [No]|Yes: yes Downloading "rutland-latest.osm.pbf" to "tests\" ... Done. >>> path_to_rutland_pbf = geofabrik_reader.get_path_to_osm_file( ... region_name, file_format, data_dir=dwnld_dir) >>> print(os.path.relpath(path_to_rutland_pbf)) tests\rutland-latest.osm.pbf >>> # Delete the downloaded PBF data file >>> os.remove(path_to_rutland_pbf)