> ## Documentation Index
> Fetch the complete documentation index at: https://docs.wherobots.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Spatial Connected Components Python Module

> Identify connected groups of geometries in Python using spatial predicates, including intersection, touching, overlap, containment, and distance.

Spatial connected components identify groups of geometries that are transitively connected through a spatial predicate. Unlike density-based clustering (DBSCAN), they do not require a minimum density: any chain of pairwise-related geometries forms a single component.

## Predicate Functions

These eight functions assign a connected component ID to each geometry according to a spatial predicate.

### ST\_IntersectsCC

Connects geometries that share at least one point. See the [ST\_IntersectsCC SQL reference](/reference/wherobots-db/geometry-data/predicates/ST_IntersectsCC).

### ST\_TouchesCC

Connects geometries that share a boundary point without overlapping interiors. See the [ST\_TouchesCC SQL reference](/reference/wherobots-db/geometry-data/predicates/ST_TouchesCC).

### ST\_OverlapsCC

Connects geometries of the same dimension that share some, but not all, interior points. See the [ST\_OverlapsCC SQL reference](/reference/wherobots-db/geometry-data/predicates/ST_OverlapsCC).

### ST\_ContainsCC

Connects geometries when one fully contains another. See the [ST\_ContainsCC SQL reference](/reference/wherobots-db/geometry-data/predicates/ST_ContainsCC).

### ST\_CoversCC

Connects geometries when one covers every point of another. See the [ST\_CoversCC SQL reference](/reference/wherobots-db/geometry-data/predicates/ST_CoversCC).

### ST\_WithinCC

Connects geometries when one is completely within another. See the [ST\_WithinCC SQL reference](/reference/wherobots-db/geometry-data/predicates/ST_WithinCC).

### ST\_CoveredByCC

Connects geometries when one is covered by another. See the [ST\_CoveredByCC SQL reference](/reference/wherobots-db/geometry-data/predicates/ST_CoveredByCC).

### ST\_CrossesCC

Connects geometries that cross and have a lower-dimensional intersection. See the [ST\_CrossesCC SQL reference](/reference/wherobots-db/geometry-data/predicates/ST_CrossesCC).

## Shared Predicate Function API

All eight predicate functions share this signature; replace `ST_IntersectsCC` with the function name you need:

```python theme={"system"}
ST_IntersectsCC(
    geometry: ColumnOrName,
    partition_by: Optional[ColumnOrName] = None,
) -> Column
```

### Parameters

<ParamField path="geometry" type="ColumnOrName" required>
  Geometry column or column name to analyze. Pass the desired `GeometryType` column explicitly.
</ParamField>

<ParamField path="partition_by" type="Optional[ColumnOrName]">
  Optional column to partition by 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.
</ParamField>

### Returns

<ResponseField name="return" type="BIGINT">
  A PySpark Column containing the connected component ID for each row, including singletons (geometries that do not satisfy the predicate with any other geometry).
</ResponseField>

### Usage Examples

```python theme={"system"}
from sedona.spark.sql.st_functions import ST_IntersectsCC, ST_TouchesCC

# Find connected components based on intersection
result = df.select("*", ST_IntersectsCC("geometry").alias("component_id"))

# With partition_by to limit comparisons within categories
result = df.select(
    "*", ST_IntersectsCC("geometry", partition_by="category").alias("component_id")
)

# Using ST_TouchesCC for boundary-adjacent geometries
result = df.select("*", ST_TouchesCC("geometry").alias("component_id"))
```

## ST\_DWithinCC

Assign a connected component ID to each geometry using a distance-based predicate. See the [ST\_DWithinCC SQL reference](/reference/wherobots-db/geometry-data/predicates/ST_DWithinCC).

```python theme={"system"}
ST_DWithinCC(
    geometry: ColumnOrName,
    distance: Union[ColumnOrName, float],
    use_spheroid: Optional[Union[ColumnOrName, bool]] = None,
    partition_by: Optional[ColumnOrName] = None,
) -> Column
```

### Parameters

<ParamField path="geometry" type="ColumnOrName" required>
  Geometry column or column name to analyze.
</ParamField>

<ParamField path="distance" type="Union[ColumnOrName, float]" required>
  The distance threshold. Two geometries within this distance are considered connected.
</ParamField>

<ParamField path="use_spheroid" type="Optional[Union[ColumnOrName, bool]]">
  Whether to use spheroidal distance calculation. Default is false.
</ParamField>

<ParamField path="partition_by" type="Optional[ColumnOrName]">
  Optional column to partition by before computing connected components. When provided, the spatial predicate is only evaluated between rows that share the same partition value.
</ParamField>

### Returns

<ResponseField name="return" type="BIGINT">
  A PySpark Column containing the connected component ID for each row.
</ResponseField>

### Usage Examples

```python theme={"system"}
from sedona.spark.sql.st_functions import ST_DWithinCC

# Distance-based connected components
result = df.select(
    "*", ST_DWithinCC("geometry", 1.0, use_spheroid=False).alias("component_id")
)

# With partition_by
result = df.select(
    "*", ST_DWithinCC("geometry", 500.0, use_spheroid=True, partition_by="state").alias("component_id")
)
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.