OSMPbfLoader
srai.loaders.OSMPbfLoader(
pbf_file=None,
download_source="geofabrik",
download_directory="files",
)
¶
srai.loaders.OSMPbfLoader(
pbf_file=None,
download_source="geofabrik",
download_directory="files",
)
Bases: OSMLoader
OSMPbfLoader.
OSM(OpenStreetMap)[1] PBF(Protocolbuffer Binary Format)[2] loader is a loader capable of loading OSM features from a PBF file. It filters features based on OSM tags[3] in form of key:value pairs, that are used by OSM users to give meaning to geometries.
This loader uses PbfFileReader from the QuackOSM[3] library.
It utilizes the duckdb[4] engine with spatial[5] extension
capable of parsing an *.osm.pbf file.
Additionally, it can download a pbf file extract for a given area using different sources.
References
| PARAMETER | DESCRIPTION |
|---|---|
pbf_file |
Downloaded
TYPE:
|
download_source |
Source to use when downloading PBF files.
Can be one of:
TYPE:
|
download_directory |
Directory where to save the downloaded
TYPE:
|
Source code in srai/loaders/osm_loaders/osm_pbf_loader.py
¶
Load OSM features with specified tags for a given area from an *.osm.pbf file.
The loader will use provided *.osm.pbf file, or download extracts
automatically. Later it will parse and filter features from files
using PbfFileReader from QuackOSM library. It will return a GeoDataFrame
containing the geometry column and columns for tag keys.
Some key/value pairs might be missing from the resulting GeoDataFrame,
simply because there are no such objects in the given area.
| PARAMETER | DESCRIPTION |
|---|---|
area |
Area for which to download objects.
TYPE:
|
tags |
A dictionary
specifying which tags to download.
The keys should be OSM tags (e.g.
TYPE:
|
ignore_cache |
(bool, optional): Whether to ignore precalculated geoparquet files or not. Defaults to False.
TYPE:
|
explode_tags |
(bool, optional): Whether to split OSM tags into multiple columns or keep them in a single dict. Defaults to True.
TYPE:
|
keep_all_tags |
(bool, optional): Whether to keep all tags related to the element,
or return only those defined in the
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If PBF file is expected to be downloaded and provided geometries aren't shapely.geometry.Polygons. |
| RETURNS | DESCRIPTION |
|---|---|
GeoDataFrame
|
gpd.GeoDataFrame: Downloaded features as a GeoDataFrame. |
Source code in srai/loaders/osm_loaders/osm_pbf_loader.py
¶
Load OSM features with specified tags for a given area and save it to geoparquet file.
| PARAMETER | DESCRIPTION |
|---|---|
area |
Area for which to download objects.
TYPE:
|
tags |
A dictionary
specifying which tags to download.
The keys should be OSM tags (e.g.
TYPE:
|
ignore_cache |
(bool, optional): Whether to ignore precalculated geoparquet files or not. Defaults to False.
TYPE:
|
explode_tags |
(bool, optional): Whether to split OSM tags into multiple columns or keep them in a single dict. Defaults to True.
TYPE:
|
keep_all_tags |
(bool, optional): Whether to keep all tags related to the element,
or return only those defined in the
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Path
|
Path to the saved GeoParquet file.
TYPE:
|