PBF File Reader¶
PBFFileReader
can really quickly parse full OSM extract in the form of *.osm.pbf
file.
It uses DuckDB
with spatial
extension to convert pbf
files into geoparquet
files without GDAL dependency.
Reader can filter objects by geometry and by OSM tags with option to split tags into columns or keep it as a single dictionary.
Caching strategy is implemented to reduce computations, but it can be overriden using ignore_cache
parameter.
Download all buildings in Reykjavík, Iceland¶
Filtering the data with geometry and by tags, with tags in exploded form
import urllib.request
from quackosm import PbfFileReader, geocode_to_geometry
iceland_pbf_url = "https://download.geofabrik.de/europe/iceland-latest.osm.pbf"
iceland_pbf_file = "iceland.osm.pbf"
urllib.request.urlretrieve(iceland_pbf_url, iceland_pbf_file)
('iceland.osm.pbf', <http.client.HTTPMessage at 0x7f16d7b21700>)
reykjavik_geometry = geocode_to_geometry("Reykjavík, IS")
reykjavik_geometry
To filter out buildings, we will utilize format used also in the osmnx
library: a dictionary with keys representing tag keys and values that could be a bool, string or a list of string.
By default, QuackOSM
will return only the tags that are present in the passed filter.
In this example we will select all the buildings using { "building": True }
filter and only building
tag values will be present in the result.
reader = PbfFileReader(
geometry_filter=reykjavik_geometry, tags_filter={"building": True}
)
reykjavik_buildings_gpq = reader.convert_pbf_to_parquet("iceland.osm.pbf")
reykjavik_buildings_gpq
Finished operation in 0:00:19
PosixPath('files/iceland_ae99e3d9_4e8a6f65_exploded_sorted.parquet')
Read those features using DuckDB¶
import duckdb
connection = duckdb.connect()
connection.load_extension("parquet")
connection.load_extension("spatial")
features_relation = connection.read_parquet(str(reykjavik_buildings_gpq))
features_relation
┌────────────────┬────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┬──────────────┐ │ feature_id │ geometry │ building │ │ varchar │ geometry │ varchar │ ├────────────────┼────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼──────────────┤ │ way/61934038 │ POLYGON ((-21.8437438 64.1084884, -21.8437503 64.1082447, -21.8437548 64.1080761, -21.844211 64.1080784, -21.8442 64.1084907, -21.8437438 64.1084884)) │ yes │ │ way/61934018 │ POLYGON ((-21.8431866 64.1079564, -21.8431225 64.1079561, -21.843123 64.1079396, -21.8431273 64.1077785, -21.8431962 64.1077788, -21.843197 64.1077511, -21.843708 64.1077537, -21.8437072 64.1077839, -21.843764 64.1077841, -21.8437592 64.1079616, -21.8436976 64.1079613, -21.8436962 64.1080122, -21.8431852 64.1080096, -21.8431866 64.1079564)) │ apartments │ │ way/61933932 │ POLYGON ((-21.8434848 64.1070313, -21.8434268 64.1070543, -21.843394 64.1069969, -21.8432922 64.1070146, -21.843207 64.1070404, -21.8433233 64.1070904, -21.8432325 64.1070969, -21.8432383 64.1071307, -21.843187 64.1071575, -21.8432326 64.1071819, -21.8432242 64.1072204, -21.843299 64.1072354, -21.8433326 64.1072691, -21.8433761 64.107268, -21.843322 64.1073354, -21.8433933 64.1073462, -21.8434693 64.107349, -21.8435612 64.1073458, -21.8436249 64.1073376, -21.8435791 64.1072684, -21.8436211 64.1072707, -21.8436537 64.1072371, -21.8437317 64.1072233, -21.8437179 64.1071874, -21.8437759 64.1071601, -21.8437236 64.1071316, -21.8437386 64.1070967, -21.8436633 64.107085, -21.8436326 64.1070471, -21.8435497 64.1070556, -21.8434848 64.1070313)) │ church │ │ way/61934167 │ POLYGON ((-21.8443402 64.108232, -21.8443443 64.1080791, -21.8443535 64.1077336, -21.8443541 64.1077086, -21.8448455 64.1077111, -21.8448425 64.1078236, -21.8449022 64.1078239, -21.844893 64.1081703, -21.8447929 64.1081698, -21.8447912 64.1082342, -21.8443402 64.108232)) │ yes │ │ way/1346502222 │ POLYGON ((-21.8523431 64.1054147, -21.8520855 64.1051045, -21.8482221 64.1057163, -21.8484909 64.1060401, -21.8491877 64.1059297, -21.8491363 64.1058678, -21.8513297 64.1055207, -21.8513697 64.1055689, -21.8523431 64.1054147)) │ construction │ │ way/849242393 │ POLYGON ((-21.8477126 64.1052314, -21.8477865 64.1053217, -21.8480253 64.1052844, -21.848183 64.105477, -21.8479411 64.1055148, -21.8480191 64.10561, -21.8484656 64.1055403, -21.848156 64.1051621, -21.8477126 64.1052314)) │ yes │ │ way/204102373 │ POLYGON ((-21.8451786 64.1055617, -21.8456047 64.1056787, -21.84601 64.10579, -21.8459173 64.1058544, -21.8459857 64.1058727, -21.846112 64.1057827, -21.8461856 64.1058025, -21.846246 64.1057594, -21.8461874 64.1057437, -21.8463012 64.1056626, -21.8462285 64.1056428, -21.8461376 64.1057066, -21.8457298 64.1055958, -21.8457048 64.1055488, -21.8455401 64.1055041, -21.8454232 64.105516, -21.8452938 64.1054809, -21.8451786 64.1055617)) │ yes │ │ way/95141704 │ POLYGON ((-21.846527 64.1057239, -21.8463012 64.1056626, -21.8462285 64.1056428, -21.8460204 64.1055863, -21.8461907 64.1054668, -21.8466973 64.1056044, -21.846527 64.1057239)) │ residential │ │ way/95141705 │ POLYGON ((-21.846062 64.1060629, -21.8455547 64.1059271, -21.8457279 64.1058037, -21.8459173 64.1058544, -21.8459857 64.1058727, -21.8462352 64.1059395, -21.846062 64.1060629)) │ residential │ │ way/923188606 │ POLYGON ((-21.8471423 64.1058071, -21.847081 64.1058173, -21.8470434 64.1057739, -21.8471047 64.1057638, -21.8471423 64.1058071)) │ yes │ │ · │ · │ · │ │ · │ · │ · │ │ · │ · │ · │ │ way/107499294 │ POLYGON ((-21.7755766 64.1469719, -21.7755096 64.1470595, -21.7752141 64.1470165, -21.7752811 64.146929, -21.7755766 64.1469719)) │ residential │ │ way/107499177 │ POLYGON ((-21.7754569 64.1467157, -21.775356 64.146701, -21.775364 64.1466906, -21.775276 64.1466778, -21.7753539 64.1465759, -21.7755428 64.1466033, -21.7754569 64.1467157)) │ residential │ │ way/107499229 │ POLYGON ((-21.7755643 64.1465752, -21.7755428 64.1466033, -21.7754569 64.1467157, -21.7755562 64.1467301, -21.7755641 64.1467197, -21.7756519 64.1467325, -21.7757314 64.1466285, -21.7756284 64.1466135, -21.7756483 64.1465874, -21.7755643 64.1465752)) │ residential │ │ way/107499255 │ POLYGON ((-21.7752934 64.1461881, -21.7752114 64.1462968, -21.7752789 64.1463065, -21.7752873 64.1462954, -21.775333 64.146302, -21.7754066 64.1462044, -21.7752934 64.1461881)) │ residential │ │ way/107499264 │ POLYGON ((-21.7752934 64.1461881, -21.7751811 64.146172, -21.7751072 64.1462698, -21.7751482 64.1462757, -21.77514 64.1462865, -21.7752114 64.1462968, -21.7752934 64.1461881)) │ residential │ │ way/107499296 │ POLYGON ((-21.7761242 64.1464504, -21.7757389 64.1464324, -21.7757639 64.1463304, -21.7758411 64.146334, -21.7758569 64.1462695, -21.7760925 64.1462805, -21.7760762 64.1463471, -21.7761487 64.1463505, -21.7761242 64.1464504)) │ residential │ │ way/107499263 │ POLYGON ((-21.7764388 64.1460403, -21.7760522 64.1460214, -21.7760782 64.1459203, -21.7761569 64.1459241, -21.7761739 64.1458582, -21.7764086 64.1458697, -21.7763911 64.1459377, -21.7764643 64.1459413, -21.7764388 64.1460403)) │ residential │ │ way/107499211 │ POLYGON ((-21.777345 64.1460877, -21.7769605 64.146069, -21.7769871 64.1459652, -21.7770648 64.145969, -21.7770811 64.1459053, -21.7773149 64.1459167, -21.7772981 64.1459821, -21.7773712 64.1459856, -21.777345 64.1460877)) │ residential │ │ way/107499191 │ POLYGON ((-21.7757411 64.1455954, -21.7756575 64.1457061, -21.7757288 64.1457164, -21.7757386 64.1457035, -21.7757862 64.1457103, -21.7758601 64.1456125, -21.7757411 64.1455954)) │ residential │ │ way/107499218 │ POLYGON ((-21.7755203 64.1458898, -21.7754103 64.145874, -21.7753376 64.1459708, -21.7753777 64.1459765, -21.7753691 64.145988, -21.7754389 64.145998, -21.7755203 64.1458898)) │ residential │ ├────────────────┴────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┴──────────────┤ │ ? rows (>9999 rows, 20 shown) 3 columns │ └────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
Count all buildings¶
features_relation.count("feature_id")
┌───────────────────┐ │ count(feature_id) │ │ int64 │ ├───────────────────┤ │ 25389 │ └───────────────────┘
Keeping all the tags while filtering the data¶
To keep all of the tags present in the source data, we can use keep_all_tags
parameter. That way we will still return only buildings, but with all of the tags attached.
By default, all of those tags will be kept in a single column as a dict
.
reader.convert_pbf_to_geodataframe("iceland.osm.pbf", keep_all_tags=True)
Finished operation in 0:00:19
tags | geometry | |
---|---|---|
feature_id | ||
way/61934038 | {'addr:housenumber': '10', 'addr:postcode': '1... | POLYGON ((-21.84374 64.10849, -21.84375 64.108... |
way/61934018 | {'addr:city': 'Reykjavík', 'addr:housenumber':... | POLYGON ((-21.84319 64.10796, -21.84312 64.107... |
way/61933932 | {'addr:housenumber': '5', 'addr:postcode': '10... | POLYGON ((-21.84348 64.10703, -21.84343 64.107... |
way/61934167 | {'addr:housenumber': '8', 'addr:postcode': '10... | POLYGON ((-21.84434 64.10823, -21.84434 64.108... |
way/1346502222 | {'addr:city': 'Reykjavík', 'addr:housenumber':... | POLYGON ((-21.85234 64.10541, -21.85209 64.105... |
... | ... | ... |
way/222355490 | {'addr:housenumber': '6', 'addr:postcode': '11... | POLYGON ((-21.69511 64.11597, -21.69516 64.115... |
way/365759197 | {'building': 'industrial'} | POLYGON ((-21.70156 64.1055, -21.70186 64.1051... |
relation/13506468 | {'addr:city': 'Reykjavík', 'addr:housenumber':... | POLYGON ((-21.69638 64.09985, -21.69636 64.099... |
way/992249961 | {'building': 'yes'} | POLYGON ((-21.6986 64.09975, -21.69855 64.0997... |
way/570226126 | {'building': 'yes'} | POLYGON ((-21.70041 64.08481, -21.70032 64.084... |
25389 rows × 2 columns
Download main roads for Estonia¶
Filtering the data only by tags, with tags in exploded form
highways_filter = {
"highway": [
"motorway",
"trunk",
"primary",
"secondary",
"tertiary",
]
}
estonia_pbf_url = "http://download.geofabrik.de/europe/estonia-latest.osm.pbf"
estonia_pbf_file = "estonia.osm.pbf"
urllib.request.urlretrieve(estonia_pbf_url, estonia_pbf_file)
reader = PbfFileReader(geometry_filter=None, tags_filter=highways_filter)
estonia_features_gpq = reader.convert_pbf_to_parquet(estonia_pbf_file)
estonia_features_gpq
Finished operation in 0:00:20
PosixPath('files/estonia_87e7b741_noclip_exploded_sorted.parquet')
features_relation = connection.read_parquet(str(estonia_features_gpq))
features_relation
┌────────────────┬──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┬───────────┐ │ feature_id │ geometry │ highway │ │ varchar │ geometry │ varchar │ ├────────────────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼───────────┤ │ way/1018216517 │ LINESTRING (22.0563349 57.9115746, 22.0565881 57.911771, 22.0567573 57.9119305, 22.0568909 57.912108, 22.0569823 57.9122961, 22.057069 57.9125329, 22.0571383 57.9127075) │ tertiary │ │ way/441801965 │ LINESTRING (22.055825 57.9111269, 22.0560882 57.9113742, 22.0563349 57.9115746) │ tertiary │ │ way/37439072 │ LINESTRING (22.0571383 57.9127075, 22.0571903 57.9127901, 22.0573036 57.9128767, 22.0573909 57.9129283, 22.0575834 57.9129985, 22.0576021 57.9130034, 22.0579829 57.9131031, 22.0581652 57.9131651, 22.0583127 57.913228, 22.0584328 57.9132951, 22.0585628 57.9133852, 22.0586936 57.9134988, 22.058829 57.9136461, 22.0594326 57.9143824, 22.0596083 57.9145685, 22.0597846 57.9147444, 22.060021 57.9149467, 22.0606738 57.9154739, 22.0613254 57.9160024, 22.06168 57.9162791, 22.0619472 57.9164677, 22.0621751 57.9166234, 22.0626801 57.9169592, 22.0630516 57.9171963, 22.0632575 57.9173115, 22.0634442 57.9174006, 22.0636074 57.9174747, 22.0637146 57.917547, 22.0638036 57.9176209, 22.0640832 57.9178738) │ tertiary │ │ way/1018216516 │ LINESTRING (22.0640832 57.9178738, 22.0642168 57.9179896, 22.0642584 57.918064, 22.0642581 57.9181382) │ tertiary │ │ way/232265919 │ LINESTRING (22.0409996 58.0039353, 22.0388314 58.002661, 22.03839 58.0025194, 22.0380646 58.0024242, 22.0376184 58.0022958, 22.0370582 58.0021423, 22.0363056 58.0019396, 22.0344895 58.0014445, 22.0334132 58.0011464, 22.031798 58.0007169, 22.0312669 58.0005554, 22.0308003 58.0003958, 22.0299982 58.0000671, 22.0293673 57.9997562, 22.0255445 57.9975239, 22.0235683 57.9963199, 22.019945 57.9941124, 22.0189449 57.993394, 22.0185402 57.9927809, 22.0183619 57.9919954, 22.0185665 57.9912965, 22.0193382 57.9896141, 22.0197497 57.9886068, 22.0203264 57.9873089, 22.0207424 57.986355, 22.0209716 57.9857848, 22.0210919 57.9854853, 22.0213131 57.9849392, 22.0215284 57.9844135, 22.0216545 57.9839407, 22.0216902 57.9836398, 22.0217102 57.9833145, 22.0215934 57.982903, 22.021419 57.9825155, 22.0211337 57.9819858, 22.0208339 57.9816209, 22.0205326 57.9813067, 22.0198611 57.9808164, 22.0189558 57.9802367, 22.0181816 57.9797606, 22.0169012 57.9789891, 22.0144007 57.9774724, 22.0126276 57.9764101, 22.0114743 57.975706, 22.0107859 57.9752858, 22.0071663 57.9731103, 22.0061964 57.9724639, 22.0052121 57.9717478, 22.0039716 57.970712, 22.0029867 57.9697428, 22.00269 57.9694162, 22.0019228 57.968535, 22.0013785 57.9677904, 22.0003182 57.9662021, 21.9992996 57.9646586, 21.9972166 57.9615807, 21.9971443 57.9614702, 21.9967701 57.9608983, 21.996616 57.9604841, 21.9964811 57.9599436, 21.9964489 57.9593717, 21.9965829 57.9584759, 21.9967887 57.9575496, 21.9971487 57.9556953, 21.9974206 57.9543359, 21.997672 57.9530652, 21.9976949 57.9529393, 21.997965 57.9516116, 21.9980774 57.9511991, 21.9982022 57.9509179, 21.9983111 57.9507133, 21.9986802 57.9501513, 21.9990458 57.9496884, 21.9995387 57.9492148, 22.0000886 57.9487813, 22.0002683 57.9486511, 22.0004491 57.9485276, 22.0008378 57.9482893, 22.0016256 57.9478062, 22.0039493 57.946387, 22.0067603 57.9446678, 22.0080223 57.9438992, 22.0081881 57.9437989, 22.0106623 57.9422877, 22.0117012 57.9416498, 22.0123896 57.941114, 22.0128118 57.9407148, 22.0133024 57.9401891, 22.0134488 57.9399937, 22.0140052 57.9391042, 22.0145747 57.9381741, 22.0149037 57.9376662, 22.0152858 57.9371623, 22.0164393 57.9358291, 22.0173204 57.9348554, 22.0181691 57.9339626, 22.0184151 57.9338105, 22.0188136 57.9336245, 22.0251493 57.9310279, 22.0348016 57.9271172, 22.0375506 57.926033, 22.0445412 57.9237122, 22.0468228 57.9229301, 22.0473732 57.9227291, 22.0476643 57.9225905, 22.0482686 57.9222757, 22.0491394 57.9217129, 22.0506239 57.9207264, 22.0512772 57.9202941, 22.051932 57.91989, 22.0524278 57.9196645, 22.052747 57.919569, 22.0530308 57.9195005, 22.0534041 57.9194237, 22.0540667 57.9193325, 22.0574948 57.9189141, 22.0596265 57.9186637, 22.0618148 57.9183929, 22.0636563 57.9181602, 22.0639902 57.918131, 22.0642581 57.9181382, 22.0644605 57.9181695, 22.0647002 57.9182452, 22.0649041 57.9183419, 22.0662254 57.9190668, 22.0667118 57.9193563, 22.067059 57.9195838, 22.0673697 57.9198141, 22.0676331 57.9200253, 22.0679073 57.9202593, 22.0681937 57.9205324, 22.0687993 57.9210981, 22.069128 57.9214281, 22.0704011 57.9228595, 22.0710745 57.9235712, 22.0717436 57.9242615, 22.0723043 57.9247631, 22.0728413 57.9251791, 22.0733455 57.9255487, 22.0736327 57.9257744, 22.0738081 57.9258917, 22.0740418 57.926021, 22.0743881 57.9261976, 22.074814 57.9263984, 22.0753661 57.9266451, 22.0757039 57.9267793, 22.0761404 57.9269525, 22.0769401 57.927235, 22.0789279 57.9278726, 22.0807069 57.9283837, 22.082883 57.928978, 22.0838908 57.9292754, 22.0847777 57.9295613, 22.0853585 57.929765, 22.0865895 57.9302597, 22.0874274 57.9306336, 22.0920971 57.9330818, 22.0952889 57.9347543, 22.097774 57.9359314, 22.1000961 57.9370645, 22.1030526 57.9387145, 22.1039535 57.9391836, 22.1049281 57.9396676, 22.1061235 57.9402157, 22.1068671 57.9405925, 22.107055 57.9407084, 22.1071949 57.9408593, 22.1076188 57.9415401, 22.1078304 57.941831, 22.1081511 57.9421122, 22.1086647 57.9424304, 22.1093062 57.9427187, 22.1114706 57.9434859, 22.1122651 57.9438023, 22.1152236 57.9453406, 22.1155635 57.9455581, 22.1158115 57.945766, 22.1160467 57.9460158, 22.1187927 57.9495541, 22.1191505 57.9500351, 22.1195952 57.9505917, 22.1198863 57.9508971, 22.12105 57.9520537, 22.121246 57.9523306, 22.1213243 57.9524814, 22.1213918 57.9528157, 22.1213298 57.9532003, 22.1212331 57.9537161, 22.1211679 57.954094, 22.1211802 57.9542294, 22.1212168 57.9543797, 22.1213226 57.954477, 22.1219175 57.9548877, 22.1220815 57.9550373, 22.122546 57.9558138, 22.1239156 57.957798, 22.1241603 57.9582011, 22.1248062 57.9591621, 22.1257003 57.9601034, 22.12679 57.9611765, 22.1273795 57.9620948, 22.1280326 57.9631733, 22.1283243 57.9638429, 22.128603 57.9645727, 22.128952 57.965223, 22.1319977 57.9684531, 22.1334987 57.9698068, 22.1346931 57.9711443, 22.1349226 57.9715106) │ tertiary │ │ way/1018220952 │ LINESTRING (22.1068474 57.9623483, 22.1065086 57.962407, 22.1036122 57.9631158, 22.1012661 57.9639724, 22.0999695 57.9646673, 22.0888238 57.970641, 22.0884304 57.9708519, 22.08696 57.9716403, 22.0843338 57.9730484, 22.0816274 57.9742212) │ tertiary │ │ way/1018220953 │ LINESTRING (22.0608019 57.978236, 22.0535175 57.9800692) │ tertiary │ │ way/1018220951 │ LINESTRING (22.0622446 57.9779054, 22.0608019 57.978236) │ tertiary │ │ way/4937123 │ LINESTRING (22.0792412 57.975065, 22.0777345 57.9755978, 22.0765658 57.9761355, 22.0755268 57.9765237, 22.0749313 57.9767099, 22.0742608 57.9768686, 22.0735309 57.97699, 22.0709656 57.9773805, 22.0701591 57.9774945, 22.0693971 57.9775859, 22.0690844 57.9776128, 22.0687346 57.9776384, 22.0684389 57.9776509, 22.0677736 57.977668, 22.063527 57.9777223, 22.0632252 57.9777654, 22.0622446 57.9779054) │ tertiary │ │ way/1018220950 │ LINESTRING (22.0816274 57.9742212, 22.0792412 57.975065) │ tertiary │ │ · │ · │ · │ │ · │ · │ · │ │ · │ · │ · │ │ way/323230843 │ LINESTRING (24.872365 58.9160758, 24.8723409 58.9159294, 24.8723225 58.9157322, 24.8722321 58.9154883, 24.8721541 58.9153422, 24.8720292 58.9151702, 24.8710787 58.9142743, 24.8705927 58.9138286) │ tertiary │ │ way/1029515887 │ LINESTRING (24.8795896 58.9140645, 24.8791961 58.9145876) │ secondary │ │ way/388120072 │ LINESTRING (24.8791961 58.9145876, 24.8776711 58.9167011, 24.8774931 58.9170523) │ secondary │ │ way/388120073 │ LINESTRING (24.8774931 58.9170523, 24.8772829 58.9174582, 24.8770701 58.9182914, 24.8770096 58.9187077) │ secondary │ │ way/1030050590 │ LINESTRING (24.88778 58.9212033, 24.884387 58.9204303) │ tertiary │ │ way/388120070 │ LINESTRING (24.884387 58.9204303, 24.8820392 58.9198834, 24.8788454 58.9191393, 24.8786284 58.9190816, 24.8775769 58.9188362, 24.8770096 58.9187077) │ tertiary │ │ way/114190347 │ LINESTRING (24.8770096 58.9187077, 24.8745972 58.9179816, 24.8742516 58.9178855, 24.8739823 58.917789, 24.8737387 58.9176709, 24.873556 58.9175306, 24.8733449 58.9173356, 24.8730897 58.9170999, 24.872861 58.9168803, 24.8727013 58.9167226, 24.8725584 58.9165597, 24.8724608 58.9163985, 24.8724171 58.9163184, 24.8723935 58.9162274) │ tertiary │ │ way/223725268 │ LINESTRING (24.8680628 58.9115615, 24.8665548 58.9108508, 24.8634911 58.9095778, 24.8619472 58.9090895, 24.8603555 58.9087311, 24.8503863 58.9075321, 24.8485433 58.9072293, 24.8443322 58.906155, 24.8385502 58.9045283, 24.8310105 58.9022042, 24.8273364 58.9010606, 24.8266458 58.9008653, 24.8253258 58.9004919, 24.8236862 58.9001704, 24.8226479 58.9000382, 24.8209699 58.8998435, 24.8203933 58.8997824, 24.8196076 58.8997271, 24.8189719 58.8997086, 24.8152714 58.8996881, 24.8147404 58.899696, 24.8142389 58.8997221, 24.8136008 58.8997738, 24.8118332 58.8999528, 24.8071226 58.9004752, 24.8046982 58.9007478, 24.8045702 58.9007621, 24.8035025 58.9008779, 24.802694 58.9009604, 24.8025958 58.9009691, 24.8022533 58.9009979, 24.8016116 58.9010516, 24.8008792 58.9010913, 24.8003034 58.9011216, 24.7995255 58.9011309, 24.7985838 58.9011263) │ tertiary │ │ way/114185197 │ LINESTRING (24.7469847 58.9307449, 24.7474653 58.9300432, 24.748274 58.9288624, 24.7489535 58.9278571, 24.7500727 58.9262013, 24.752303 58.9229436, 24.7528481 58.9222402, 24.7532389 58.9217997, 24.7541609 58.9208789, 24.7546798 58.9203853, 24.755661 58.9194365, 24.7562396 58.9188908, 24.7570178 58.9182513, 24.757723 58.9178062, 24.7581375 58.9175992, 24.7609162 58.9165575, 24.7618413 58.916228, 24.7637709 58.9155419, 24.7650072 58.9150793, 24.7660149 58.9146156, 24.7691234 58.9129893, 24.7730921 58.9109062, 24.7749344 58.9099392, 24.7776635 58.9085067, 24.7813803 58.9065564, 24.7816949 58.9063913, 24.7830344 58.9056086, 24.7834327 58.9053659, 24.7845559 58.9045443, 24.7854475 58.9037797, 24.7859457 58.9032063, 24.7860934 58.9030318, 24.7862645 58.9028109, 24.7870256 58.9017422, 24.7874306 58.9009123, 24.7874462 58.9008804) │ secondary │ │ way/1195027050 │ LINESTRING (24.7975018 58.9011026, 24.7917148 58.9009763, 24.7906482 58.9009532, 24.7874462 58.9008804) │ tertiary │ ├────────────────┴──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┴───────────┤ │ ? rows (>9999 rows, 20 shown) 3 columns │ └───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
Count loaded roads¶
features_relation.count("feature_id")
┌───────────────────┐ │ count(feature_id) │ │ int64 │ ├───────────────────┤ │ 25811 │ └───────────────────┘
length_in_meters = (
features_relation.project(
"ST_Length(ST_Transform(geometry, 'EPSG:4326', 'EPSG:3301')) AS road_length"
)
.sum("road_length")
.fetchone()[0]
)
length_in_km = length_in_meters / 1000
length_in_km
29495.52079963101
Plot the roads using GeoPandas¶
With fast loading of geoparquet files using geoarrow.pyarrow
library.
import geoarrow.pyarrow as ga
from geoarrow.pyarrow import io
from quackosm._constants import GEOMETRY_COLUMN
parquet_table = io.read_geoparquet_table(estonia_features_gpq)
ga.to_geopandas(parquet_table.column(GEOMETRY_COLUMN)).plot()
<Axes: >
Download all data for Liechtenstein¶
Without filtering, with tags in a compact form
liechtenstein_pbf_url = "https://download.geofabrik.de/europe/liechtenstein-latest.osm.pbf"
liechtenstein_pbf_file = "liechtenstein.osm.pbf"
urllib.request.urlretrieve(liechtenstein_pbf_url, liechtenstein_pbf_file)
# Here explode_tags is set to False explicitly,
# but it would set automatically when not filtering the data
reader = PbfFileReader(geometry_filter=None, tags_filter=None)
liechtenstein_features_gpq = reader.convert_pbf_to_parquet(
liechtenstein_pbf_file, explode_tags=False
)
liechtenstein_features_gpq
Finished operation in 0:00:06
PosixPath('files/liechtenstein_nofilter_noclip_compact_sorted.parquet')
features_relation = connection.read_parquet(str(liechtenstein_features_gpq))
features_relation
┌─────────────────┬──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┬───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐ │ feature_id │ tags │ geometry │ │ varchar │ map(varchar, varchar) │ geometry │ ├─────────────────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤ │ node/540308211 │ {power=tower} │ POINT (9.5372399 46.9862797) │ │ node/1338490716 │ {power=tower} │ POINT (9.5342839 46.9887559) │ │ node/540308206 │ {power=tower} │ POINT (9.5313353 46.9912103) │ │ node/540308180 │ {power=tower} │ POINT (9.5285455 46.9936492) │ │ node/540308170 │ {power=tower} │ POINT (9.5257615 46.9960867) │ │ node/540308159 │ {power=tower} │ POINT (9.5231821 46.998349) │ │ way/160527579 │ {highway=path, surface=gravel} │ LINESTRING (9.4763856 47.0521369, 9.4764306 47.0519574, 9.476491 47.0518671, 9.4766172 47.0517149, 9.476662 47.0516592, 9.4766745 47.0515936, 9.4767745 47.0514237, 9.4768773 47.0512946, 9.4769524 47.0511758, 9.4770544 47.0510716, 9.4770946 47.050993, 9.4772689 47.0507445, 9.4773317 47.0505664, 9.4774119 47.0503482, 9.4774255 47.0502526, 9.4774889 47.0501908, 9.4775274 47.0500558, 9.477582 47.0499795, 9.4776337 47.0498801, 9.4776686 47.0498161, 9.4778721 47.0497533) │ │ way/122990817 │ {admin_level=4, boundary=administrative} │ LINESTRING (9.4772452 47.049055, 9.4757865 47.0517524) │ │ node/1725816418 │ {barrier=bollard} │ POINT (9.4763856 47.0521369) │ │ way/1214145501 │ {'cycleway:both'=no, highway=unclassified, lane_markings=no, name=Rheindamm, smoothness=excellent, surface=asphalt, width=4} │ LINESTRING (9.476461 47.0524842, 9.4766379 47.0521002) │ │ · │ · │ · │ │ · │ · │ · │ │ · │ · │ · │ │ way/346556216 │ {highway=footway} │ LINESTRING (9.5285035 47.1137413, 9.528546 47.1137306) │ │ way/346556164 │ {'addr:city'=Triesen, 'addr:country'=LI, 'addr:housenumber'=37, 'addr:postcode'=9495, 'addr:street'=Matschilsstrasse, building=yes} │ POLYGON ((9.5285404 47.1136454, 9.5286312 47.1136284, 9.5286476 47.1136253, 9.5285855 47.1134718, 9.5284783 47.1134919, 9.5285404 47.1136454)) │ │ way/489240064 │ {natural=scrub} │ POLYGON ((9.528335 47.1127211, 9.5282503 47.1127135, 9.5283961 47.1134813, 9.5284775 47.1134002, 9.528335 47.1127211)) │ │ way/1236273577 │ {highway=footway, incline=up} │ LINESTRING (9.5285035 47.1137413, 9.5284697 47.1137424, 9.5283112 47.1136669, 9.5282892 47.1136682, 9.5282477 47.1136604, 9.5281252 47.1136076, 9.5280712 47.1135821, 9.5280522 47.1135774, 9.5280457 47.1135889, 9.5280607 47.1136128, 9.5281692 47.1137536, 9.5281712 47.1137655, 9.5281457 47.1137645, 9.5280832 47.1137387, 9.5280177 47.1137298, 9.5279417 47.113706, 9.5277752 47.113658, 9.5276942 47.1136444, 9.5276862 47.1136492, 9.5277282 47.1136903, 9.5277747 47.1137417, 9.5277742 47.1137547, 9.5277512 47.1137543, 9.5276242 47.1137063, 9.5276052 47.113708, 9.5276067 47.1137206, 9.5276392 47.1138234, 9.5276392 47.1138448, 9.5276312 47.1138727, 9.5275837 47.1138411, 9.5275557 47.113837, 9.5275547 47.1138663, 9.5275497 47.1139068, 9.5275442 47.1139323, 9.5275282 47.1139337, 9.5274787 47.1139044, 9.5274842 47.1138724, 9.5274662 47.113836, 9.5274582 47.1138183, 9.5274487 47.1138207, 9.5274222 47.1138809, 9.5273522 47.1139711, 9.5273442 47.1139997, 9.5273597 47.1140514, 9.5273337 47.1140936, 9.5273522 47.1141324, 9.5273752 47.1141691, 9.5273727 47.1142015, 9.5273577 47.1142086, 9.5273247 47.1141998, 9.5272931 47.114178, 9.5272341 47.1141079, 9.5272231 47.1141147, 9.5272161 47.1141372, 9.5272251 47.1141998, 9.5272351 47.1142518, 9.5272306 47.114259, 9.5272096 47.114243, 9.5271261 47.1141566, 9.5271006 47.1141504, 9.5270911 47.1141661, 9.5270981 47.1142433, 9.5271386 47.1143424, 9.5271306 47.1143488, 9.5271041 47.1143379, 9.5270196 47.1142743, 9.5269781 47.1141889, 9.5269601 47.1141742, 9.5269488 47.1141868) │ │ node/4796795683 │ {natural=tree} │ POINT (9.5276099 47.1141069) │ │ way/452685631 │ {landuse=grass} │ POLYGON ((9.5270805 47.1144362, 9.5276527 47.1142977, 9.5274471 47.1140471, 9.5272436 47.1137796, 9.5272656 47.114087, 9.5272441 47.1141527, 9.5270134 47.1142294, 9.5270805 47.1144362)) │ │ way/1057614958 │ {'addr:city'=Triesen, 'addr:country'=LI, 'addr:housenumber'=32, 'addr:postcode'=9495, 'addr:street'=Haldenweg, building=residential} │ POLYGON ((9.5270639 47.1138934, 9.5271741 47.114049, 9.5269871 47.1141103, 9.5269395 47.114042, 9.5269942 47.1140243, 9.526933 47.1139363, 9.5270639 47.1138934)) │ │ node/4796795694 │ {natural=tree} │ POINT (9.5274159 47.112136) │ │ node/3530176170 │ {natural=tree} │ POINT (9.5270531 47.1126442) │ │ node/3530176169 │ {natural=tree} │ POINT (9.5269761 47.1126164) │ ├─────────────────┴──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┴───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤ │ ? rows (>9999 rows, 20 shown) 3 columns │ └────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
Return data as GeoDataFrame¶
PbfFileReader
can also return the data in the GeoDataFrame form.
Here the caching strategy will be utilized - file won't be transformed again.
features_gdf = reader.convert_pbf_to_geodataframe(liechtenstein_pbf_file)
features_gdf
tags | geometry | |
---|---|---|
feature_id | ||
node/540308211 | {'power': 'tower'} | POINT (9.53724 46.98628) |
node/1338490716 | {'power': 'tower'} | POINT (9.53428 46.98876) |
node/540308206 | {'power': 'tower'} | POINT (9.53134 46.99121) |
node/540308180 | {'power': 'tower'} | POINT (9.52855 46.99365) |
node/540308170 | {'power': 'tower'} | POINT (9.52576 46.99609) |
... | ... | ... |
way/439890023 | {'natural': 'cliff'} | LINESTRING (9.60433 47.06468, 9.60382 47.06464... |
way/1195535494 | {'natural': 'grassland'} | POLYGON ((9.60181 47.06237, 9.60136 47.06238, ... |
node/540308216 | {'line_attachment': 'suspension', 'power': 'to... | POINT (9.54003 46.98396) |
node/1110282277 | {'power': 'tower'} | POINT (9.5405 46.98211) |
node/2186283697 | {'power': 'tower'} | POINT (9.54143 46.97844) |
54650 rows × 2 columns
Plot the forests using GeoPandas¶
Filter all polygons and features with landuse
=forest
.
features_gdf[
features_gdf.geom_type.isin(("Polygon", "MultiPolygon"))
& features_gdf.tags.apply(lambda x: "landuse" in x and x["landuse"] == "forest")
].plot(color="green")
<Axes: >