Thematic mapping: where should investment go first?¶

A choropleth is most useful when it answers a decision question. Here we map a fictional accessibility index for nine districts, then overlay candidate improvement projects.

Everything is generated locally with Python's standard library: no pandas, GeoPandas, API key, or network dataset is needed.

In [1]:
from maplibreum import Choropleth, LayerControl, Map

def district_feature(name, west, south, size=0.018):
    east, north = west + size, south + size
    return {
        "type": "Feature",
        "properties": {"district": name},
        "geometry": {
            "type": "Polygon",
            "coordinates": [[[west, south], [east, south], [east, north], [west, north], [west, south]]],
        },
    }

district_names = [
    "Northwest", "North", "Northeast",
    "West", "Centre", "East",
    "Southwest", "South", "Southeast",
]
districts = {"type": "FeatureCollection", "features": []}
for row in range(3):
    for column in range(3):
        index = row * 3 + column
        districts["features"].append(
            district_feature(
                district_names[index],
                west=-49.315 + column * 0.018,
                south=-25.455 + (2 - row) * 0.018,
            )
        )

accessibility_index = {
    "Northwest": 42, "North": 68, "Northeast": 55,
    "West": 37, "Centre": 91, "East": 73,
    "Southwest": 29, "South": 48, "Southeast": 62,
}

print(f"{len(districts['features'])} districts; index range {min(accessibility_index.values())}–{max(accessibility_index.values())}")
9 districts; index range 29–91

Bind values to geography¶

key_on tells the choropleth how a feature matches the Python dictionary. Quantile classification distributes the districts across the palette, while the legend is generated automatically.

In [2]:
priority_map = Map(
    center=[-49.288, -25.428],
    zoom=12,
    title="Illustrative district accessibility index",
    height="580px",
)

Choropleth(
    geojson=districts,
    data=accessibility_index,
    key_on="properties.district",
    colors=["#8c1d40", "#d1495b", "#edae49", "#90be6d", "#277da1"],
    color_scale="quantile",
    legend_title="Accessibility index",
).add_to(priority_map)

projects = {
    "type": "FeatureCollection",
    "features": [
        {"type": "Feature", "geometry": {"type": "Point", "coordinates": [-49.306, -25.446]}, "properties": {"project": "Crossing retrofit", "budget": "R$ 180k", "priority": "High"}},
        {"type": "Feature", "geometry": {"type": "Point", "coordinates": [-49.288, -25.428]}, "properties": {"project": "Tactile paving corridor", "budget": "R$ 320k", "priority": "Medium"}},
        {"type": "Feature", "geometry": {"type": "Point", "coordinates": [-49.270, -25.446]}, "properties": {"project": "Kerb ramp programme", "budget": "R$ 240k", "priority": "High"}},
    ],
}
priority_map.add_source("projects", {"type": "geojson", "data": projects})
priority_map.add_circle_layer(
    "candidate-projects",
    source="projects",
    paint={
        "circle-color": ["match", ["get", "priority"], "High", "#111827", "#ffffff"],
        "circle-radius": 9,
        "circle-stroke-color": "#ffffff",
        "circle-stroke-width": 2,
    },
)
priority_map.add_feature_popup(
    "candidate-projects",
    fields=["project", "priority", "budget"],
    aliases=["Project", "Priority", "Indicative budget"],
    title="Candidate investment",
)
LayerControl().add_to(priority_map)
priority_map.add_control("navigation", options={"showZoom": True})
priority_map.fit_bounds([[-49.317, -25.457], [-49.259, -25.399]], padding=35)

priority_map
Out[2]:

Read the map critically¶

The palette communicates performance, but the decision still depends on population, cost, network connectivity, and equity. A compelling map should clarify a decision—not pretend the decision is only cartographic.

Next: move beyond embedded GeoJSON to terrain and a cloud-native PMTiles archive.