ST_ClusterIntersectingWin
What is ST_ClusterIntersectingWin?
ST_ClusterIntersectingWin is a PostGIS window function that returns a cluster id for each input geometry based on connected-component intersection. Two geometries end up in the same cluster if they intersect directly or through a chain of other intersecting geometries.
ST_ClusterIntersectingWin(geometry winset geom) OVER () → integerIt is the window-function companion to the aggregate ST_ClusterIntersecting, returning a cluster id column rather than a packed array of collections.
When would you use ST_ClusterIntersectingWin?
Use ST_ClusterIntersectingWin when you want each feature row to carry its cluster id — for GROUP BY aggregations, joining back to the original table, or per-row attribute classification. It is the right tool when downstream queries work in "one-row-per-feature" style rather than "one-row-per-cluster".
1SELECT id,
2 ST_ClusterIntersectingWin(geom) OVER () AS cluster_id
3FROM parcels;FAQs
How does it compare to ST_ClusterIntersecting?
Same clustering logic, different output shape. The aggregate returns an array of cluster geometries (one row), while the window function returns a cluster id per input row. Use the window form for reporting and joins; use the aggregate for collection-based downstream processing.
Is cluster id zero- or one-based?
Cluster ids are assigned as non-negative integers starting at 0 and are stable within a single query invocation. They are not guaranteed to match ids from a re-run or a different query, so treat them as opaque grouping labels.
How is this different from ST_ClusterDBSCAN with eps = 0?
DBSCAN with eps = 0 and minpoints = 1 matches only exactly coincident geometries — not touching or crossing ones. ST_ClusterIntersectingWin uses ST_Intersects, which captures touches, crossings, and coverings. For topological grouping, use this function.
How does it handle large datasets?
Internally it builds a spatial index on the partition and does a union-find over intersecting pairs — much faster than the O(n²) naive version. For partitioned datasets, use a PARTITION BY clause (e.g. by region) to limit each window's size further.