Public
Edited
Oct 14, 2024
10 stars
Hello simple-data-analysis (and geospatial data)
Hello simple-data-analysis
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

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more