Public
Edited
Feb 16, 2023
1 star
Contour Labels (canvas)Coordinated mapsgeoformatSmall circle testKruskal MazeAll the geoshapesReprojecting Vector TilesCloud ContoursHello h3-jsClipping AlbersTranslucent EarthThe truth about the Mercator projectionUsing d3-inertia with observableMercator projection of a Mercator globeD3 Vector Tiles (WIP)Finding intersections between the graticule and the clip sphere of the stereographic projection, method 2Plate tectonicsAnother hex mapEquateur & tropiquesTissot's indicatrixDistance to shoreMultiPolygon clippingSouth Africa’s medial axisSpherical intersectionVolcano Semis (points circulaires)Pencil Airocean45° mapNetCDFBlue noise sphereRubber DymaxionSpherical quasi-random (R2) distributionAutomated label placement (countries)Automated label placement (France)Automated label placement (cities)d3.geoIntersectArcDelaunay.findTriangled3-geo-voronoi and gridded dataElevation vtk.jsMapfillKrigingSpherical HeatmapReproject elevation tiles — detailReproject elevation tiles — worldFisheye Conformal MapSpherical KDE InterpolationSpherical kernel interpolation with nearest neighborsShepard’s methodModified Shepard’s methodSpherical contoursGeo Voronoi interpolationBlurry contoursHow much warmer? (BBC)H3 hexagons & geoContoursHillshading & supersamplingH3 odditiesManhattan VoronoiManhattan Voronoi IIGeoJSON feature editorColorized Manhattan Spanning Treelegra mapslegra country mapsThe complex logarithm projectionCountries small multipleThe 2D approximate Newton-Raphson methodOceanAttitudeCount visible objectsThe Gray-Fuller spatial gridGray-Fuller grid metricsGray-Fuller grid odditiesSpherical smallest-circle problemBounding CirclesCountries Enclosing CirclesFullscreen Seamless Zoomable Map TilesMap Pan & ZoomSpherical EllipsesSynchronized projectionsThe closest countryTriangular tiling of icosahedronHello, polygon-clippingCorées / KoreasHello, procedural-glHello, placekeyZoom World ChoroplethClipping spherical polygonsSpherical phyllotaxisFour-color world map with ClingoHello, jsgeoda!The Sun’s analemmaWorld of squaresWorld of squares (spherical)A map of AfricaTagged borders
Clipped geoVoronoi
Blue noise sphere IISpherical Perlin NoiseSpherical Delaunay triangulationDynamic simplificationRewindPlot: Voronoi labelsAoC 12: shortest path under constraintsHello, pixi.jsFlight PathsRay out of a convex hullDistance to a segment
Also listed in…
d3-geo-voronoi
Insert cell
Insert cell
Insert cell
Insert cell
bbox = [-60, -10, 40, 60]
Insert cell
points = ({
type: "FeatureCollection",
features: Array.from({ length: 100 }, () => [
bbox[0] + (bbox[2] - bbox[0]) * Math.random(),
bbox[1] + (bbox[3] - bbox[1]) * Math.random()
]).map((d) => ({
type: "Feature",
geometry: { type: "Point", coordinates: d }
}))
})
Insert cell
cells = clippedVoronoi(points, padding)
Insert cell
function clippedVoronoi(points, padding = 0) {
const coords = points.features.map(d3.geoCentroid);
const X = d3.extent(coords, (d) => d[0]);
const Y = d3.extent(coords, (d) => d[1]);

// the projection sends the shapes to a rectangle which is a bit larger
// than the data’s bounding-box.
const projection = d3
.geoEquirectangular()
.fitExtent(
[
[X[0], Y[0]],
[X[1], Y[1]]
],
points
)
.clipExtent([
[X[0] - padding, Y[0] - padding],
[X[1] + padding, Y[1] + padding]
]);
const path = d3.geoPath(projection);

// Unproject each of the voronoi polygons, reclaiming the spherical coordinates
// of their points. However it's not as simple as it sounds, because… when we clip
// to the (planar) rectangle, we get edges that look straight on the plane, but are
// not segments of great circles. So we need to make sure that the segments are not
// too long. And when they are too long, we have to sample by splitting them into
// small pieces, in order to have enough intermediate points.
return {
type: "FeatureCollection",
features: d3
.geoVoronoi(points)
.polygons()
.features.map((feature) => {
let p = path(feature);
if (p) {
const planarRing = p
.replace(/^M|Z$/g, "")
.split("L")
.map((d) => d.split(",").map((d) => +d));

// needed because we'll use d3.pairs
planarRing.push(planarRing[0]);

const sphericalRing = d3.pairs(planarRing).flatMap(([a, b]) => {
const dist = Math.hypot(a[0] - b[0], a[1] - b[1]); // sample about every 1 degree
const inter = d3.interpolate(a, b);
const steps = Math.ceil(dist);
return d3
.range(steps)
.map((i) => projection.invert(inter(i / steps)));
});

// needed to close the ring, per GeoJSON
sphericalRing.push(sphericalRing[0]);

return {
...feature,
geometry: { type: "Polygon", coordinates: [sphericalRing] }
};
}
})
};
}
Insert cell
import { d3 } from "@visionscarto/geo"
Insert cell
Insert cell
turf = require("@turf/turf@6")
Insert cell
options = ({ bbox })
Insert cell
pts = turf.randomPoint(100, options)
Insert cell
voronoiPolygons = turf.voronoi(pts, options)
Insert cell
Plot.plot({
projection: "equirectangular",
marks: [Plot.geo(voronoiPolygons), Plot.geo(pts, { fill: "black" })]
})
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