Published
Edited
Sep 2, 2022
2 forks
5 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
points = {
//Modified from https://observablehq.com/@toja/gridded-population-of-the-world
const features = [];
const { nrows, ncols, cellsize, xllcorner, yllcorner, NODATA_value } =
parsed.header;
for (let y = 0; y < nrows; y++) {
for (let x = 0; x < ncols; x++) {
/*
Raster starts in upper left hand corner and moves east then restarts one row down on the left. This is confusing because the reference coordinates are provided for the lower left hand of the raster.
*/
features.push({
type: "Feature",
geometry: {
type: "Point",
coordinates: [
x * cellsize - (-xllcorner - cellsize / 2),
-y * cellsize + (-yllcorner - cellsize / 2)
]
},
properties: {
count: parsed.data[y][x]
}
});
}
}
return {
type: "FeatureCollection",
features: features.filter(
(d) =>
(d.properties.count !== parsed.header.NODATA_value) &
(d.properties.count > 0)
)
};
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
import { parse } from "@toja/gridded-population-of-the-world"
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