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,
compression=PARQUET_COMPRESSION,
compression_level=PARQUET_COMPRESSION_LEVEL,
row_group_size=PARQUET_ROW_GROUP_SIZE,
osm_extract_source=OsmExtractSource.any,
verbosity_mode="transient",
geometry_coverage_iou_threshold=0.01,
allow_uncovered_geometry=False,
ignore_metadata_tags=True,
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,
compression=PARQUET_COMPRESSION,
compression_level=PARQUET_COMPRESSION_LEVEL,
row_group_size=PARQUET_ROW_GROUP_SIZE,
osm_extract_source=OsmExtractSource.any,
verbosity_mode="transient",
geometry_coverage_iou_threshold=0.01,
allow_uncovered_geometry=False,
ignore_metadata_tags=True,
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:
|
compression
|
Compression of the final parquet file. Check https://duckdb.org/docs/sql/statements/copy#parquet-options for more info. Remember to change compression level together with this parameter. Defaults to "zstd".
TYPE:
|
compression_level
|
Compression level of the final parquet file. Check https://duckdb.org/docs/sql/statements/copy#parquet-options for more info. Defaults to 3.
TYPE:
|
row_group_size
|
Approximate number of rows per row group in the final parquet file. Defaults to 100_000.
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:
|
ignore_metadata_tags
|
Remove metadata tags, based on the default GDAL
config. 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
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 250 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 |
|
task_progress_tracker
property
¶
Get task progress tracker.
¶
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,
sort_result=True,
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,
sort_result=True,
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:
|
sort_result
|
Whether to sort the result by geometry or not. Defaults to True.
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
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 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 |
|
convert_geometry_to_parquet(
result_file_path=None,
keep_all_tags=False,
explode_tags=None,
sort_result=True,
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,
sort_result=True,
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:
|
sort_result
|
Whether to sort the result by geometry or not. Defaults to True.
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
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 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 |
|
convert_pbf_to_geodataframe(
pbf_path,
keep_all_tags=False,
explode_tags=None,
sort_result=True,
ignore_cache=False,
filter_osm_ids=None,
)
¶
convert_pbf_to_geodataframe(
pbf_path,
keep_all_tags=False,
explode_tags=None,
sort_result=True,
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:
|
sort_result
|
Whether to sort the result by geometry or not. Defaults to True.
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,
sort_result=True,
ignore_cache=False,
filter_osm_ids=None,
)
¶
convert_geometry_to_geodataframe(
keep_all_tags=False,
explode_tags=None,
sort_result=True,
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:
|
sort_result
|
Whether to sort the result by geometry or not. Defaults to True.
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,
sort_result=True,
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,
sort_result=True,
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:
|
sort_result
|
Whether to sort the result by geometry or not. Defaults to True.
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
792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 |
|
convert_geometry_to_duckdb(
result_file_path=None,
keep_all_tags=False,
explode_tags=None,
sort_result=True,
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,
sort_result=True,
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:
|
sort_result
|
Whether to sort the result by geometry or not. Defaults to True.
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
882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 |
|