OSMPbfLoader
srai.loaders.OSMPbfLoader ¶
OSMPbfLoader(
pbf_file: Optional[Union[str, Path]] = None,
download_source: OsmExtractSource = "any",
download_directory: Union[str, Path] = "files",
verbosity_mode: Literal["silent", "transient", "verbose"] = "transient",
)
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:
|
verbosity_mode
|
Set progress verbosity mode. Can be one of: silent, transient and verbose. Silent disables output completely. Transient tracks progress, but removes output after finished. Verbose leaves all progress outputs in the stdout. Defaults to "transient".
TYPE:
|
Source code in srai/loaders/osm_loaders/osm_pbf_loader.py
load ¶
load(
area: Union[
BaseGeometry, Iterable[BaseGeometry], gpd.GeoSeries, gpd.GeoDataFrame
],
tags: Union[OsmTagsFilter, GroupedOsmTagsFilter],
ignore_cache: bool = False,
explode_tags: bool = True,
keep_all_tags: bool = False,
) -> gpd.GeoDataFrame
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_to_geoparquet ¶
load_to_geoparquet(
area: Union[
BaseGeometry, Iterable[BaseGeometry], gpd.GeoSeries, gpd.GeoDataFrame
],
tags: Union[OsmTagsFilter, GroupedOsmTagsFilter],
ignore_cache: bool = False,
explode_tags: bool = True,
keep_all_tags: bool = False,
) -> Path
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:
|