名称

ST_ClusterIntersectingWin — 窗口函数,返回每个输入几何图形的簇 ID,将输入几何图形聚类到连接的集合中。

大纲

integer ST_ClusterIntersectingWin(geometry winset geom);

描述

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

可用性:3.4.0

示例

Return an explicit cluster id for each input geometry. Using the conventional cid alias keeps the geometry column ready for color-by-cluster rendering.

Code
WITH testdata(id, geom) AS (
  VALUES (1, 'LINESTRING (0 0,1 1)'::geometry),
         (2, 'LINESTRING (5 5,4 4)'::geometry),
         (3, 'LINESTRING (6 6,7 7)'::geometry),
         (4, 'LINESTRING (0 0,-1 -1)'::geometry),
         (5, 'POLYGON ((0 0,4 0,4 4,0 4,0 0))'::geometry)
), clustered AS (
  SELECT id,
         geom,
         ST_ClusterIntersectingWin(geom) OVER () AS cid
  FROM testdata
)
SELECT id,
       geom AS geom_wkt,
       cid
FROM clustered
ORDER BY id;
栅格输出
id |            geom_wkt            | cid
----+--------------------------------+-----
  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
Figure
Geometry figure for visual-st-clusterintersectingwin-01