Skip to main content
Computes spatial connected components across the entire dataframe using the ST_DWithin predicate. Two geometries are in the same component if they are within the specified distance of each other. Returns a component ID for each row. ST_DWithinCC
  • geometry is the geometry column to analyze.
  • distance is the maximum distance threshold for considering two geometries as connected.
  • useSpheroid is whether to use a spheroidal distance calculation (default: false).
  • partitionBy is an optional column to partition the data before computing connected components. When provided, the spatial predicate is only evaluated between rows that share the same partition value. This can significantly improve performance on large datasets.

Signatures

ST_DWithinCC(geometry: Geometry, distance: Double)
ST_DWithinCC(geometry: Geometry, distance: Double, useSpheroid: Boolean)
ST_DWithinCC(geometry: Geometry, distance: Double, useSpheroid: Boolean, partitionBy: Column)

Parameters

geometry
Geometry
required
The input geometry.
distance
Double
required
The distance value.
useSpheroid
Boolean
Whether to use spheroidal distance calculation.
partitionBy
Column
The partition by value.

Return type

The connected component ID for each row.

Example

SELECT ST_DWithinCC(geom, 1.0, False) FROM my_table
85899345920