ST_DWithinCC
Clustering
ST_DWithinCC (Python)
Assign a connected component id to each geometry based on the ST_DWithin predicate.
Assign a connected component id to each geometry based on the ST_DWithin predicate.
Two geometries are in the same component if they are connected through any chain
of geometries that are within the given distance of each other.
SQL reference:

