QGIS API Documentation
3.24.2-Tisler (13c1a02865)
|
A spatial index for QgsFeature objects. More...
#include <qgsspatialindex.h>
Public Types | |
enum | Flag { FlagStoreFeatureGeometries = 1 << 0 } |
Flags controlling index behavior. More... | |
Public Types inherited from QgsFeatureSink | |
enum | Flag { FastInsert = 1 << 1 , RollBackOnErrors = 1 << 2 } |
Flags controlling how features are added to a sink. More... | |
enum | SinkFlag { RegeneratePrimaryKey = 1 << 1 } |
Flags that can be set on a QgsFeatureSink. More... | |
Public Member Functions | |
QgsSpatialIndex (const QgsFeatureIterator &fi, const std::function< bool(const QgsFeature &) > &callback, QgsSpatialIndex::Flags flags=QgsSpatialIndex::Flags()) | |
Constructor - creates R-tree and bulk loads it with features from the iterator. More... | |
QgsSpatialIndex (const QgsFeatureIterator &fi, QgsFeedback *feedback=nullptr, QgsSpatialIndex::Flags flags=QgsSpatialIndex::Flags()) | |
Constructor - creates R-tree and bulk loads it with features from the iterator. More... | |
QgsSpatialIndex (const QgsFeatureSource &source, QgsFeedback *feedback=nullptr, QgsSpatialIndex::Flags flags=QgsSpatialIndex::Flags()) | |
Constructor - creates R-tree and bulk loads it with features from the source. More... | |
QgsSpatialIndex (const QgsSpatialIndex &other) | |
Copy constructor. More... | |
QgsSpatialIndex (QgsSpatialIndex::Flags flags=QgsSpatialIndex::Flags()) | |
Constructor for QgsSpatialIndex. More... | |
~QgsSpatialIndex () override | |
Destructor finalizes work with spatial index. More... | |
bool | addFeature (QgsFeature &feature, QgsFeatureSink::Flags flags=QgsFeatureSink::Flags()) override |
Adds a feature to the index. More... | |
bool | addFeature (QgsFeatureId id, const QgsRectangle &bounds) |
Add a feature id to the index with a specified bounding box. More... | |
bool | addFeatures (QgsFeatureList &features, QgsFeatureSink::Flags flags=QgsFeatureSink::Flags()) override |
Adds a list of features to the index. More... | |
bool | deleteFeature (const QgsFeature &feature) |
Removes a feature from the index. More... | |
QgsGeometry | geometry (QgsFeatureId id) const |
Returns the stored geometry for the indexed feature with matching id. More... | |
Q_DECL_DEPRECATED bool | insertFeature (const QgsFeature &feature) |
Adds a feature to the index. More... | |
Q_DECL_DEPRECATED bool | insertFeature (QgsFeatureId id, const QgsRectangle &bounds) |
Add a feature id to the index with a specified bounding box. More... | |
QList< QgsFeatureId > | intersects (const QgsRectangle &rectangle) const |
Returns a list of features with a bounding box which intersects the specified rectangle. More... | |
QList< QgsFeatureId > | nearestNeighbor (const QgsGeometry &geometry, int neighbors=1, double maxDistance=0) const |
Returns nearest neighbors to a geometry. More... | |
QList< QgsFeatureId > | nearestNeighbor (const QgsPointXY &point, int neighbors=1, double maxDistance=0) const |
Returns nearest neighbors to a point. More... | |
QgsSpatialIndex & | operator= (const QgsSpatialIndex &other) |
Implement assignment operator. More... | |
QAtomicInt | refs () const |
Gets reference count - just for debugging! More... | |
Public Member Functions inherited from QgsFeatureSink | |
virtual | ~QgsFeatureSink ()=default |
virtual bool | addFeatures (QgsFeatureIterator &iterator, QgsFeatureSink::Flags flags=QgsFeatureSink::Flags()) |
Adds all features from the specified iterator to the sink. More... | |
virtual bool | flushBuffer () |
Flushes any internal buffer which may exist in the sink, causing any buffered features to be added to the sink's destination. More... | |
virtual QString | lastError () const |
Returns the most recent error encountered by the sink, e.g. More... | |
Friends | |
class | QgsFeatureIteratorDataStream |
A spatial index for QgsFeature objects.
QgsSpatialIndex objects are implicitly shared and can be inexpensively copied.
Definition at line 67 of file qgsspatialindex.h.
Flags controlling index behavior.
Definition at line 75 of file qgsspatialindex.h.
QgsSpatialIndex::QgsSpatialIndex | ( | QgsSpatialIndex::Flags | flags = QgsSpatialIndex::Flags() | ) |
Constructor for QgsSpatialIndex.
Creates an empty R-tree index.
Definition at line 345 of file qgsspatialindex.cpp.
|
explicit |
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 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.
Definition at line 350 of file qgsspatialindex.cpp.
|
explicit |
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.
This construct and bulk load variant 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.
|
explicit |
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 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.
Definition at line 362 of file qgsspatialindex.cpp.
QgsSpatialIndex::QgsSpatialIndex | ( | const QgsSpatialIndex & | other | ) |
Copy constructor.
Definition at line 367 of file qgsspatialindex.cpp.
|
override |
Destructor finalizes work with spatial index.
Definition at line 372 of file qgsspatialindex.cpp.
|
overridevirtual |
Adds a feature to the index.
The flags argument is ignored.
Reimplemented from QgsFeatureSink.
Definition at line 407 of file qgsspatialindex.cpp.
bool QgsSpatialIndex::addFeature | ( | QgsFeatureId | id, |
const QgsRectangle & | bounds | ||
) |
Add a feature id to the index with a specified bounding box.
true
if feature was successfully added to index. Definition at line 448 of file qgsspatialindex.cpp.
|
overridevirtual |
Adds a list of features to the index.
The flags argument is ignored.
Implements QgsFeatureSink.
Definition at line 426 of file qgsspatialindex.cpp.
bool QgsSpatialIndex::deleteFeature | ( | const QgsFeature & | feature | ) |
Removes a feature from the index.
Definition at line 478 of file qgsspatialindex.cpp.
QgsGeometry QgsSpatialIndex::geometry | ( | QgsFeatureId | id | ) | const |
Returns the stored geometry for the indexed feature with matching id.
Geometry is only stored if the QgsSpatialIndex was created with the FlagStoreFeatureGeometries flag.
Definition at line 556 of file qgsspatialindex.cpp.
bool QgsSpatialIndex::insertFeature | ( | const QgsFeature & | feature | ) |
Adds a feature to the index.
Definition at line 437 of file qgsspatialindex.cpp.
bool QgsSpatialIndex::insertFeature | ( | QgsFeatureId | id, |
const QgsRectangle & | bounds | ||
) |
Add a feature id to the index with a specified bounding box.
true
if feature was successfully added to index. Definition at line 443 of file qgsspatialindex.cpp.
QList< QgsFeatureId > QgsSpatialIndex::intersects | ( | const QgsRectangle & | rectangle | ) | const |
Returns a list of features with a bounding box which intersects the specified rectangle.
Definition at line 492 of file qgsspatialindex.cpp.
QList< QgsFeatureId > QgsSpatialIndex::nearestNeighbor | ( | const QgsGeometry & | geometry, |
int | neighbors = 1 , |
||
double | maxDistance = 0 |
||
) | const |
Returns nearest neighbors to a geometry.
The number of neighbors returned is specified by the neighbors argument.
If the maxDistance argument is greater than 0, then only features within the specified distance of point will be considered.
Note that in some cases the number of returned features may differ from the requested number of neighbors. E.g. if not enough features exist within the maxDistance of the search point. If multiple features are equidistant from the search point then the number of returned feature IDs may exceed neighbors.
Definition at line 531 of file qgsspatialindex.cpp.
QList< QgsFeatureId > QgsSpatialIndex::nearestNeighbor | ( | const QgsPointXY & | point, |
int | neighbors = 1 , |
||
double | maxDistance = 0 |
||
) | const |
Returns nearest neighbors to a point.
The number of neighbors returned is specified by the neighbors argument.
If the maxDistance argument is greater than 0, then only features within the specified distance of point will be considered.
Note that in some cases the number of returned features may differ from the requested number of neighbors. E.g. if not enough features exist within the maxDistance of the search point. If multiple features are equidistant from the search point then the number of returned feature IDs may exceed neighbors.
Definition at line 505 of file qgsspatialindex.cpp.
QgsSpatialIndex & QgsSpatialIndex::operator= | ( | const QgsSpatialIndex & | other | ) |
Implement assignment operator.
Definition at line 376 of file qgsspatialindex.cpp.
QAtomicInt QgsSpatialIndex::refs | ( | ) | const |
Gets reference count - just for debugging!
Definition at line 562 of file qgsspatialindex.cpp.
|
friend |
Definition at line 297 of file qgsspatialindex.h.