QGIS API Documentation 3.99.0-Master (2fe06baccd8)
Loading...
Searching...
No Matches
QgsSpatialIndexKDBush Class Reference

A very fast static spatial index for 2D points based on a flat KD-tree. More...

#include <qgsspatialindexkdbush.h>

Public Member Functions

 QgsSpatialIndexKDBush (const QgsFeatureSource &source, QgsFeedback *feedback=nullptr)
 Constructor - creates KDBush index and bulk loads it with features from the source.
 QgsSpatialIndexKDBush (const QgsSpatialIndexKDBush &other)
 QgsSpatialIndexKDBush (QgsFeatureIterator &fi, const std::function< bool(const QgsFeature &) > &callback, QgsFeedback *feedback=nullptr)
 Constructor - creates KDBush index and bulk loads it with features from the source.
 QgsSpatialIndexKDBush (QgsFeatureIterator &fi, QgsFeedback *feedback=nullptr)
 Constructor - creates KDBush index and bulk loads it with features from the iterator.
 ~QgsSpatialIndexKDBush ()
QList< QgsSpatialIndexKDBushDataintersects (const QgsRectangle &rectangle) const
 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.
QgsSpatialIndexKDBushoperator= (const QgsSpatialIndexKDBush &other)
qgssize size () const
 Returns the size of the index, i.e.
QList< QgsSpatialIndexKDBushDatawithin (const QgsPointXY &point, double radius) const
 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.

Friends

class TestQgsSpatialIndexKdBush

Detailed Description

A very fast static spatial index for 2D points based on a flat KD-tree.

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.

See also
QgsSpatialIndex, which is an general, mutable index for geometry bounding boxes.
Since
QGIS 3.4

Definition at line 56 of file qgsspatialindexkdbush.h.

Constructor & Destructor Documentation

◆ QgsSpatialIndexKDBush() [1/4]

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

Definition at line 25 of file qgsspatialindexkdbush.cpp.

◆ QgsSpatialIndexKDBush() [2/4]

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

Definition at line 31 of file qgsspatialindexkdbush.cpp.

◆ QgsSpatialIndexKDBush() [3/4]

QgsSpatialIndexKDBush::QgsSpatialIndexKDBush ( QgsFeatureIterator & fi,
const std::function< bool(const QgsFeature &) > & callback,
QgsFeedback * feedback = nullptr )
explicit

Constructor - creates KDBush index and bulk loads it with features from the source.

This constructor allows for a callback function to be specified, which is called for each added feature in turn. It allows for bulk spatial index load along with other feature based operations on a single iteration through a feature source. If callback returns false, the load and iteration is canceled.

The optional feedback object can be used to allow cancellation 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.

Note
Not available in Python bindings
Since
QGIS 3.22

◆ QgsSpatialIndexKDBush() [4/4]

QgsSpatialIndexKDBush::QgsSpatialIndexKDBush ( const QgsSpatialIndexKDBush & other)

Definition at line 43 of file qgsspatialindexkdbush.cpp.

◆ ~QgsSpatialIndexKDBush()

QgsSpatialIndexKDBush::~QgsSpatialIndexKDBush ( )

Definition at line 63 of file qgsspatialindexkdbush.cpp.

Member Function Documentation

◆ intersects() [1/2]

QList< QgsSpatialIndexKDBushData > QgsSpatialIndexKDBush::intersects ( const QgsRectangle & rectangle) const

Returns the list of features which fall within the specified rectangle.

Definition at line 86 of file qgsspatialindexkdbush.cpp.

◆ intersects() [2/2]

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.

Note
Not available in Python bindings

Definition at line 96 of file qgsspatialindexkdbush.cpp.

◆ operator=()

QgsSpatialIndexKDBush & QgsSpatialIndexKDBush::operator= ( const QgsSpatialIndexKDBush & other)

Definition at line 48 of file qgsspatialindexkdbush.cpp.

◆ size()

qgssize QgsSpatialIndexKDBush::size ( ) const

Returns the size of the index, i.e.

the number of points contained within the index.

Definition at line 81 of file qgsspatialindexkdbush.cpp.

◆ within() [1/2]

QList< QgsSpatialIndexKDBushData > QgsSpatialIndexKDBush::within ( const QgsPointXY & point,
double radius ) const

Returns the list of features which are within the given search radius of point.

Definition at line 69 of file qgsspatialindexkdbush.cpp.

◆ within() [2/2]

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.

Note
Not available in Python bindings

Definition at line 76 of file qgsspatialindexkdbush.cpp.

◆ TestQgsSpatialIndexKdBush

friend class TestQgsSpatialIndexKdBush
friend

Definition at line 145 of file qgsspatialindexkdbush.h.


The documentation for this class was generated from the following files: