PbfFileReader¶
quackosm.pbf_file_reader.PbfFileReader(
tags_filter=None,
geometry_filter=None,
custom_sql_filter=None,
working_directory="files",
osm_way_polygon_features_config=None,
parquet_compression="snappy",
osm_extract_source=OsmExtractSource.any,
verbosity_mode="transient",
geometry_coverage_iou_threshold=0.01,
allow_uncovered_geometry=False,
debug_memory=False,
debug_times=False,
)
¶
quackosm.pbf_file_reader.PbfFileReader(
tags_filter=None,
geometry_filter=None,
custom_sql_filter=None,
working_directory="files",
osm_way_polygon_features_config=None,
parquet_compression="snappy",
osm_extract_source=OsmExtractSource.any,
verbosity_mode="transient",
geometry_coverage_iou_threshold=0.01,
allow_uncovered_geometry=False,
debug_memory=False,
debug_times=False,
)
PbfFileReader.
PBF(Protocolbuffer Binary Format)[1] file reader is a dedicated *.osm.pbf
files reader
class based on DuckDB[2] and its spatial extension[3].
Handler can filter out OSM features based on tags filter and geometry filter to limit the result.
References
PARAMETER | DESCRIPTION |
---|---|
tags_filter |
A dictionary
specifying which tags to download.
The keys should be OSM tags (e.g.
TYPE:
|
geometry_filter |
Region which can be used to filter only
intersecting OSM objects. Defaults to
TYPE:
|
custom_sql_filter |
Allows users to pass custom SQL conditions used
to filter OSM features. It will be embedded into predefined queries and requires
DuckDB syntax to operate on tags map object. Defaults to
TYPE:
|
working_directory |
Directory where to save
the parsed
TYPE:
|
osm_way_polygon_features_config |
Config used to determine which closed way features are polygons. Modifications to this config left are left for experienced OSM users. Defaults to predefined "osm_way_polygon_features.json".
TYPE:
|
parquet_compression |
Compression of intermediate parquet files. Check https://duckdb.org/docs/sql/statements/copy#parquet-options for more info. Defaults to "snappy".
TYPE:
|
osm_extract_source |
A source for automatic
downloading of OSM extracts. Can be Geofabrik, BBBike, OSMfr or any.
Defaults to
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:
|
geometry_coverage_iou_threshold |
Minimal value of the Intersection over Union metric for selecting the matching OSM extracts. Is best matching extract has value lower than the threshold, it is discarded (except the first one). Has to be in range between 0 and 1. Value of 0 will allow every intersected extract, value of 1 will only allow extracts that match the geometry exactly. Defaults to 0.01.
TYPE:
|
allow_uncovered_geometry |
Suppress an error if some geometry parts
aren't covered by any OSM extract. Defaults to
TYPE:
|
debug_memory |
If turned on, will keep all temporary files after
operation for debugging. Defaults to
TYPE:
|
debug_times |
If turned on, will report timestamps at which second each
step has been executed. Defaults to
TYPE:
|
RAISES | DESCRIPTION |
---|---|
InvalidGeometryFilter
|
When provided geometry filter has parts without area. |
Source code in quackosm/pbf_file_reader.py
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 |
|
¶
Bases: NamedTuple
List of parquet files read from the *.osm.pbf
file.
convert_pbf_to_parquet(
pbf_path,
result_file_path=None,
keep_all_tags=False,
explode_tags=None,
ignore_cache=False,
filter_osm_ids=None,
save_as_wkt=False,
pbf_extract_geometry=None,
)
¶
convert_pbf_to_parquet(
pbf_path,
result_file_path=None,
keep_all_tags=False,
explode_tags=None,
ignore_cache=False,
filter_osm_ids=None,
save_as_wkt=False,
pbf_extract_geometry=None,
)
Convert PBF file to GeoParquet file.
PARAMETER | DESCRIPTION |
---|---|
pbf_path |
Path or list of paths of
TYPE:
|
result_file_path |
Where to save
the geoparquet file. If not provided, will be generated based on hashes
from provided tags filter and geometry filter. Defaults to
TYPE:
|
keep_all_tags |
Works only with the
TYPE:
|
explode_tags |
Whether to split tags into columns based on OSM tag keys.
If
TYPE:
|
ignore_cache |
Whether to ignore precalculated geoparquet files or not. Defaults to False.
TYPE:
|
filter_osm_ids |
(list[str], optional): List of OSM features ids to read from the file.
Have to be in the form of 'node/
TYPE:
|
save_as_wkt |
Whether to save the file with geometry in the WKT form instead
of WKB. If
TYPE:
|
pbf_extract_geometry |
List of geometries defining PBF extract. Used internally to speed up intersections
for complex filters. Defaults to
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Path
|
Path to the generated GeoParquet file.
TYPE:
|
Source code in quackosm/pbf_file_reader.py
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 |
|
convert_geometry_to_parquet(
result_file_path=None,
keep_all_tags=False,
explode_tags=None,
ignore_cache=False,
filter_osm_ids=None,
save_as_wkt=False,
)
¶
convert_geometry_to_parquet(
result_file_path=None,
keep_all_tags=False,
explode_tags=None,
ignore_cache=False,
filter_osm_ids=None,
save_as_wkt=False,
)
Convert geometry to GeoParquet file.
Will automatically find and download OSM extracts covering a given geometry and convert them to a single GeoParquet file.
PARAMETER | DESCRIPTION |
---|---|
result_file_path |
Where to save
the geoparquet file. If not provided, will be generated based on hashes
from provided tags filter and geometry filter. Defaults to
TYPE:
|
keep_all_tags |
Works only with the
TYPE:
|
explode_tags |
Whether to split tags into columns based on OSM tag keys.
If
TYPE:
|
ignore_cache |
Whether to ignore precalculated geoparquet files or not. Defaults to False.
TYPE:
|
filter_osm_ids |
(list[str], optional): List of OSM features ids to read from the file.
Have to be in the form of 'node/
TYPE:
|
save_as_wkt |
Whether to save the file with geometry in the WKT form instead
of WKB. If
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Path
|
Path to the generated GeoParquet file.
TYPE:
|
Source code in quackosm/pbf_file_reader.py
511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 |
|
convert_pbf_to_geodataframe(
pbf_path,
keep_all_tags=False,
explode_tags=None,
ignore_cache=False,
filter_osm_ids=None,
)
¶
convert_pbf_to_geodataframe(
pbf_path,
keep_all_tags=False,
explode_tags=None,
ignore_cache=False,
filter_osm_ids=None,
)
Get features GeoDataFrame from a list of PBF files.
Function parses multiple PBF files and returns a single GeoDataFrame with parsed OSM objects.
PARAMETER | DESCRIPTION |
---|---|
pbf_path |
Path or list of paths of
TYPE:
|
keep_all_tags |
Works only with the
TYPE:
|
explode_tags |
Whether to split tags into columns based on OSM tag keys.
If
TYPE:
|
ignore_cache |
(bool, optional): Whether to ignore precalculated geoparquet files or not. Defaults to False.
TYPE:
|
filter_osm_ids |
(list[str], optional): List of OSM features ids to read from the file.
Have to be in the form of 'node/
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
GeoDataFrame
|
gpd.GeoDataFrame: GeoDataFrame with OSM features. |
Source code in quackosm/pbf_file_reader.py
convert_geometry_to_geodataframe(
keep_all_tags=False,
explode_tags=None,
ignore_cache=False,
filter_osm_ids=None,
)
¶
convert_geometry_to_geodataframe(
keep_all_tags=False,
explode_tags=None,
ignore_cache=False,
filter_osm_ids=None,
)
Get features GeoDataFrame from a provided geometry filter.
Will automatically find and download OSM extracts covering a given geometry and return a single GeoDataFrame with parsed OSM objects.
PARAMETER | DESCRIPTION |
---|---|
keep_all_tags |
Works only with the
TYPE:
|
explode_tags |
Whether to split tags into columns based on OSM tag keys.
If
TYPE:
|
ignore_cache |
(bool, optional): Whether to ignore precalculated geoparquet files or not. Defaults to False.
TYPE:
|
filter_osm_ids |
(list[str], optional): List of OSM features ids to read from the file.
Have to be in the form of 'node/
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
GeoDataFrame
|
gpd.GeoDataFrame: GeoDataFrame with OSM features. |
Source code in quackosm/pbf_file_reader.py
convert_pbf_to_duckdb(
pbf_path,
result_file_path=None,
keep_all_tags=False,
explode_tags=None,
ignore_cache=False,
filter_osm_ids=None,
duckdb_table_name="quackosm",
)
¶
convert_pbf_to_duckdb(
pbf_path,
result_file_path=None,
keep_all_tags=False,
explode_tags=None,
ignore_cache=False,
filter_osm_ids=None,
duckdb_table_name="quackosm",
)
Convert PBF file to DuckDB Database.
Function parses multiple PBF files and returns a single GeoDataFrame with parsed OSM objects.
PARAMETER | DESCRIPTION |
---|---|
pbf_path |
Path or list of paths of
TYPE:
|
result_file_path |
Where to save
the duckdb file. If not provided, will be generated based on hashes
from provided tags filter and geometry filter. Defaults to
TYPE:
|
keep_all_tags |
Works only with the
TYPE:
|
explode_tags |
Whether to split tags into columns based on OSM tag keys.
If
TYPE:
|
ignore_cache |
(bool, optional): Whether to ignore precalculated geoparquet files or not. Defaults to False.
TYPE:
|
filter_osm_ids |
(list[str], optional): List of OSM features ids to read from the file.
Have to be in the form of 'node/
TYPE:
|
duckdb_table_name |
Table name in which data will be stored inside the DuckDB database (default: "quackosm")
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Path
|
gpd.GeoDataFrame: GeoDataFrame with OSM features. |
Source code in quackosm/pbf_file_reader.py
708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 |
|
convert_geometry_to_duckdb(
result_file_path=None,
keep_all_tags=False,
explode_tags=None,
ignore_cache=False,
filter_osm_ids=None,
duckdb_table_name="quackosm",
)
¶
convert_geometry_to_duckdb(
result_file_path=None,
keep_all_tags=False,
explode_tags=None,
ignore_cache=False,
filter_osm_ids=None,
duckdb_table_name="quackosm",
)
Get features GeoDataFrame from a provided geometry filter.
Will automatically find and download OSM extracts covering a given geometry and return a single GeoDataFrame with parsed OSM objects.
PARAMETER | DESCRIPTION |
---|---|
result_file_path |
Where to save
the duckdb file. If not provided, will be generated based on hashes
from provided tags filter and geometry filter. Defaults to
TYPE:
|
keep_all_tags |
Works only with the
TYPE:
|
explode_tags |
Whether to split tags into columns based on OSM tag keys.
If
TYPE:
|
ignore_cache |
(bool, optional): Whether to ignore precalculated geoparquet files or not. Defaults to False.
TYPE:
|
filter_osm_ids |
(list[str], optional): List of OSM features ids to read from the file.
Have to be in the form of 'node/
TYPE:
|
duckdb_table_name |
Table name in which data will be stored inside the DuckDB database (default: "quackosm")
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Path
|
gpd.GeoDataFrame: GeoDataFrame with OSM features. |