GeofabrikDownloader.download_subregion_data

GeofabrikDownloader.download_subregion_data(subregion_names, osm_file_format, download_dir=None, update=False, verbose=False, ret_download_path=False)[source]

Download OSM data (in a specific file format) of one (or multiple) geographic region(s) and all its (or their) subregions.

Parameters
  • subregion_names (str or list) – name(s) of one (or multiple) region(s)/subregion(s) available on Geofabrik’s free download server

  • osm_file_format (str) – OSM file format; valid values include ".osm.pbf", ".shp.zip" and ".osm.bz2"

  • download_dir (str or None) – directory for saving the downloaded file(s); if None (default), use the default directory

  • update (bool) – whether to check on update and proceed to update the package data, defaults to False

  • verbose (bool or int) – whether to print relevant information in console, defaults to False

  • ret_download_path (bool) – whether to return the path(s) to the downloaded file(s), defaults to False

Returns

the path(s) to the downloaded file(s) when ret_download_path=True

Return type

list or str

Examples:

>>> import os
>>> from pyhelpers.dir import cd
>>> from pydriosm.downloader import GeofabrikDownloader

>>> geofabrik_downloader = GeofabrikDownloader()

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

>>> sr_names = ['rutland', 'west yorkshire']

>>> geofabrik_downloader.download_subregion_data(sr_names, file_fmt,
...                                              dwnld_dir, verbose=True)
Confirmed to download .osm.pbf data of the following geographic region(s):
    Rutland
    West Yorkshire
? [No]|Yes: yes
Downloading "rutland-latest.osm.pbf" to "\tests" ...
Done.
Downloading "west-yorkshire-latest.osm.pbf" to "\tests" ...
Done.

>>> os.remove(cd("tests", "rutland-latest.osm.pbf"))

>>> sr_names = ['west midlands', 'west yorkshire']

>>> dwnld_paths = geofabrik_downloader.download_subregion_data(
...     sr_names, file_fmt, dwnld_dir, verbose=True, ret_download_path=True)
Confirmed to download .osm.pbf data of the following geographic region(s):
    West Midlands
? [No]|Yes: yes
Downloading "west-midlands-latest.osm.pbf" to "\tests" ...
Done.
"west-yorkshire-latest.osm.pbf" is already available at "\tests".

>>> for dwnld_path in dwnld_paths: print(os.path.relpath(dwnld_path))
tests\west-midlands-latest.osm.pbf
tests\west-yorkshire-latest.osm.pbf

>>> for dwnld_path in dwnld_paths: os.remove(dwnld_path)