ST_ClusterWithin — 按分隔距离对输入几何图形进行聚类的聚合函数。
geometry[] ST_ClusterWithin(
geometry set g, float8 distance)
;
ST_ClusterWiThin是一个聚合函数,它返回GeometryCollection数组,其中每个GeometryCollection表示一组相隔不超过指定距离的几何图形。(距离是以SRID为单位的笛卡尔距离。)
可用性:2.2.0
WITH testdata AS (SELECT unnest(ARRAY['LINESTRING (0 0, 1 1)'::geometry, 'LINESTRING (5 5, 4 4)'::geometry, 'LINESTRING (6 6, 7 7)'::geometry, 'LINESTRING (0 0, -1 -1)'::geometry, 'POLYGON ((0 0, 4 0, 4 4, 0 4, 0 0))'::geometry]) AS geom) SELECT ST_AsText(unnest(ST_ClusterWithin(geom, 1.4))) FROM testdata; --result st_astext --------- GEOMETRYCOLLECTION(LINESTRING(0 0,1 1),LINESTRING(5 5,4 4),LINESTRING(0 0,-1 -1),POLYGON((0 0,4 0,4 4,0 4,0 0))) GEOMETRYCOLLECTION(LINESTRING(6 6,7 7))