Skip to content

Simple GeoJSON Map ​

The smallest Python map spec: load neighborhood polygons from GeoJSON, style fill and stroke, and run with ak.cli(spec).

Python Script ​

python
"""Simple GeoJSON map — Style B (CLI-driven).

Demonstrates `ak.cli(spec)`, which dispatches `--output` / `--html` /
`--validate` / `--json` / default `spec.window()`.
"""
from __future__ import annotations

import json
from pathlib import Path

import pyautark as ak

DATA_DIR = Path(__file__).resolve().parents[1] / "data"

with (DATA_DIR / "neighborhoods.geojson").open(encoding="utf-8") as f:
    neighborhoods_data = json.load(f)

neighborhoods = ak.GeoJSON(
    "neighborhoods",
    values=neighborhoods_data,
    layer_type="polygons",
    coordinate_format="EPSG:4326",
)

spec = ak.Spec(
    metadata=ak.Metadata(
        title="Simple GeoJSON Map",
        description="Neighborhood polygons with custom styling.",
    ),
    data=[neighborhoods],
    views=[
        ak.Map(
            camera=ak.Camera(zoom=13),
            layers=[
                ak.Layer(neighborhoods, id="neighborhoods_layer").style(
                    color="#3498db",
                    opacity=0.7,
                    strokeColor="#2c3e50",
                )
            ],
        )
    ],
)

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.

Released under the MIT License.