Subgroup: other

Class: QgsSpatialIndex

class qgis.core.QgsSpatialIndex

Bases: sip.wrapper

Constructor - creates R-tree

QgsSpatialIndex(fi: QgsFeatureIterator, feedback: QgsFeedback = None) Constructor - creates R-tree and bulk loads it with features from the iterator. This is much faster approach than creating an empty index and then inserting features one by one.

The optional feedback object can be used to allow cancelation of bulk feature loading. Ownership of feedback is not transferred, and callers must take care that the lifetime of feedback exceeds that of the spatial index construction.

New in version 2.8.

QgsSpatialIndex(source: QgsFeatureSource, feedback: QgsFeedback = None) Constructor - creates R-tree and bulk loads it with features from the source. This is much faster approach than creating an empty index and then inserting features one by one.

The optional feedback object can be used to allow cancelation of bulk feature loading. Ownership of feedback is not transferred, and callers must take care that the lifetime of feedback exceeds that of the spatial index construction.

New in version 3.0.

QgsSpatialIndex(other: QgsSpatialIndex) Copy constructor

Methods

deleteFeature Remove feature from index
insertFeature Add feature to index
intersects Returns features that intersect the specified rectangle
nearestNeighbor Returns nearest neighbors (their count is specified by second parameter)
refs get reference count - just for debugging!

Attributes

deleteFeature(self, f: QgsFeature) → bool

Remove feature from index

insertFeature(self, f: QgsFeature) → bool

Add feature to index

insertFeature(self, id: int, bounds: QgsRectangle) -> bool Add a feature id to the index with a specified bounding box.

Returns:true if feature was successfully added to index.

New in version 3.0.

intersects(self, rect: QgsRectangle) → object

Returns features that intersect the specified rectangle

nearestNeighbor(self, point: QgsPointXY, neighbors: int) → object

Returns nearest neighbors (their count is specified by second parameter)

refs(self) → int

get reference count - just for debugging!