Skip to content

Read features from OSM PBF file #1292

Description

@gboeing

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions