ST_ClusterIntersecting

更新时间:
复制 MD 格式

Groups a set of geometry objects by intersection connectivity and returns the result as an array of GeometryCollection objects. Each GeometryCollection contains one cluster of mutually intersecting geometries.

Syntax

geometry[]  ST_ClusterIntersecting(geometry set g)

Parameters

ParameterDescription
gThe geometry dataset to cluster.

Example

The following example clusters three geometries. The two LINESTRING objects share a point, so they form one cluster. The isolated POINT forms a second cluster.

SELECT ST_AsText(unnest(ST_ClusterIntersecting(geom)))
    from (select ARRAY['LINESTRING (0 0,0 1)'::geometry,
                     'LINESTRING (0 1,3 3)'::geometry,
                     'POINT (-1 -1)'::geometry] as geom) as test;

Output:

                          st_astext
-------------------------------------------------------------
 GEOMETRYCOLLECTION(LINESTRING(0 0,0 1),LINESTRING(0 1,3 3))
 GEOMETRYCOLLECTION(POINT(-1 -1))
(2 rows)