Public
Edited
Jul 4, 2023
1 fork
5 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
makeMap = (year, { w = width / 4, h = width / 4, grouped = false } = {}) => {
const maxYear = year === 2016 ? 2021 : year + 4;
const yearFormat = d3.format("");
return Plot.plot({
width: w,
insetTop: 30,
height: h,
marks: [
// Boundaries
Plot.geo(boundariesProj, {
stroke: "#f3f3f3",
strokeWidth: 0.5,
strokeOpacity: 0.3,
fill: "#f3f3f3",
fillOpacity: 0.1
}),
// Wildfire shapes
Plot.geo(fires, {
filter: (d) =>
year === "all"
? true
: grouped
? d.id > year && d.id <= maxYear
: +d.id === year,
strokeWidth: 1,
stroke: (d) => +d.id,
fill: (d) => +d.id
}),
// label
Plot.text([year], {
frameAnchor: "top",
dy: 10,
fontSize: 14,
fontFamily: "sans-serif",
text: (d) =>
year === "all"
? "Wildfies, 1986 - 2021"
: grouped
? `${yearFormat(year)} - ${yearFormat(maxYear)}`
: yearFormat(year),
fill: "white"
}),
// outline
Plot.frame({ stroke: "#f3f3f3" })
],
x: { axis: null },
y: { axis: null },
color: {
scheme: "Reds"
},
style: {
backgroundColor: "black"
}
});
}
Insert cell
boundaries = FileAttachment("boundaries@2.json").json()
Insert cell
fires = FileAttachment("simple@3.json").json()
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
// gdalsrsinfo lpr_000b21a_e.prj
boundaryProj = `+proj=lcc +lat_0=63.390675 +lon_0=-91.8666666666667 +lat_1=49 +lat_2=77 +x_0=6200000 +y_0=3000000 +datum=NAD83 +units=m +no_defs`
Insert cell
// gdalsrsinfo nbac_2020_r9_20210810.prj
fireProj = `+proj=lcc +lat_0=49 +lon_0=-95 +lat_1=49 +lat_2=77 +x_0=0 +y_0=0 +datum=NAD83 +units=m +no_defs`
Insert cell
proj4 = require("proj4@2.8")
Insert cell
// A function to recursively project coordinates in a geoJSON object
function recurseProject(coordsArr) {
if (Array.isArray(coordsArr[0])) return coordsArr.map(recurseProject);
return proj4(boundaryProj, fireProj, coordsArr); // project the coordinates from one projection to the other
}
Insert cell
// Do the projection of all coordinates
boundariesProj = {
return {
type: "FeatureCollection",
features: boundaries.features.map((feature) => {
return {
...feature,
geometry: {
type: feature.geometry.type,
coordinates: recurseProject(feature.geometry.coordinates)
}
};
})
};
}
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more