All Products
Search
Document Center

PolarDB:ST_ClusterIntersecting

Last Updated:Mar 28, 2026

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)