QgsAbstractFeatureIterator class

Internal feature iterator to be implemented within data providers.

Derived classes

template<typename T>
class QgsAbstractFeatureIteratorFromSource
Helper template that cares of two things: 1.
template<typename T>
class QgsAbstractFeatureIteratorFromSource
Helper template that cares of two things: 1.
class QgsCachedFeatureIterator
Delivers features from the cache.
class QgsCachedFeatureWriterIterator
Uses another iterator as backend and writes features to the cache.

Public types

enum CompileStatus { NoCompilation, PartiallyCompiled, Compiled }
Status of expression compilation for filter expression requests.

Constructors, destructors, conversion operators

QgsAbstractFeatureIterator(const QgsFeatureRequest& request)
base class constructor - stores the iteration parameters
~QgsAbstractFeatureIterator() defaulted virtual
destructor makes sure that the iterator is closed properly

Public functions

auto close() -> bool pure virtual
end of iterating: free the resources / lock
auto compileFailed() const -> bool
Indicator if there was an error when sending the compiled query to the server.
auto compileStatus() const -> CompileStatus
Returns the status of expression compilation for filter expression requests.
auto isValid() const -> bool virtual
Returns if this iterator is valid.
auto nextFeature(QgsFeature& f) -> bool virtual
fetch next feature, return true on success
auto rewind() -> bool pure virtual
reset the iterator to the starting position
void setInterruptionChecker(QgsFeedback* interruptionChecker) virtual
Attach an object that can be queried regularly by the iterator to check if it must stopped.

Protected functions

void deref()
Remove reference, delete if refs == 0.
auto fetchFeature(QgsFeature& f) -> bool pure virtual
If you write a feature iterator for your provider, this is the method you need to implement!!
auto filterRectToSourceCrs(const QgsCoordinateTransform& transform) -> QgsRectangle
Returns a rectangle representing the original request's QgsFeatureRequest::filterRect().
void geometryToDestinationCrs(QgsFeature& feature, const QgsCoordinateTransform& transform) const
Transforms feature's geometry according to the specified coordinate transform.
auto nextFeatureFilterExpression(QgsFeature& f) -> bool virtual
By default, the iterator will fetch all features and check if the feature matches the expression.
auto nextFeatureFilterFids(QgsFeature& f) -> bool virtual
By default, the iterator will fetch all features and check if the id is in the request.
auto prepareSimplification(const QgsSimplifyMethod& simplifyMethod) -> bool virtual
Setup the simplification of geometries to fetch using the specified simplify method.
void ref()
Add reference.

Protected variables

bool mClosed
Sets to true, as soon as the iterator is closed.
CompileStatus mCompileStatus
Status of compilation of filter expression.
long mFetchedCount
Number of features already fetched by iterator.
QgsFeatureRequest mRequest
A copy of the feature request.
bool mValid
An invalid state of a feature iterator indicates that there was a problem with even getting it up and running.
bool mZombie
A feature iterator may be closed already but still be serving features from the cache.
int refs
reference counting (to allow seamless copying of QgsFeatureIterator instances) TODO QGIS3: make this private

Private functions

auto prepareOrderBy(const QList<QgsFeatureRequest::OrderByClause>& orderBys) -> bool virtual
Should be overwritten by providers which implement an own order by strategy If the own order by strategy is successful, return true, if not, return false and a local order by will be triggered instead.
auto providerCanSimplify(QgsSimplifyMethod::MethodType methodType) const -> bool virtual
returns whether the iterator supports simplify geometries on provider side

Enum documentation

enum QgsAbstractFeatureIterator::CompileStatus

Status of expression compilation for filter expression requests.

Enumerators
NoCompilation

Expression could not be compiled or not attempt was made to compile expression.

PartiallyCompiled

Expression was partially compiled, but extra checks need to be applied to features.

Compiled

Expression was fully compiled and delegated to data provider source.

Function documentation

bool QgsAbstractFeatureIterator::compileFailed() const

