> ## 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.

# SpatialIndex

> The spatial index returned by GeoSeries.sindex and GeoDataFrame.sindex.

```python theme={"system"}
from sedona.spark.geopandas.sindex import SpatialIndex
```

## SpatialIndex

```python theme={"system"}
SpatialIndex(geometry, index_type='strtree', column_name=None)
```

A wrapper around Sedona's spatial index functionality.

Initialize the SpatialIndex with geometry data.

#### Parameters

<ParamField path="geometry" type="np.array of Shapely geometries, GeoSeries, or PySparkDataFrame" required />

<ParamField path="index_type" type="str" default="'strtree'">
  The type of spatial index to use.
</ParamField>

<ParamField path="column_name" type="str" default="None">
  The column name to extract geometry from if `geometry` is a PySparkDataFrame.
</ParamField>

### is\_empty

```python theme={"system"}
SpatialIndex.is_empty
```

Check if the spatial index is empty.

#### Returns

<ResponseField name="return" type="bool">
  True if the index is empty, False otherwise.
</ResponseField>

### size

```python theme={"system"}
SpatialIndex.size
```

Get the size of the spatial index.

#### Returns

<ResponseField name="return" type="int">
  Number of geometries in the index.
</ResponseField>

### valid\_query\_predicates

```python theme={"system"}
SpatialIndex.valid_query_predicates: set
```

Return the supported values for the `query` predicate.

*Added in version 2.0.0.*

#### Returns

<ResponseField name="return" type="set">
  A new set containing `None`, `"intersects"`, and `"contains"`.
  `None` selects the default `"intersects"` behavior.
</ResponseField>

### intersection()

```python theme={"system"}
intersection(bounds)
```

Find geometries that intersect the given bounding box. Similar to the Geopandas version,
this is a compatibility wrapper for rtree.index.Index.intersection, use query instead.

#### Parameters

<ParamField path="bounds" type="tuple" required>
  Bounding box as (min\_x, min\_y, max\_x, max\_y).
</ParamField>

#### Returns

<ResponseField name="return" type="list">
  List of geometries if constructed from a GeoSeries or PySparkDataFrame.
  List of the corresponding indices if constructed from a np.array.
</ResponseField>

### nearest()

```python theme={"system"}
nearest(geometry: BaseGeometry, k: int = 1, return_distance: bool = False)
```

Find the nearest geometry in the spatial index.

#### Parameters

<ParamField path="geometry" type="BaseGeometry" required>
  The geometry to find the nearest neighbor for.
</ParamField>

<ParamField path="k" type="int" default="1">
  Number of nearest neighbors to find.
</ParamField>

<ParamField path="return_distance" type="bool" default="False">
  Whether to return distances along with indices.
</ParamField>

#### Returns

<ResponseField name="return" type="list or tuple">
  List of geometries if constructed from a GeoSeries or PySparkDataFrame.
  List of the corresponding indices if constructed from a np.array.
</ResponseField>

### query()

```python theme={"system"}
query(geometry: BaseGeometry, predicate: str = None, sort: bool = False)
```

Query the spatial index for geometries that intersect the given geometry.

#### Parameters

<ParamField path="geometry" type="BaseGeometry" required>
  The geometry to query against the spatial index.
</ParamField>

<ParamField path="predicate" type="str" default="None">
  Spatial predicate to filter results. Must be either 'intersects' (default) or 'contains'.
</ParamField>

<ParamField path="sort" type="bool" default="False">
  Whether to sort the results.
</ParamField>

#### Returns

<ResponseField name="return" type="list">
  List of geometries if constructed from a GeoSeries or PySparkDataFrame.
  List of the corresponding indices if constructed from a np.array.
</ResponseField>


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