Skip to content

OSM: Local PBF Extract ​

Read OpenStreetMap layers from a local .osm.pbf file with source="pbf" and pbf_file_url, without querying Overpass.

Python Script ​

python
from __future__ import annotations

from pathlib import Path

import pyautark as ak

pbf_url = (Path(__file__).resolve().parents[1] / "data" / "lower_mnt.osm.pbf").resolve().as_uri()

osm = ak.OSM(
    "osm",
    source="pbf",
    pbf_file_url=pbf_url,
    geocode_area="New York",
    area="Financial District",
    layers=["surface", "parks", "water", "roads", "buildings"],
)

spec = ak.Spec(
    data=[osm],
    views=[
        ak.Map(
            layers=[
                ak.Layer("osm_surface", id="surface_layer"),
                ak.Layer("osm_water", id="water_layer"),
                ak.Layer("osm_parks", id="parks_layer"),
                ak.Layer("osm_roads", id="roads_layer"),
                ak.Layer("osm_buildings", id="buildings_layer"),
            ]
        )
    ],
)

if __name__ == "__main__":
    spec.window(height="760px")

Run in Jupyter or standalone HTML

Replace spec.window(...) with spec.widget() inside a Jupyter notebook (requires pip install "pyautark[widget]") or spec.save_html("out.html") to export a standalone web page.

This example comes from the pyautark repository.

Released under the MIT License.