GeofabrikReader.read_gpkg¶
- GeofabrikReader.read_gpkg(subregion_name, layer_names=None, feature_names=None, data_dir=None, update=False, download=False, verbose=False, raise_error=True, **kwargs)[source]¶
Reads GeoPackage (.gpkg.zip) data for a specific subregion.
- Parameters:
subregion_name (str) – Name of the subregion (e.g. ‘West Midlands’ or ‘london’).
layer_names (str | list | None) – Specific OSM layer(s) to load (e.g., ‘points’, ‘roads’); defaults to
None(loads all available layers).feature_names (str | list | None) – Specific feature type(s) to extract from the loaded layers (e.g., ‘residential’, ‘motorway’); defaults to
None.data_dir (str | os.PathLike | None) – Directory where the data file is stored or will be downloaded to; defaults to
None.update (bool) – Whether to update the local file by re-downloading it; defaults to
False.download (bool) – Whether to download the file if it is missing locally; defaults to
False.verbose (bool) – Whether to print progress messages to the console; defaults to
False.raise_error (bool) – Whether to raise an exception if an error occurs during parsing; defaults to
True.kwargs (Any) – Additional optional arguments for
pyhelpers.store.load_geopackage().
- Returns:
A GeoDataFrame (if a single layer is resolved) or a dictionary of GeoDataFrames (keyed by layer names).
- Return type:
geopandas.GeoDataFrame | dict | None
Examples:
>>> from pydriosm.reader import GeofabrikReader >>> from pyhelpers.dirs import cd, delete_dir >>> gbr = GeofabrikReader() >>> subregion_name = 'West midlands' >>> data_dir = "tests/osm_data" >>> wm_gpkg = gbr.read_gpkg(subregion_name, data_dir=data_dir, verbose=True) Traceback (most recent call last): ... FileNotFoundError: The shapefile "west-midlands-latest-free.gpkg.zip" is not availa... Set `download=True` to download it. >>> wm_gpkg = gbr.read_gpkg( ... subregion_name, data_dir=data_dir, verbose=True, download=True) Downloading "west-midlands-latest-free.gpkg.zip" 100%|██████████| 103M/103M |... Saving "west-midlands-latest-free.gpkg.zip" to "./tests/osm_data/west-midlands/" ... Parsing the data ... Done. >>> type(wm_gpkg) dict >>> list(wm_gpkg.keys()) ['traffic', 'pois', 'transport', 'places', 'pofw', 'natural', 'roads', 'railways', 'waterways', 'landuse', 'water', 'protected_areas', 'buildings', 'adminareas'] >>> delete_dir(data_dir, verbose=True) # Delete the downloaded .csv.xz data file To delete the directory "./tests/osm_data/" (Not empty) ? [No]|Yes: yes Deleting "./tests/osm_data/" ... Done.