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_nameis located/saved; ifNone(default), the default local directory
- Returns:
path to PBF (.osm.pbf) file
- Return type:
pathlib.Path | None
Examples:
>>> from pydriosm.reader import BBBikeReader >>> from pyhelpers.dirs import delete_dir, get_relative_path >>> 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 >>> path_to_pbf.is_file() 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 with downloading data in the format ".pbf" for the following geographic (su... "Birmingham" to "tests/osm_data/birmingham/" ? [No]|Yes: yes Downloading "Birmingham.osm.pbf" 100%|██████████| 57.3M/57.3M | 16.3MB/s | E... 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) >>> path_to_pbf.is_file() True >>> get_relative_path(path_to_pbf, as_str=True) 'tests/osm_data/birmingham/Birmingham.osm.pbf' >>> # Delete the test data directory >>> delete_dir(data_dir, verbose=True) Confirm deletion of the directory "tests/osm_data/" (Not empty)? [No]|Yes: yes Deleting "tests/osm_data/" ... Done.