Skip to main content

SpatialIndex

A wrapper around Sedona’s spatial index functionality. Initialize the SpatialIndex with geometry data.

Parameters

np.array of Shapely geometries, GeoSeries, or PySparkDataFrame
required
str
default:"'strtree'"
The type of spatial index to use.
str
default:"None"
The column name to extract geometry from if geometry is a PySparkDataFrame.

is_empty

Check if the spatial index is empty.

Returns

bool
True if the index is empty, False otherwise.

size

Get the size of the spatial index.

Returns

int
Number of geometries in the index.

valid_query_predicates

Return the supported values for the query predicate. Added in version 2.0.0.

Returns

set
A new set containing None, "intersects", and "contains". None selects the default "intersects" behavior.

intersection()

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

tuple
required
Bounding box as (min_x, min_y, max_x, max_y).

Returns

list
List of geometries if constructed from a GeoSeries or PySparkDataFrame. List of the corresponding indices if constructed from a np.array.

nearest()

Find the nearest geometry in the spatial index.

Parameters

BaseGeometry
required
The geometry to find the nearest neighbor for.
int
default:"1"
Number of nearest neighbors to find.
bool
default:"False"
Whether to return distances along with indices.

Returns

list or tuple
List of geometries if constructed from a GeoSeries or PySparkDataFrame. List of the corresponding indices if constructed from a np.array.

query()

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

Parameters

BaseGeometry
required
The geometry to query against the spatial index.
str
default:"None"
Spatial predicate to filter results. Must be either ‘intersects’ (default) or ‘contains’.
bool
default:"False"
Whether to sort the results.

Returns

list
List of geometries if constructed from a GeoSeries or PySparkDataFrame. List of the corresponding indices if constructed from a np.array.