ST_ClusterIntersecting

更新时间: 2026-03-28 03:32:49

Groups geometry objects into clusters based on intersection, returning one GeometryCollection per connected group.

Syntax

geometry[]  ST_ClusterIntersecting(geometry set  g)

Parameters

ParameterDescription
gThe geometry dataset to cluster.

Description

ST_ClusterIntersecting returns an array that consists of GeometryCollection objects. Each GeometryCollection object represents an interconnected set of geometry objects.

Examples

The following example clusters three geometry objects — two line strings and one point. The two line strings share the coordinate (0 1), so they are grouped into one GeometryCollection. The point does not intersect either line string, so it forms its own GeometryCollection.

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;
                          st_astext
-------------------------------------------------------------
 GEOMETRYCOLLECTION(LINESTRING(0 0,0 1),LINESTRING(0 1,3 3))
 GEOMETRYCOLLECTION(POINT(-1 -1))
(2 rows)
上一篇: ST_ClusterDBSCAN 下一篇: ST_ClusterKMeans
阿里云首页 云原生数据库 PolarDB 相关技术圈