PostGISGeometry Processing

ST_VoronoiPolygons

What is ST_VoronoiPolygons?

ST_VoronoiPolygons is a PostGIS function that computes the Voronoi diagram of the input points and returns it as a GeometryCollection of polygons. Each polygon (cell) contains all locations closer to its seed point than to any other.

SQL
ST_VoronoiPolygons(geometry g1, float tolerance = 0.0, geometry extend_to = NULL)geometry

tolerance snaps nearby points together; extend_to clips cells to a bounding envelope so that cells along the convex hull are finite.

When would you use ST_VoronoiPolygons?

Use ST_VoronoiPolygons to produce nearest-neighbour regions around a set of points — catchment areas for facilities, proximity zones for sensors, or territory assignments for delivery hubs. It is the canonical "nearest X to each location" decomposition in spatial analysis.

SQL
1SELECT ST_VoronoiPolygons(
2  ST_Collect(geom), 0.0,
3  (SELECT ST_Expand(ST_Extent(geom), 1000) FROM hospitals)
4) AS service_areas
5FROM hospitals;

FAQs

How do I associate each output cell with its input point?

The returned GeometryCollection preserves input order, so the N-th cell corresponds to the N-th input point. Use ST_Dump to unnest with a path, or wrap the input in a subquery with row numbers and join on ordinal position.

Why are cells on the outside unbounded?

By definition, Voronoi cells for points on the convex hull extend to infinity. ST_VoronoiPolygons clips them to a bounding envelope — by default slightly larger than the input extent. Pass extend_to to clip to your study area for cleaner output.

Is this sensitive to coincident points?

Yes — exactly coincident points produce zero-area cells. Use the tolerance parameter to snap near-duplicates together; set it to roughly the positional precision of your data. Deduplicating inputs with ST_Collect(DISTINCT geom) is another option.

Can I use this on geographic coordinates?

The computation is planar, so running on EPSG:4326 gives cells that are distorted relative to true geodesic nearest-neighbour regions. For globally accurate results, reproject to an equal-area or locally-appropriate projection first.