GeofabrikDownloader.download_subregion_data

GeofabrikDownloader.download_subregion_data(subregion_names, osm_file_format, download_dir=None, deep=False, update=False, confirmation_required=True, interval=None, verbose=False, ret_download_path=False, **kwargs)

Download OSM data (in a specific file format) of all subregions (if available) for one (or multiple) geographic region(s).

If no subregion data is available for the region(s) specified by subregion_names, then the data of subregion_names would be downloaded only.

Parameters
  • subregion_names (str or list) – name of a geographic region (or names of multiple geographic regions) available on Geofabrik free download server

  • osm_file_format (str) – file format of the OSM data available on the free download server

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

  • deep (bool) – whether to try to search for subregions of subregion(s), defaults to False

  • update (bool) – whether to update the data if it already exists, defaults to False

  • confirmation_required (bool) – whether asking for confirmation to proceed, defaults to True

  • interval (int or None) – interval (in second) between downloading two subregions, defaults to None

  • 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

  • kwargs – optional parameters of pydriosm.GeofabrikDownloader.download_osm_data()

Returns

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

Return type

list or str

Examples:

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

>>> geofabrik_downloader = GeofabrikDownloader()

>>> region_names = ['rutland', 'west yorkshire']
>>> file_format = ".pbf"
>>> dwnld_dir = "tests"

>>> geofabrik_downloader.download_subregion_data(
...     region_names, file_format, dwnld_dir, verbose=True)
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.

>>> # Delete "tests\rutland-latest.osm.pbf"
>>> os.remove(cd(dwnld_dir, "rutland-latest.osm.pbf"))

>>> # Try to download data given another list which also includes 'West Yorkshire'
>>> region_names = ['west midlands', 'west yorkshire']

>>> dwnld_paths = geofabrik_downloader.download_subregion_data(
...     region_names, file_format, dwnld_dir, verbose=True, ret_download_path=True)
"west-yorkshire-latest.osm.pbf" is already available at "tests\".
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.

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

>>> # Update (or re-download) the existing data file
>>> dwnld_paths = geofabrik_downloader.download_subregion_data(
...     region_names, file_format, dwnld_dir, update=True, verbose=True,
...     ret_download_path=True)
"west-midlands-latest.osm.pbf" is already available at "tests\".
"west-yorkshire-latest.osm.pbf" is already available at "tests\".
To update the .osm.pbf data of the following geographic region(s):
    West Midlands
    West Yorkshire
? [No]|Yes: yes
Updating "west-midlands-latest.osm.pbf" at "tests\" ... Done.
Updating "west-yorkshire-latest.osm.pbf" at "tests\" ... Done.

>>> # To download the PBF data of England
>>> region_names = 'England'

>>> dwnld_paths = geofabrik_downloader.download_subregion_data(
...     region_names, file_format, dwnld_dir, update=True, verbose=True,
...     ret_download_path=True)
"west-midlands-latest.osm.pbf" is already available at "tests\".
"west-yorkshire-latest.osm.pbf" is already available at "tests\".
To download/update the .osm.pbf data of the following geographic region(s):
    Bedfordshire
    Berkshire
    ...
    West Midlands
    ...
    West Yorkshire
    Wiltshire
    Worcestershire
? [No]|Yes: yes
Downloading "bedfordshire-latest.osm.pbf" to "tests\" ... Done.
Downloading "berkshire-latest.osm.pbf" to "tests\" ... Done.
...
Updating "west-midlands-latest.osm.pbf" at "tests\" ... Done.
...
Updating "west-yorkshire-latest.osm.pbf" at "tests\" ... Done.
Downloading "wiltshire-latest.osm.pbf" to "tests\" ... Done.
Downloading "worcestershire-latest.osm.pbf" to "tests\" ... Done.

>>> len(dwnld_paths)
47

>>> # Delete the downloaded files
>>> for dwnld_path in dwnld_paths:
...     os.remove(dwnld_path)