GeofabrikDownloader.download_osm_data¶
-
GeofabrikDownloader.
download_osm_data
(subregion_names, osm_file_format, download_dir=None, update=False, confirmation_required=True, deep_retry=False, interval_sec=None, verbose=False, ret_download_path=False)[source]¶ Download OSM data (in a specific file format) of one (or multiple) geographic region(s).
- Parameters
subregion_names (str or list) – name(s) of one (or multiple) geographic region(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
confirmation_required (bool) – whether to prompt a message for confirmation to proceed, defaults to
True
deep_retry (bool) – whether to further check availability of sub-subregions data, defaults to
False
interval_sec (int or None) – interval (in sec) 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
- Returns
absolute path(s) to downloaded file(s) when
ret_download_path=True
- Return type
list or str
Examples:
>>> import os >>> from pyhelpers.dir import delete_dir >>> from pydriosm.downloader import GeofabrikDownloader, cd_dat_geofabrik >>> geofabrik_downloader = GeofabrikDownloader() >>> # Download PBF data file of Greater London and Rutland >>> sr_names = ['London', 'Rutland'] >>> file_fmt = ".pbf" >>> dwnld_paths = geofabrik_downloader.download_osm_data( ... sr_names, file_fmt, verbose=True, ret_download_path=True) Confirmed to download .osm.pbf data of the following geographic region(s): Greater London Rutland ? [No]|Yes: yes Downloading "greater-london-latest.osm.pbf" to "\dat_... \England" ... Done. Downloading "rutland-latest.osm.pbf" to "\dat_... \England" ... Done. >>> for dwnld_path in dwnld_paths: ... print(os.path.relpath(dwnld_path)) dat_GeoFabrik\Europe\Great Britain\England\greater-london-latest.osm.pbf dat_GeoFabrik\Europe\Great Britain\England\rutland-latest.osm.pbf >>> # Delete the directory generated above >>> delete_dir(cd_dat_geofabrik(), verbose=True) The directory "\dat_Geofabrik" is not empty. Confirmed to delete it? [No]|Yes: yes Deleting "\dat_Geofabrik" ... Done. >>> # Download shapefiles of West Midlands >>> sr_name = 'west midlands' >>> file_fmt = ".shp" >>> dwnld_dir = "tests" >>> dwnld_path = geofabrik_downloader.download_osm_data( ... sr_name, file_fmt, dwnld_dir, verbose=True, ret_download_path=True) Confirmed to download .shp.zip data of the following geographic region(s): West Midlands ? [No]|Yes: yes Downloading "west-midlands-latest-free.shp.zip" to "\tests" ... Done. >>> print(os.path.relpath(dwnld_path)) tests\west-midlands-latest-free.shp.zip >>> # Delete the downloaded .shp.zip file >>> os.remove(dwnld_path) >>> # Download shapefiles of Great Britain >>> sr_name = 'Great Britain' >>> file_fmt = ".shp" >>> dwnld_path = geofabrik_downloader.download_osm_data( ... sr_name, file_fmt, dwnld_dir, deep_retry=True, verbose=True, ... ret_download_path=True) Confirmed to download .shp.zip data of the following geographic region(s): Great Britain ? [No]|Yes: yes The .shp.zip data is not found for "Great Britain". Try downloading the data of its subregions instead [No]|Yes: no >>> print(dwnld_path) []