OSMnx Workflow
Fetch street networks and buildings with OSMnx in Python, pass the GeoDataFrames into pyautark, and display them in an interactive WebGPU map.
Python Script
python
"""OSMnx → Autark — download a street network, then render edges and an attribute table.
Style B (CLI-driven) because the OSMnx round-trip is heavy and you may want to
regenerate JSON in CI without opening a window. Requires the optional ``osmnx``
and ``geopandas`` dependencies.
Hardcoded to a tiny ~200 m walk around lower Manhattan. Edit the constants at
the top of the script for a different area.
"""
from __future__ import annotations
from pathlib import Path
import pyautark as ak
LATITUDE = 40.7128
LONGITUDE = -74.0060
DISTANCE_M = 200
NETWORK_TYPE = "walk"
def _load_osmnx_network() -> tuple[object, object]:
try:
import osmnx as ox
except ModuleNotFoundError as exc:
raise RuntimeError(
"This example requires osmnx and geopandas."
) from exc
ox.settings.use_cache = True
ox.settings.cache_folder = "/tmp/autark-osmnx-cache"
graph = ox.graph_from_point(
(LATITUDE, LONGITUDE),
dist=DISTANCE_M,
network_type=NETWORK_TYPE,
simplify=True,
)
graph = ox.add_edge_speeds(graph)
graph = ox.add_edge_travel_times(graph)
nodes, edges = ox.graph_to_gdfs(graph)
return nodes.reset_index(), edges.reset_index()
nodes_gdf, edges_gdf = _load_osmnx_network()
edges = ak.GeoJSON.from_geopandas("street_edges", edges_gdf, layer_type="polylines")
nodes = ak.GeoJSON.from_geopandas("street_nodes", nodes_gdf, layer_type="points")
spec = ak.Spec(
metadata=ak.Metadata(
title="OSMnx Walk Network",
description="OSMnx downloads a small walk network; Autark renders it as a map and a table.",
),
data=[edges, nodes],
views=[
ak.Map(
camera=ak.Camera(zoom=13),
layers=[
ak.Layer("street_edges", id="edges").style(
color="#3949ab", width=6, opacity=0.9
),
ak.Layer("street_nodes", id="nodes").style(
color="#f57c00", opacity=0.85
),
],
),
ak.Table(
"street_edges",
name="edge_table",
columns=["u", "v", "length", "speed_kph", "travel_time", "highway"],
sort={"column": "travel_time", "direction": "desc"},
),
],
layout=ak.Layout(type="vertical"),
)
if __name__ == "__main__":
ak.cli(spec, description=__doc__)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.