Published
Edited
Sep 16, 2019
10 stars
Also listed in…
Geo
Algorithms
Insert cell
Insert cell
kriging = require("@sakitam-gis/kriging@0.1")
Insert cell
Insert cell
data = {
const n = 300,
t = new Float32Array(n),
x = new Float32Array(n),
y = new Float32Array(n);

for (let i = 0; i < n; i++) {
x[i] = -180 + Math.random() * 360;
y[i] = 90 * (Math.random() - Math.random());
t[i] =
(d3.geoContains(land, [x[i], y[i]]) ? 1 : -1) * (0.05 + Math.random());
}

return { t, x, y };
}
Insert cell
Insert cell
variogram = kriging.train(data.t, data.x, data.y, "exponential", 0, 10)
Insert cell
Insert cell
map = {
const context = DOM.context2d(width, height),
path = d3.geoPath(projection).context(context);

context.save();
context.beginPath();
path({ type: "Sphere" });
context.clip();

for (let x = 0; x < width; x += 5) {
for (let y = 0; y < height; y += 5) {
const p = projection.invert([x - 0.5, y - 0.5]);
context.fillStyle = color(kriging.predict(...p, variogram));
context.fillRect(x, y, 10, 10);
}
}

context.restore();
context.beginPath();
path(land);
context.stroke();

context.beginPath();
path.pointRadius(1.5);
context.fillStyle = "white";
path({ type: "MultiPoint", coordinates: d3.zip(data.x, data.y) });
context.fill();

context.beginPath();
path({ type: "Sphere" });
context.stroke();

return context.canvas;
}
Insert cell
projection = d3.geoEqualEarth()
Insert cell
height = 500
Insert cell
color = d3.scaleSequential(d3.interpolateRdBu).domain([1, -1])
Insert cell
d3 = require("d3@5")
Insert cell
land = d3.json(
"https://unpkg.com/visionscarto-world-atlas@0.0.6/world/110m_land.geojson"
)
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