Public
Edited
Oct 14
9 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
sda = import("https://esm.sh/jsr/@nshiab/simple-data-analysis@3.13.9/web")
Insert cell
Insert cell
sdb = new sda.SimpleWebDB().start()
Insert cell
Insert cell
Insert cell
provinces = {
// We create a new table.
const provinces = sdb.newTable("provinces");

// We fetch the provinces' boundaries.
await provinces.fetchGeoData(
"https://raw.githubusercontent.com/nshiab/simple-data-analysis/main/test/geodata/files/CanadianProvincesAndTerritories.json"
);

// We return the table.
return provinces;
}
Insert cell
Insert cell
provincesGeoData = await provinces.getGeoData()
Insert cell
Insert cell
Insert cell
fires = {
// We create a new table.
const fires = sdb.newTable("fires");

// We fetch the wildfires data.
await fires.fetchData(
"https://raw.githubusercontent.com/nshiab/simple-data-analysis/main/test/geodata/files/firesCanada2023.csv"
);

// We create point geometries from the lat and lon columns
// and we store the points in the new column geom.
await fires.points("lat", "lon", "geom");

return fires;
}
Insert cell
Insert cell
firesGeoData = await fires.getGeoData()
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
firesInsideProvinces = {
// We match fires inside provinces
// and we output the results in a new table.
// By default, joinGeo will automatically look
// for columns storing geometries in the tables,
// do a left join, and put the results
// in the left table.
const firesInsideProvinces = await fires.joinGeo(provinces, "inside", {
outputTable: "firesInsideProvinces"
});

// We remove fires that could not be matched
await firesInsideProvinces.removeMissing();

// We summarize to count the number of fires
// and sum up the area burnt in each province.
await firesInsideProvinces.summarize({
values: "hectares",
categories: "nameEnglish",
summaries: ["count", "sum"],
decimals: 0
});

// We rename columns.
await firesInsideProvinces.renameColumns({
count: "nbFires",
sum: "burntArea"
});

// We want the province with
// the greatest burnt area first.
await firesInsideProvinces.sort({ burntArea: "desc" });

return firesInsideProvinces;
}
Insert cell
Insert cell
Inputs.table(await firesInsideProvinces.getData())
Insert cell
Insert cell
Insert cell
Insert cell
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