OSMnx downloads OSM features from Overpass or reads them from a local OSM XML file. Both of these are relatively slow to process. Reading data from a PBF file can be much faster. Pyrosm previously offered this functionality, but now appears to be dead. QuackOSM also offers this functionality.
As a test, I quickly threw together a demonstration of how to use QuackOSM to load features from a PBF file into the same GeoDataFrame format that all of OSMnx's features module functions provide:
import geopandas as gpd
import quackosm as qosm
import pandas as pd
def features_from_pbf(filepath):
gdf = qosm.convert_pbf_to_geodataframe(filepath)
idx = ((element, osmid) for element, osmid in gdf.index.str.split("/"))
gdf.index = pd.MultiIndex.from_tuples(idx, names=["element", "id"])
tags = pd.DataFrame(gdf["tags"].tolist(), index=gdf.index)
return gpd.GeoDataFrame(tags, geometry=gdf.geometry, crs=gdf.crs)
url = "https://download.geofabrik.de/north-america/us/delaware-latest.osm.pbf"
gdf = features_from_pbf(url)
This issue is just to share a demonstration here where others can find it. It isn't to propose that we add a features_from_pbf to the OSMnx features module, but rather provides a proof of concept and some sample code if anyone else is looking for this functionality. Conversely, loading a graph model from a PBF file seems much more complicated and would probably require reproducing a large portion of Pyrosm's codebase.
OSMnx downloads OSM features from Overpass or reads them from a local OSM XML file. Both of these are relatively slow to process. Reading data from a PBF file can be much faster. Pyrosm previously offered this functionality, but now appears to be dead. QuackOSM also offers this functionality.
As a test, I quickly threw together a demonstration of how to use QuackOSM to load features from a PBF file into the same GeoDataFrame format that all of OSMnx's
featuresmodule functions provide:This issue is just to share a demonstration here where others can find it. It isn't to propose that we add a
features_from_pbfto the OSMnxfeaturesmodule, but rather provides a proof of concept and some sample code if anyone else is looking for this functionality. Conversely, loading a graph model from a PBF file seems much more complicated and would probably require reproducing a large portion of Pyrosm's codebase.