BBBikeReader.get_file_path

BBBikeReader.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; if None (default), the default local directory

Returns:

path to PBF (.osm.pbf) file

Return type:

str | None

Examples:

>>> from pydriosm.reader import BBBikeReader
>>> from pyhelpers.dirs import delete_dir
>>> import os
>>> bbr = BBBikeReader()
>>> subregion_name = 'rutland'
>>> osm_file_format = ".pbf"
>>> data_dir = "tests/osm_data"
>>> path_to_pbf = bbr.get_file_path(subregion_name, osm_file_format, data_dir)
Traceback (most recent call last):
    ...
pydriosm.errors.InvalidSubregionNameError:
  `subregion_name='rutland'` -> The input of `subregion_name` is not recognizable.
  Check the `.data_source`, or try another one instead.
>>> subregion_name = 'birmingham'
>>> path_to_pbf = bbr.get_file_path(subregion_name, osm_file_format, data_dir)
>>> # When "Birmingham.osm.pbf" is unavailable at the data directory
>>> os.path.isfile(path_to_pbf)
False
>>> # Download the PBF data file of Birmingham to "./tests/osm_data/"
>>> bbr.downloader.download_data(
...     subregion_name, osm_file_format, data_dir, verbose=True)
Proceed to download data in the format '.pbf' for the following geographic (sub)reg...
  "Birmingham"
  to "./tests/osm_data/birmingham/"
? [No]|Yes: yes
Downloading "Birmingham.osm.pbf" 100%|██████████| 55.8M/55.8M | 15.3MB/s | ET...
  Saving "Birmingham.osm.pbf" to "./tests/osm_data/birmingham/" ... Done.
>>> # Check again
>>> path_to_pbf = bbr.get_file_path(subregion_name, osm_file_format, data_dir)
>>> os.path.isfile(path_to_pbf)
True
>>> os.path.relpath(path_to_pbf)  # (on Windows)
'tests\osm_data\birmingham\Birmingham.osm.pbf'
>>> # Delete the test data directory
>>> delete_dir(data_dir, verbose=True)
To delete the directory "./tests/osm_data/" (Not empty)
? [No]|Yes: yes
Deleting "./tests/osm_data/" ... Done.