Published
Edited
Apr 23, 2022
1 fork
1 star
Insert cell
Insert cell
mapfill(d => color(interpolate(d, sources)), d3.geoAirocean(), {
N: 10000,
graticule: land,
interval: 1000,
})
Insert cell
Insert cell
Insert cell
nn = 100 // in this case nn is high; the limiting factor being R
Insert cell
R = 0.1 // geoDistances are in radians
Insert cell
color = d3.scaleSequential(d3.interpolatePRGn).domain([-1, 1])
Insert cell
function interpolate(p, sources) {
let value = 0,
weight = 0;
tree.nearest(p, nn, R).forEach(([q, dist]) => {
const k = kernel(dist);
value += k * q[2];
weight += k;
});
return value / weight;
}
Insert cell
function kernel(dist) {
return Math.pow(dist, -P);
}
Insert cell
sources = Array.from({ length: 5000 }, () => {
const lon = 360 * (Math.random() - 0.5),
lat = 90 * (Math.random() - Math.random()),
t = (d3.geoContains(land, [lon, lat]) ? 1 : -1) * (0.3 + Math.random());
return [lon, lat, t];
})
Insert cell
import {mapfill} from "@fil/mapfill"
Insert cell
d3 = require("d3@7", "d3-geo-polygon@1")
Insert cell
kd = require("kd-tree-javascript@1")
Insert cell
distance = d3.geoDistance
Insert cell
tree = new kd.kdTree(sources, distance, [0, 1])
Insert cell
land = d3.json(
"https://unpkg.com/visionscarto-world-atlas@0.0.6/world/110m_land.geojson"
)
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