Turf.jsTransformation

turf.voronoi

What is turf.voronoi?

turf.voronoi takes a FeatureCollection<Point> and returns a FeatureCollection<Polygon> where each polygon is the Voronoi cell for one input point — the region of space closer to that point than to any other. Cells are clipped to a user-provided bounding box.

JavaScript
turf.voronoi(points, options?) → FeatureCollection<Polygon>

Options include:

  • bbox — bounding box to clip to (default [-180, -85, 180, 85])

When would you use turf.voronoi?

Use turf.voronoi to compute service areas — which police station, store, or warehouse is nearest for every location. The resulting polygons are perfect MapLibre fill layers for "closest to" visualisations.

Beyond service areas, Voronoi tessellations are used in grid-free interpolation (natural neighbour), cell decomposition for agent simulations, and quick point-in-polygon lookups when you want to bucket arbitrary query points by nearest seed.

Code
undefined

FAQs

Is the result clipped to my bbox?

Yes — cells extending beyond bbox are truncated at the bbox edges. Choose a bbox matching your area of interest; the default (near-global) is rarely what you want.

How do I install just voronoi?

npm install @turf/voronoi. It depends on @turf/helpers, @turf/invariant, and d3-voronoi.

Does it handle duplicate coordinates?

No — coincident points produce degenerate Voronoi diagrams and are silently skipped or cause null cells. Deduplicate your input with turf.cleanCoords or a Map-based filter first.

Can I use this for nearest-neighbour queries?

Yes — pre-compute Voronoi cells once, then use turf.booleanPointInPolygon to classify any new point by its containing cell. This is much faster than scanning every seed point for large datasets.