给定一个Geometry对象的集合,返回由距离不大于给定数值的对象构成的GeometryCollections组成的结果数组。

语法

geometry[]  ST_ClusterWithin(geometry set  g , float8  distance);

参数

参数名称 描述
g 目标Geometry对象。
distance 聚和距离。

描述

距离是由SRID指定单位的笛卡尔距离。

示例

  • 默认调用:
    SELECT ST_AsText(unnest(ST_ClusterWithin(geom,1)))
    	from (select ARRAY['LINESTRING (0 0,0 1)'::geometry,
                         'LINESTRING (2 3,3 3)'::geometry,
                         'LINESTRING (0 1,2 3)'::geometry,
                         'POINT (-1 -1)'::geometry] as geom) as test;
                               st_astext
    ---------------------------------------------------------------
     GEOMETRYCOLLECTION(LINESTRING(0 0,0 1),LINESTRING(2 3,3 3),LINESTRING(0 1,2 3))
     GEOMETRYCOLLECTION(POINT(-1 -1))
    (2 rows)
    
  • 修改聚合距离为2:
    SELECT ST_AsText(unnest(ST_ClusterWithin(geom,2)))
    	from (select ARRAY['LINESTRING (0 0,0 1)'::geometry,
                         'LINESTRING (2 3,3 3)'::geometry,
                         'LINESTRING (0 1,2 3)'::geometry,
                         'POINT (-1 -1)'::geometry] as geom) as test;
                               st_astext
    ---------------------------------------------------------------
     GEOMETRYCOLLECTION(LINESTRING(0 0,0 1),LINESTRING(2 3,3 3),LINESTRING(0 1,2 3),POINT(-1 -1))
    (1 row)