Heatmap over GeoJSON
Aggregate point density into a regular grid with ak.Heatmap and draw it as a translucent raster over neighborhood polygons.
Python Script
python
"""Heatmap — noise complaints on a 30 x 30 grid over the neighborhoods (gallery: heatmap-vis-geojson)."""
from __future__ import annotations
from pathlib import Path
import pyautark as ak
DATA_DIR = Path(__file__).resolve().parents[1] / "data"
neighborhoods = ak.GeoJSON("neighborhoods", url=(DATA_DIR / "mnt_neighs.geojson").as_uri())
noise = ak.CSV(
"noise",
url=(DATA_DIR / "noise.csv").as_uri(),
geometry=ak.latlng("Latitude", "Longitude"),
)
spec = ak.Spec(
metadata=ak.Metadata(title="Heatmap — Noise Complaints"),
data=[neighborhoods, noise],
transforms=[
ak.Heatmap(
noise,
output="heatmap",
near=ak.Near(1000),
grid=ak.HeatmapGrid(rows=30, columns=30),
group_by=[ak.count("Unique Key")],
)
],
views=[
ak.Map(
layers=[
ak.Layer(neighborhoods, id="neighborhoods").style(color="#f0f0f0"),
ak.Layer("heatmap", id="noise density")
.encode(color=ak.field("count.noise", ak.Scale(scheme="inferno")))
.style(opacity=0.6),
]
)
],
)
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.