QgsSpatialIndexKDBush class
A very fast static spatial index for 2D points based on a flat KD-tree.
Contents
Compared to QgsSpatialIndex, this index:
- supports single point features only (no multipoints)
- is static (features cannot be added or removed from the index after construction)
- is much faster!
- allows direct retrieval of the original feature's points, without requiring additional feature requests
- supports true "distance based" searches, i.e. return all points within a radius from a search point
QgsSpatialIndexKDBush objects are implicitly shared and can be inexpensively copied.
Constructors, destructors, conversion operators
- QgsSpatialIndexKDBush(QgsFeatureIterator& fi, QgsFeedback* feedback = nullptr) explicit
- Constructor - creates KDBush index and bulk loads it with features from the iterator.
- QgsSpatialIndexKDBush(const QgsFeatureSource& source, QgsFeedback* feedback = nullptr) explicit
- Constructor - creates KDBush index and bulk loads it with features from the source.
- QgsSpatialIndexKDBush(const QgsSpatialIndexKDBush& other)
- Copy constructor.
Public functions
- auto intersects(const QgsRectangle& rectangle) const -> QList<QgsSpatialIndexKDBushData>
- Returns the list of features which fall within the specified rectangle.
- void intersects(const QgsRectangle& rectangle, const std::function<void(QgsSpatialIndexKDBushData)>& visitor) const
- Calls a visitor function for all features which fall within the specified rectangle.
- auto operator=(const QgsSpatialIndexKDBush& other) -> QgsSpatialIndexKDBush&
- Assignment operator.
- auto size() const -> qgssize
- Returns the size of the index, i.e.
- auto within(const QgsPointXY& point, double radius) const -> QList<QgsSpatialIndexKDBushData>
- Returns the list of features which are within the given search radius of point.
- void within(const QgsPointXY& point, double radius, const std::function<void(QgsSpatialIndexKDBushData)>& visitor)
- Calls a visitor function for all features which are within the given search radius of point.
Function documentation
QgsSpatialIndexKDBush:: QgsSpatialIndexKDBush(QgsFeatureIterator& fi,
QgsFeedback* feedback = nullptr) explicit
Constructor - creates KDBush index and bulk loads it with features from the iterator.
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.
Any non-single point features encountered during iteration will be ignored and not included in the index.
QgsSpatialIndexKDBush:: QgsSpatialIndexKDBush(const QgsFeatureSource& source,
QgsFeedback* feedback = nullptr) explicit
Constructor - creates KDBush index and bulk loads it with features from the source.
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.
Any non-single point features encountered during iteration will be ignored and not included in the index.
void QgsSpatialIndexKDBush:: intersects(const QgsRectangle& rectangle,
const std::function<void(QgsSpatialIndexKDBushData)>& visitor) const
Calls a visitor function for all features which fall within the specified rectangle.
void QgsSpatialIndexKDBush:: within(const QgsPointXY& point,
double radius,
const std::function<void(QgsSpatialIndexKDBushData)>& visitor)
Calls a visitor function for all features which are within the given search radius of point.