Indicator if there was an error when sending the compiled query to the server.

This indicates that there is something wrong with the expression compiler.

CompileStatus QgsAbstractFeatureIterator::compileStatus() const

Returns the status of expression compilation for filter expression requests.

bool QgsAbstractFeatureIterator::isValid() const virtual

Returns if this iterator is valid.

An invalid feature iterator is not able to provide a reliable source for data. If an iterator is invalid, either give up or try to send the request again (preferably after a timeout to give the system some time to stay responsive).

If you want to check if the iterator successfully completed, better use QgsFeatureIterator::isClosed().

void QgsAbstractFeatureIterator::setInterruptionChecker(QgsFeedback* interruptionChecker) virtual

Attach an object that can be queried regularly by the iterator to check if it must stopped.

This is mostly useful for iterators where a single nextFeature()/fetchFeature() iteration might be very long. A typical use case is the WFS provider. When nextFeature()/fetchFeature() is reasonably fast, it is not necessary to implement this method. The default implementation does nothing.

bool QgsAbstractFeatureIterator::fetchFeature(QgsFeature& f) pure virtual protected

If you write a feature iterator for your provider, this is the method you need to implement!!

Parameters
f The feature to write to
Returns true if a feature was written to f

QgsRectangle QgsAbstractFeatureIterator::filterRectToSourceCrs(const QgsCoordinateTransform& transform) protected

Returns a rectangle representing the original request's QgsFeatureRequest::filterRect().

If transform is a valid coordinate transform, the return rectangle will represent the requested filterRect() transformed to the source's coordinate reference system. Iterators should call this method and use the returned rectangle for filtering features to ensure that any QgsFeatureRequest::destinationCrs() set on the request is respected. Will throw a QgsCsException if the rect cannot be transformed from the destination CRS.

void QgsAbstractFeatureIterator::geometryToDestinationCrs(QgsFeature& feature, const QgsCoordinateTransform& transform) const protected

Transforms feature's geometry according to the specified coordinate transform.

If feature has no geometry or transform is invalid then calling this method has no effect and will be shortcut. Iterators should call this method before returning features to ensure that any QgsFeatureRequest::destinationCrs() set on the request is respected.

bool QgsAbstractFeatureIterator::nextFeatureFilterExpression(QgsFeature& f) virtual protected

By default, the iterator will fetch all features and check if the feature matches the expression.

Parameters
f The feature to write to
Returns true if a feature was written to f

If you have a more sophisticated metodology (SQL request for the features...) and you check for the expression in your fetchFeature method, you can just redirect this call to fetchFeature so the default check will be omitted.

bool QgsAbstractFeatureIterator::nextFeatureFilterFids(QgsFeature& f) virtual protected

By default, the iterator will fetch all features and check if the id is in the request.

Parameters
f The feature to write to
Returns true if a feature was written to f

If you have a more sophisticated metodology (SQL request for the features...) and you are sure, that any feature you return from fetchFeature will match if the request was FilterFids you can just redirect this call to fetchFeature so the default check will be omitted.

bool QgsAbstractFeatureIterator::prepareOrderBy(const QList<QgsFeatureRequest::OrderByClause>& orderBys) virtual private

Should be overwritten by providers which implement an own order by strategy If the own order by strategy is successful, return true, if not, return false and a local order by will be triggered instead.

By default returns false

Variable documentation

bool QgsAbstractFeatureIterator::mValid protected

An invalid state of a feature iterator indicates that there was a problem with even getting it up and running.

This should be set to false by subclasses if they have problems connecting to the provider. Do NOT set this to false when the feature iterator closes or has no features but we are sure, that it's just an empty dataset.

bool QgsAbstractFeatureIterator::mZombie protected

A feature iterator may be closed already but still be serving features from the cache.

This is done when we serve features which have been pre-fetched and the order by has been locally sorted. In such a scenario, all resources have been released (mClosed is true) but the deads are still alive.