Skip to main content
Pukar Bhandari
  • About
  • Projects
  • Research
  • Socials
    • Github
    • LinkedIn
    • Mastodon
    • Bluesky
    • E-mail

New: Demographic Profiles, a zero-backend, map-first dashboard of Census and economic indicators for Utah.

Salt Lake County Places Dashboard
maplibregl = require("maplibre-gl@4.7.1")
db = DuckDBClient.of({
  places: FileAttachment("../posts/overture-data-download/output/slco_places_r.parquet")
})
places = db.sql`
  SELECT names.primary AS name,
         categories.main AS category,
         bbox.xmin AS lon,
         bbox.ymin AS lat,
         confidence,
         addresses[1].locality AS city
  FROM places
  WHERE names.primary IS NOT NULL AND categories.main IS NOT NULL
`
label = c => c.replaceAll("_", " ").replace(/^./, s => s.toUpperCase())
categoryCounts = d3.rollups(places, v => v.length, d => d.category).sort((a, b) => b[1] - a[1])
topCategories = categoryCounts.slice(0, 10).map(d => d[0])
palette = ["#007EA7", "#D96E34", "#6A4C93", "#2A9D8F", "#E9B44C", "#C44569", "#4A6FA5", "#8A9A5B", "#A23E02", "#6C757D"]
color = d3.scaleOrdinal(topCategories, palette)

Places selected

html`${rows.length.toLocaleString()}`

Share of all places

html`${(rows.length / places.length * 100).toFixed(1)}%`

Cities with a match

knownCities.length

Busiest city

html`${knownCities.length ? knownCities[0][0] : "none"}`

Where the selected places are
mapEl = html`<div class="map-fill"></div>`
map = {
  const m = new maplibregl.Map({
    container: mapEl,
    style: "https://tiles.openfreemap.org/styles/positron",
    bounds: [[-112.26, 40.41], [-111.55, 40.93]],
    fitBoundsOptions: {padding: 20},
    attributionControl: false
  });
  m.addControl(new maplibregl.AttributionControl({compact: true, customAttribution: "Places: Overture Maps"}));
  m.addControl(new maplibregl.NavigationControl({showCompass: false}), "top-right");
  new ResizeObserver(() => m.resize()).observe(mapEl);
  await new Promise(resolve => m.on("load", resolve));
  m.addSource("places", {type: "geojson", data: {type: "FeatureCollection", features: []}});
  m.addLayer({
    id: "places",
    type: "circle",
    source: "places",
    paint: {
      "circle-color": ["get", "color"],
      "circle-radius": ["interpolate", ["linear"], ["zoom"], 8, 1.6, 12, 3.2, 16, 6],
      "circle-opacity": 0.75,
      "circle-stroke-color": "#ffffff",
      "circle-stroke-width": 0.4
    }
  });
  const popup = new maplibregl.Popup({closeButton: false, closeOnClick: false, offset: 8});
  m.on("mousemove", "places", e => {
    m.getCanvas().style.cursor = "pointer";
    const p = e.features[0].properties;
    popup.setLngLat(e.features[0].geometry.coordinates)
      .setHTML(`<strong>${p.name}</strong><br>${p.category}<br>Confidence ${(+p.confidence).toFixed(2)}`)
      .addTo(m);
  });
  m.on("mouseleave", "places", () => { m.getCanvas().style.cursor = ""; popup.remove(); });
  return m;
}
map.getSource("places").setData({
  type: "FeatureCollection",
  features: rows.map(d => ({
    type: "Feature",
    geometry: {type: "Point", coordinates: [d.lon, d.lat]},
    properties: {name: d.name, category: label(d.category), confidence: d.confidence, color: color(d.category)}
  }))
})
  • By category
  • By city
Plot.plot({
  width: 420,
  height: 440,
  marginLeft: 178,
  marginRight: 44,
  x: {label: null, grid: true, ticks: 4},
  y: {label: null},
  style: {backgroundColor: "transparent", fontSize: "11px"},
  marks: [
    Plot.barX(catRows, {x: d => d[1], y: d => label(d[0]), fill: d => color(d[0]), sort: {y: "-x"}, tip: true}),
    Plot.text(catRows, {x: d => d[1], y: d => label(d[0]), text: d => d[1].toLocaleString(), dx: 4, textAnchor: "start"}),
    Plot.ruleX([0])
  ]
})
Plot.plot({
  width: 420,
  height: 440,
  marginLeft: 110,
  marginRight: 44,
  x: {label: null, grid: true, ticks: 4},
  y: {label: null},
  style: {backgroundColor: "transparent", fontSize: "11px"},
  marks: [
    Plot.barX(knownCities.slice(0, 12), {x: d => d[1], y: d => d[0], fill: "#007EA7", sort: {y: "-x"}, tip: true}),
    Plot.text(knownCities.slice(0, 12), {x: d => d[1], y: d => d[0], text: d => d[1].toLocaleString(), dx: 4, textAnchor: "start"}),
    Plot.ruleX([0])
  ]
})
viewof chosen = Inputs.checkbox(topCategories, {
  label: "Categories",
  value: topCategories.slice(0, 5),
  format: c => html`<span class="swatch" style="background:${color(c)}"></span>${label(c)}`
})
viewof minConfidence = Inputs.range([0, 1], {label: "Minimum confidence", step: 0.05, value: 0.5})

Overture Maps places for Salt Lake County, shown for the ten most common categories.

Read the post →

rows = places.filter(d => d.confidence >= minConfidence && chosen.includes(d.category))
cityCounts = d3.rollups(rows, v => v.length, d => d.city || "Unknown").sort((a, b) => b[1] - a[1])
catRows = d3.rollups(rows, v => v.length, d => d.category).sort((a, b) => b[1] - a[1])
knownCities = cityCounts.filter(d => d[0] !== "Unknown")

© 2025–2026 Pukar Bhandari ∙ Made with , Quarto, and

           

  • Edit this page
  • Report an issue
  • Contact

  • License