給定一個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)