What is @turf/voronoi?
@turf/voronoi is a module within the Turf.js library that allows you to generate Voronoi diagrams from a set of points. Voronoi diagrams partition a plane into regions based on the distance to a specific set of points, which can be useful in various geospatial analyses.
What are @turf/voronoi's main functionalities?
Generate Voronoi Diagram
This feature allows you to generate a Voronoi diagram from a set of points. The code sample demonstrates how to create Voronoi polygons using a bounding box to limit the extent of the diagram.
const turf = require('@turf/turf');
const points = turf.points([
[-75.343, 39.984],
[-75.833, 39.284],
[-75.534, 39.123],
[-75.123, 39.567]
]);
const bbox = [-80, 30, -70, 50];
const voronoiPolygons = turf.voronoi(points, {bbox: bbox});
console.log(JSON.stringify(voronoiPolygons));
Other packages similar to @turf/voronoi
d3-voronoi
d3-voronoi is a module within the D3.js library that provides tools for computing Voronoi diagrams. It is highly customizable and integrates well with D3's powerful data visualization capabilities. Compared to @turf/voronoi, d3-voronoi is more focused on visualization and less on geospatial analysis.
voronoi-diagram
voronoi-diagram is a lightweight npm package for generating Voronoi diagrams. It is simple to use and can be a good alternative if you need a straightforward solution for creating Voronoi diagrams without the additional geospatial functionalities provided by @turf/voronoi.
@turf/voronoi
voronoi
Takes a FeatureCollection of points, and a bounding box, and returns a FeatureCollection
of Voronoi polygons.
The Voronoi algorithim used comes from the d3-voronoi package.
Parameters
points
FeatureCollection<Point> to find the Voronoi polygons around.options
Object Optional parameters (optional, default {}
)
options.bbox
Array<number> clipping rectangle, in [minX, minY, maxX, MaxY] order. (optional, default [-180,-85,180,-85]
)
Examples
var options = {
bbox: [-70, 40, -60, 60]
};
var points = turf.randomPoint(100, options);
var voronoiPolygons = turf.voronoi(points, options);
var addToMap = [voronoiPolygons, points];
Returns FeatureCollection<Polygon> a set of polygons, one per input point.
This module is part of the Turfjs project, an open source
module collection dedicated to geographic algorithms. It is maintained in the
Turfjs/turf repository, where you can create
PRs and issues.
Installation
Install this module individually:
$ npm install @turf/voronoi
Or install the Turf module that includes it as a function:
$ npm install @turf/turf