PostGISGeometry Processing

ST_VoronoiLines

What is ST_VoronoiLines?

ST_VoronoiLines is a PostGIS function that computes the Voronoi diagram of the input points and returns the resulting edges as a MultiLineString. Each edge represents a boundary between the regions of two nearest input points.

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

tolerance snaps nearby points together; extend_to expands the diagram's bounding envelope so that infinite edges are clipped to a useful extent.

When would you use ST_VoronoiLines?

Use ST_VoronoiLines to produce boundary linework between nearest-neighbour regions — for example drawing watershed divides from sample points, rendering service-area borders, or generating a skeleton for thick polygons via the "medial axis" technique with sampled points.

SQL
1SELECT ST_VoronoiLines(ST_Collect(geom), 0.0, (SELECT geom FROM study_area)) AS divides
2FROM sample_points;

FAQs

How is ST_VoronoiLines different from ST_VoronoiPolygons?

Both compute the same diagram, but one returns edges (MultiLineString) and the other returns closed cells (GeometryCollection of polygons). Use lines for drawing boundaries or using as routing constraints; use polygons for labelling cells or area-based analysis.

Why do some edges look clipped?

Voronoi cells on the convex hull of the input extend to infinity. The function clips them to a finite envelope — by default slightly larger than the input's bounding box, or to extend_to if supplied. Passing a study-area polygon as extend_to gives cleaner output for real-world mapping.

What happens with coincident or very close input points?

Coincident points produce degenerate cells. The tolerance parameter snaps points closer than that distance together before triangulating, which avoids sliver cells. Set tolerance to roughly the positional precision of your input.

Is the output topology consistent with ST_VoronoiPolygons?

Yes — both are computed from the same Delaunay triangulation, so the lines exactly correspond to the polygon boundaries. You can safely use either in the same workflow and expect them to line up perfectly.