名前

ST_ClusterWithin — 集計関数です。ジオメトリコレクションの配列を返します。要素は、指定した距離以内となるよう分けられたジオメトリの集合です。

概要

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

説明

集計関数です。ジオメトリコレクションの配列を返します。要素は、指定した距離 (SRIDの単位によるデカルト距離)以内となるよう分けられたジオメトリの集合です。

Availability: 2.2.0 - GEOSが必要です。

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;

-- 結果 --

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))
        

関連情報

ST_ClusterDBSCAN, ST_ClusterKMeans, ST_ClusterIntersecting