GeofabrikReader.get_path_to_osm_pbf

GeofabrikReader.get_path_to_osm_pbf(subregion_name, data_dir=None)[source]

Get the absolute local path to a PBF (.osm.pbf) data file for a geographic region.

Parameters
  • subregion_name (str) – name of a geographic region (case-insensitive) available on Geofabrik’s free download server

  • data_dir (str or None) – directory where the data file of the subregion_name is located/saved; if None (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()

>>> sr_name = 'Rutland'

>>> path_to_rutland_pbf = geofabrik_reader.get_path_to_osm_pbf(sr_name)

>>> print(path_to_rutland_pbf)
# (if "rutland-latest.osm.pbf" is unavailable at the package data directory)
# None

>>> file_fmt = ".pbf"
>>> dwnld_dir = "tests"

>>> # Download the PBF data file of Rutland to "\tests"
>>> geofabrik_reader.Downloader.download_osm_data(sr_name, file_fmt,
...                                               dwnld_dir, verbose=True)
Confirmed 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_pbf(
...     sr_name, 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)