名称

ST_ClusterIntersectingWin — 窗口函数,可为每个输入几何返回一个群集 ID,将输入几何聚类到已连接的集合中。

语法

integer ST_ClusterIntersectingWin(geometry winset geom);

描述

一个窗口函数,用于构建相交几何的连接群集。可以在不离开群集的情况下遍历群集中的所有几何。返回值是几何参数参与的群集号,或空输入的空值。

可用性:3.4.0

示例

WITH testdata AS (
  SELECT id, geom::geometry FROM (
  VALUES  (1, 'LINESTRING (0 0, 1 1)'),
          (2, 'LINESTRING (5 5, 4 4)'),
          (3, 'LINESTRING (6 6, 7 7)'),
          (4, 'LINESTRING (0 0, -1 -1)'),
          (5, 'POLYGON ((0 0, 4 0, 4 4, 0 4, 0 0))')) AS t(id, geom)
)
SELECT id, 
  ST_AsText(geom), 
  ST_ClusterIntersectingWin(geom) OVER () AS cluster 
FROM testdata;

 id |           st_astext            | cluster 
----+--------------------------------+---------
  1 | LINESTRING(0 0,1 1)            |       0
  2 | LINESTRING(5 5,4 4)            |       0
  3 | LINESTRING(6 6,7 7)            |       1
  4 | LINESTRING(0 0,-1 -1)          |       0
  5 | POLYGON((0 0,4 0,4 4,0 4,0 0)) |       0

        

另请参见

ST_ClusterIntersectingST_ClusterWithinST_ClusterWithinWin