_Reader.get_file_path

_Reader.get_file_path(subregion_name, osm_file_format, data_dir=None)

Get the path to an OSM data file (if available) of a specific file format for a geographic (sub)region.

Parameters
  • subregion_name (str) – name of a geographic (sub)region (case-insensitive) that is available on a free download server

  • osm_file_format (str) – format (file extension) of OSM data

  • data_dir (str or None) – directory where the data file is located/saved, defaults to None; when data_dir=None, it refers to the directory specified by the corresponding downloader

Returns

path to the data file

Return type

str or None

Tests:

>>> from pydriosm.reader import _Reader
>>> from pydriosm.downloader import GeofabrikDownloader, BBBikeDownloader
>>> import os

>>> r = _Reader(downloader=GeofabrikDownloader)

>>> subrgn_name = 'rutland'
>>> file_format = ".pbf"
>>> dat_dir = "tests\osm_data"

>>> path_to_rutland_pbf = r.get_file_path(subrgn_name, file_format, dat_dir)
>>> os.path.relpath(path_to_rutland_pbf)
'tests\osm_data\rutland\rutland-latest.osm.pbf'
>>> os.path.isfile(path_to_rutland_pbf)
False

>>> subrgn_name = 'leeds'
>>> path_to_leeds_pbf = r.get_file_path(subrgn_name, file_format, dat_dir)
>>> path_to_leeds_pbf is None
True

>>> # Change the `downloader` to `BBBikeDownloader`
>>> r = _Reader(downloader=BBBikeDownloader)
>>> path_to_leeds_pbf = r.get_file_path(subrgn_name, file_format, dat_dir)
>>> os.path.relpath(path_to_leeds_pbf)
'tests\osm_data\leeds\Leeds.osm.pbf'