Two Workspaces
Load two OpenStreetMap areas into separate workspaces so neither clips the other, and draw them side by side with ak.Layout(type="horizontal").
Python Script
python
"""Two workspaces — two areas of OpenStreetMap, each in its own workspace and drawn in its own map (gallery: osm-layers-api-workspaces).
A workspace is an isolated set of tables with its own extent. In one workspace the first source sets the extent and the
second area would be cut to it, so each area gets a workspace of its own; both hold a table called `osm_roads`.
"""
from __future__ import annotations
from pathlib import Path
import pyautark as ak
DATA_DIR = Path(__file__).resolve().parents[1] / "data"
PBF = (DATA_DIR / "lower_mnt.osm.pbf").as_uri()
LAYERS = ["surface", "parks", "water", "roads", "buildings"]
battery_park = ak.OSM("osm", bbox=(-74.0200, 40.7000, -74.0100, 40.7100), layers=LAYERS, source="pbf", pbf_file_url=PBF,
workspace="battery_park_city")
financial_district = ak.OSM("osm", bbox=(-74.0100, 40.7000, -73.9990, 40.7160), layers=LAYERS, source="pbf", pbf_file_url=PBF,
workspace="financial_district")
def area_map(osm: ak.OSM) -> ak.Map:
return ak.Map(
name=osm.workspace,
workspace=osm.workspace,
camera=ak.Camera(pitch=40),
layers=[ak.Layer(osm.layer_source(layer), id=layer) for layer in osm.layers],
)
spec = ak.Spec(
metadata=ak.Metadata(title="OSM Layers in Two Workspaces"),
data=[battery_park, financial_district],
views=[area_map(battery_park), area_map(financial_district)],
layout=ak.Layout(type="horizontal"),
)
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.