ST_VoronoiPolygons

更新时间:
复制 MD 格式

ST_VoronoiPolygons computes a two-dimensional Voronoi diagram from the vertices of a geometry object and returns the result as a GeometryCollection of polygons.

Syntax

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

Parameters

ParameterTypeDefaultDescription
g1geometryThe input geometry whose vertices are used to compute the Voronoi diagram.
tolerancefloat0.0The snap distance. Vertices within this distance of each other are treated as coincident. A non-zero value improves the robustness of the algorithm.
extend_togeometryNULLThe envelope to which the Voronoi diagram is extended. If NULL, the diagram extends to a bounding box expanded by approximately 50% in each direction around the input geometry. If specified, the diagram extends to cover this envelope, unless the envelope is smaller than the default.

Return value behavior

  • Returns a GeometryCollection of polygons. The output envelope is larger than the extent of the input vertices.

  • Returns NULL if g1 is NULL.

  • Returns an empty GeometryCollection if g1 contains only one vertex.

  • Returns an empty GeometryCollection if the area of the extend_to envelope is zero.

Examples

The following example shows the differences between the return results that are obtained when the extend_to parameter is set to different values.

SELECT ST_VoronoiPolygons(g, 0, e), g, e
FROM (
    SELECT
        ST_Buffer('LINESTRING(0 0,3 0,3 3)'::geometry, 1, 'join=mitre endcap=square') AS g,
        ST_Buffer('POINT(-1 -1)'::geometry, 10) AS e
) AS t;

Result with default envelope:

Result with default envelope

Result with custom envelope:

Result with custom envelope