39 if ( mUseCachedFeatures )
41 if ( mFeatureIterator != mCachedFeatures.constEnd() )
43 f = mFeatureIterator->mFeature;
82 mRequest.expressionContext()->setFeature( f );
83 if (
mRequest.filterExpression()->evaluate(
mRequest.expressionContext() ).toBool() )
93 if (
mRequest.filterFids().contains( f.
id() ) )
112 if (
mRequest.transformErrorCallback() )
114 mRequest.transformErrorCallback()( feature );
158 if (
mRequest.filterRect().isNull() )
197 Q_UNUSED( simplifyMethod )
201void QgsAbstractFeatureIterator::setupOrderBy(
const QList<QgsFeatureRequest::OrderByClause> &orderBys )
204 if ( !orderBys.isEmpty() && !prepareOrderBy( orderBys ) )
209 QList<QgsFeatureRequest::OrderByClause> preparedOrderBys( orderBys );
210 QList<QgsFeatureRequest::OrderByClause>::iterator orderByIt( preparedOrderBys.begin() );
215 orderByIt->prepare( expressionContext );
217 while ( ++orderByIt != preparedOrderBys.end() );
220 QgsIndexedFeature indexedFeature;
221 indexedFeature.
mIndexes.resize( preparedOrderBys.size() );
225 expressionContext->setFeature( indexedFeature.
mFeature );
227 const auto constPreparedOrderBys = preparedOrderBys;
228 for (
const QgsFeatureRequest::OrderByClause &orderBy : constPreparedOrderBys )
230 indexedFeature.
mIndexes.replace( i++, orderBy.expression().evaluate( expressionContext ) );
236 mCachedFeatures.append( indexedFeature );
239 std::sort( mCachedFeatures.begin(), mCachedFeatures.end(), QgsExpressionSorter( preparedOrderBys ) );
241 mFeatureIterator = mCachedFeatures.constBegin();
242 mUseCachedFeatures =
true;
250 Q_UNUSED( methodType )
254bool QgsAbstractFeatureIterator::prepareOrderBy(
const QList<QgsFeatureRequest::OrderByClause> &orderBys )
268 if (
this != &other )
@ Fids
Filter using feature IDs.
@ Expression
Filter using expression.
@ DistanceWithin
Filter by distance to reference geometry.
@ BoundingBox
Filter using a bounding box.
@ NoFilter
No spatial filtering of features.
@ Forward
Forward transform (from source to destination).
@ Reverse
Reverse/inverse transform (from destination to source).
RequestToSourceCrsResult
Possible results from the updateRequestToSourceCrs() method.
@ Success
Request was successfully updated to the source CRS, or no changes were required.
@ DistanceWithinMustBeCheckedManually
The distance within request cannot be losslessly updated to the source CRS, and callers will need to ...
bool mZombie
A feature iterator may be closed already but still be serving features from the cache.
virtual bool nextFeatureFilterFids(QgsFeature &f)
By default, the iterator will fetch all features and check if the id is in the request.
void geometryToDestinationCrs(QgsFeature &feature, const QgsCoordinateTransform &transform) const
Transforms feature's geometry according to the specified coordinate transform.
QgsRectangle filterRectToSourceCrs(const QgsCoordinateTransform &transform) const
Returns a rectangle representing the original request's QgsFeatureRequest::filterRect().
virtual void setInterruptionChecker(QgsFeedback *interruptionChecker)
Attach an object that can be queried regularly by the iterator to check if it must stopped.
virtual bool fetchFeature(QgsFeature &f)=0
If you write a feature iterator for your provider, this is the method you need to implement!
long long mFetchedCount
Number of features already fetched by iterator.
virtual bool prepareSimplification(const QgsSimplifyMethod &simplifyMethod)
Setup the simplification of geometries to fetch using the specified simplify method.
void deref()
Remove reference, delete if refs == 0.
QgsFeatureRequest mRequest
A copy of the feature request.
QgsAbstractFeatureIterator(const QgsFeatureRequest &request)
base class constructor - stores the iteration parameters
RequestToSourceCrsResult updateRequestToSourceCrs(QgsFeatureRequest &request, const QgsCoordinateTransform &transform) const
Update a QgsFeatureRequest so that spatial filters are transformed to the source's coordinate referen...
bool compileFailed() const
Indicator if there was an error when sending the compiled query to the server.
int refs
reference counting (to allow seamless copying of QgsFeatureIterator instances)
virtual bool nextFeature(QgsFeature &f)
Fetch next feature and stores in f, returns true on success.
virtual bool nextFeatureFilterExpression(QgsFeature &f)
By default, the iterator will fetch all features and check if the feature matches the expression.
Custom exception class for Coordinate Reference System related exceptions.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
QgsAbstractFeatureIterator * mIter
QgsFeatureIterator & operator=(const QgsFeatureIterator &other)
bool isValid() const
Will return if this iterator is valid.
QgsFeatureIterator()=default
Construct invalid iterator.
Wraps a request for features to a vector layer (or directly its vector data provider).
QgsRectangle filterRect() const
Returns the rectangle from which features will be taken.
QgsExpressionContext * expressionContext()
Returns the expression context used to evaluate filter expressions.
Qgis::SpatialFilterType spatialFilterType() const
Returns the spatial filter type which is currently set on this request.
QgsFeatureRequest & setFilterRect(const QgsRectangle &rectangle)
Sets the rectangle from which features will be taken.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
void clearGeometry()
Removes any geometry associated with the feature.
bool hasGeometry() const
Returns true if the feature has an associated geometry.
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
Base class for feedback objects to be used for cancellation of something running in a worker thread.
A geometry is the spatial representation of a feature.
Qgis::GeometryOperationResult transform(const QgsCoordinateTransform &ct, Qgis::TransformDirection direction=Qgis::TransformDirection::Forward, bool transformZ=false)
Transforms this geometry as described by the coordinate transform ct.
QVector< QVariant > mIndexes
A rectangle specified with double values.
Contains information about how to simplify geometries fetched from a QgsFeatureIterator.
#define BUILTIN_UNREACHABLE