QGIS API Documentation 4.3.0-Master (e0370aa57ef)
Loading...
Searching...
No Matches
qgsvectorlayerfeatureiterator.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsvectorlayerfeatureiterator.h
3 ---------------------
4 begin : Dezember 2012
5 copyright : (C) 2012 by Martin Dobias
6 email : wonder dot sk at gmail dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15#ifndef QGSVECTORLAYERFEATUREITERATOR_H
16#define QGSVECTORLAYERFEATUREITERATOR_H
17
18#include <memory>
19
20#include "qgis_core.h"
21#include "qgis_sip.h"
25#include "qgsfeatureiterator.h"
26#include "qgsfeaturesource.h"
27#include "qgsfields.h"
28
29#include <QPointer>
30#include <QSet>
31
32typedef QMap<QgsFeatureId, QgsFeature> QgsFeatureMap SIP_SKIP;
33
35class QgsVectorLayer;
41
43
44#ifdef SIP_RUN
45// clang-format off
46% ModuleHeaderCode
47#include "qgsfeatureiterator.h"
49% End
50// clang-format on
51#endif
52
58{
59 public:
64 explicit QgsVectorLayerFeatureSource( const QgsVectorLayer *layer );
65
68
70
72
74
80 QgsFields fields() const;
81
86
92 QString id() const;
93
94 protected:
95 std::unique_ptr< QgsAbstractFeatureSource > mProviderFeatureSource;
96
97 std::unique_ptr< QgsVectorLayerJoinBuffer > mJoinBuffer;
98
99#ifndef SIP_RUN
100
108 {
112 std::shared_ptr< QgsVectorLayerFeatureSource > joinSource;
113
118 };
119
121 QMap< QString, JoinLayerSource > mJoinSources;
122#endif
123
124 std::unique_ptr< QgsExpressionFieldBuffer > mExpressionFieldBuffer;
125
127
128 QString mId;
129
131
133
134 // A deep-copy is only performed, if the original maps change
135 // see here https://github.com/qgis/Quantum-GIS/pull/673
136 // for explanation
140 QList<QgsField> mAddedAttributes;
143
145 QString mEllipsoid;
149 std::unique_ptr<QgsExpressionContextScope> mProjectScope;
150
151 private:
152#ifdef SIP_RUN
154#endif
155};
156
161class CORE_EXPORT QgsVectorLayerFeatureIterator : public QgsAbstractFeatureIteratorFromSource<QgsVectorLayerFeatureSource>
162{
163 public:
164 QgsVectorLayerFeatureIterator( QgsVectorLayerFeatureSource *source, bool ownSource, const QgsFeatureRequest &request );
165
167
169 bool rewind() override;
170
172 bool close() override;
173
174 void setInterruptionChecker( QgsFeedback *interruptionChecker ) override SIP_SKIP;
175
180 struct CORE_EXPORT FetchJoinInfo
181 {
190
191#ifndef SIP_RUN
192
199 std::shared_ptr< QgsVectorLayerFeatureSource > joinSource;
200
208#endif
209
212
215
216 void addJoinedAttributesCached( QgsFeature &f, const QVariant &joinValue ) const;
217 void addJoinedAttributesDirect( QgsFeature &f, const QVariant &joinValue ) const;
218 };
219
220 bool isValid() const override;
221
222 protected:
224 bool fetchFeature( QgsFeature &feature ) override;
225
230 bool nextFeatureFilterExpression( QgsFeature &f ) override { return fetchFeature( f ); }
231
233 bool prepareSimplification( const QgsSimplifyMethod &simplifyMethod ) override;
234
236 void rewindEditBuffer() SIP_SKIP;
237
239 void prepareJoin( int fieldIdx ) SIP_SKIP;
240
242 void prepareExpression( int fieldIdx ) SIP_SKIP;
243
245 void prepareFields() SIP_SKIP;
246
248 void prepareField( int fieldIdx ) SIP_SKIP;
249
251 bool fetchNextAddedFeature( QgsFeature &f ) SIP_SKIP;
253 bool fetchNextChangedGeomFeature( QgsFeature &f ) SIP_SKIP;
255 bool fetchNextChangedAttributeFeature( QgsFeature &f ) SIP_SKIP;
257 void useAddedFeature( const QgsFeature &src, QgsFeature &f ) SIP_SKIP;
259 void useChangedAttributeFeature( QgsFeatureId fid, const QgsGeometry &geom, QgsFeature &f ) SIP_SKIP;
261 bool nextFeatureFid( QgsFeature &f ) SIP_SKIP;
263 void addJoinedAttributes( QgsFeature &f ) SIP_SKIP;
264
275 void addVirtualAttributes( QgsFeature &f ) SIP_SKIP;
276
283 void addExpressionAttribute( QgsFeature &f, int attrIndex ) SIP_SKIP;
284
289 void updateChangedAttributes( QgsFeature &f ) SIP_SKIP;
290
295 void updateFeatureGeometry( QgsFeature &f ) SIP_SKIP;
296
301
302 // filter bounding box constraint, in SOURCE CRS
304 bool mHasValidTransform = false;
306
307 // distance within constraint reference geometry and distance IN DESTINATION CRS
310 double mDistanceWithin = 0;
311
312 // only related to editing
316
317 bool mFetchedFid = false; // when iterating by FID: indicator whether it has been fetched yet or not
318
324
326
328
329 private:
330#ifdef SIP_RUN
332#endif
333
334 void createExpressionContext();
335 std::unique_ptr<QgsExpressionContext> mExpressionContext;
336
337 QgsFeedback *mInterruptionChecker = nullptr;
338
339 QList< int > mPreparedFields;
340 QList< int > mFieldsToPrepare;
341
343 QList< FetchJoinInfo > mOrderedJoinInfoList;
344
349 bool prepareOrderBy( const QList<QgsFeatureRequest::OrderByClause> &orderBys ) override;
350
352 bool providerCanSimplify( QgsSimplifyMethod::MethodType methodType ) const override;
353
354 void createOrderedJoinList();
355
359 bool postProcessFeature( QgsFeature &feature );
360
364 bool checkGeometryValidity( const QgsFeature &feature );
365
366 bool mDelegatedOrderByToProvider = false;
367};
368
369
376{
377 public:
384
387
388 QgsFeatureIterator getFeatures( const QgsFeatureRequest &request = QgsFeatureRequest() ) const override;
390 QgsFields fields() const override;
391 Qgis::WkbType wkbType() const override;
392 long long featureCount() const override;
393 QString sourceName() const override;
396
397 private:
398#ifdef SIP_RUN
400#endif
401
402 // ideally this wouldn't be mutable, but QgsVectorLayerFeatureSource has non-const getFeatures()
403 mutable QgsVectorLayerFeatureSource mSource;
404 QgsFeatureIds mSelectedFeatureIds;
406 QString mName;
407 QPointer< QgsVectorLayer > mLayer;
408};
409
411
412#ifndef SIP_RUN
413class QgsVectorLayerSelectedFeatureIterator : public QgsAbstractFeatureIterator
414{
415 public:
416 QgsVectorLayerSelectedFeatureIterator( const QgsFeatureIds &selectedFeatureIds, const QgsFeatureRequest &request, QgsVectorLayerFeatureSource &source );
417
418 bool rewind() override;
419 bool close() override;
420
421 protected:
422 bool fetchFeature( QgsFeature &f ) override;
423
424 private:
425 QgsFeatureIds mSelectedFeatureIds;
426 QgsFeatureIterator mIterator;
427};
428
429#endif
430
432
433#endif // QGSVECTORLAYERFEATUREITERATOR_H
SpatialIndexPresence
Enumeration of spatial index presence states.
Definition qgis.h:619
DistanceUnit
Units of distance.
Definition qgis.h:5580
AreaUnit
Units of area.
Definition qgis.h:5657
WkbType
The WKB type describes the number of dimensions a geometry has.
Definition qgis.h:314
@ Unknown
Unknown.
Definition qgis.h:315
QgsAbstractFeatureIteratorFromSource(QgsVectorLayerFeatureSource *source, bool ownSource, const QgsFeatureRequest &request)
Internal feature iterator to be implemented within data providers.
virtual bool rewind()=0
Resets the iterator to the starting position.
virtual bool fetchFeature(QgsFeature &f)=0
If you write a feature iterator for your provider, this is the method you need to implement!
virtual bool close()=0
Call to end the iteration.
Base class that can be used for any class that is capable of returning features.
virtual QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest())=0
Gets an iterator for features matching the specified request.
Represents a coordinate reference system (CRS).
Contains information about the context in which a coordinate transform is executed.
Handles coordinate transforms between two coordinate systems.
Abstract interface for generating an expression context scope.
Single scope for storing variables and functions for use within a QgsExpressionContext.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Buffers information about expression fields for a vector layer.
Handles parsing and evaluation of expressions (formerly called "search strings").
Wrapper for iterator of features from vector data provider or vector layer.
Wraps a request for features to a vector layer (or directly its vector data provider).
An interface for objects which provide features via a getFeatures method.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition qgsfeature.h:60
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition qgsfeedback.h:44
Container of fields for a vector layer.
Definition qgsfields.h:45
A geometry engine is a low-level representation of a QgsAbstractGeometry object, optimised for use wi...
A geometry is the spatial representation of a feature.
A rectangle specified with double values.
Contains information about how to simplify geometries fetched from a QgsFeatureIterator.
Stores queued vector layer edit operations prior to committing changes to the layer's data provider.
A feature iterator which iterates over features from a QgsVectorLayer.
QMap< const QgsVectorLayerJoinInfo *, QgsVectorLayerFeatureIterator::FetchJoinInfo > mFetchJoinInfo
Information about joins used in the current select() statement.
QgsFeatureMap::ConstIterator mFetchAddedFeaturesIt
void setInterruptionChecker(QgsFeedback *interruptionChecker) override
Attach an object that can be queried regularly by the iterator to check if it must stopped.
bool close() override
end of iterating: free the resources / lock
bool nextFeatureFilterExpression(QgsFeature &f) override
Overrides default method as we only need to filter features in the edit buffer while for others filte...
QMap< int, QgsExpression * > mExpressionFieldInfo
QgsGeometryMap::ConstIterator mFetchChangedGeomIt
bool fetchFeature(QgsFeature &feature) override
fetch next feature, return true on success
std::shared_ptr< QgsGeometryEngine > mDistanceWithinEngine
bool isValid() const override
Returns if this iterator is valid.
bool rewind() override
reset the iterator to the starting position
QgsVectorLayerFeatureIterator(QgsVectorLayerFeatureSource *source, bool ownSource, const QgsFeatureRequest &request)
Partial snapshot of vector layer's state (only the members necessary for access to features).
QgsCoordinateReferenceSystem crs() const
Returns the coordinate reference system for features retrieved from this source.
QgsChangedAttributesMap mChangedAttributeValues
std::unique_ptr< QgsAbstractFeatureSource > mProviderFeatureSource
QgsVectorLayerFeatureSource(const QgsVectorLayer *layer)
Constructor for QgsVectorLayerFeatureSource.
~QgsVectorLayerFeatureSource() override
QString id() const
Returns the layer id of the source layer.
QgsCoordinateTransformContext mTransformContext
QgsFields fields() const
Returns the fields that will be available for features that are retrieved from this source.
std::unique_ptr< QgsExpressionContextScope > mProjectScope
QgsVectorLayerFeatureSource(const QgsVectorLayerFeatureSource &other)=delete
std::unique_ptr< QgsVectorLayerJoinBuffer > mJoinBuffer
std::unique_ptr< QgsExpressionFieldBuffer > mExpressionFieldBuffer
QMap< QString, JoinLayerSource > mJoinSources
Contains prepared join sources by layer ID.
QgsVectorLayerFeatureSource & operator==(const QgsVectorLayerFeatureSource &other)=delete
Manages joined fields for a vector layer.
Defines left outer join from our vector layer to some other vector layer.
QgsVectorLayerSelectedFeatureSource(const QgsVectorLayerSelectedFeatureSource &other)=delete
long long featureCount() const override
Returns the number of features contained in the source, or -1 if the feature count is unknown.
Qgis::WkbType wkbType() const override
Returns the geometry type for features returned by this source.
Qgis::SpatialIndexPresence hasSpatialIndex() const override
Returns an enum value representing the presence of a valid spatial index on the source,...
QgsFields fields() const override
Returns the fields associated with features in the source.
QgsCoordinateReferenceSystem sourceCrs() const override
Returns the coordinate reference system for features in the source.
QgsVectorLayerSelectedFeatureSource(QgsVectorLayer *layer)
Constructor for QgsVectorLayerSelectedFeatureSource, for selected features from the specified layer.
QgsVectorLayerSelectedFeatureSource & operator==(const QgsVectorLayerSelectedFeatureSource &other)=delete
QgsExpressionContextScope * createExpressionContextScope() const override
This method needs to be reimplemented in all classes which implement this interface and return an exp...
QString sourceName() const override
Returns a friendly display name for the source.
Represents a vector layer which manages a vector based dataset.
#define SIP_SKIP
Definition qgis_sip.h:138
QMap< QgsFeatureId, QgsGeometry > QgsGeometryMap
QMap< QgsFeatureId, QgsAttributeMap > QgsChangedAttributesMap
QSet< QgsFeatureId > QgsFeatureIds
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features
QList< int > QgsAttributeList
Definition qgsfield.h:30
QMap< QgsFeatureId, QgsFeature > QgsFeatureMap
QMap< QgsFeatureId, QgsFeature > QgsFeatureMap
Join information prepared for fast attribute id mapping in QgsVectorLayerJoinBuffer::updateFeatureAtt...
QMap< int, int > attributesSourceToDestLayerMap
Mapping from original attribute index to the joined layer index.
void addJoinedAttributesDirect(QgsFeature &f, const QVariant &joinValue) const
std::shared_ptr< QgsVectorLayerFeatureSource > joinSource
Feature source for join.
int targetField
Index of field (of this layer) that drives the join.
const QgsVectorLayerJoinInfo * joinInfo
Canonical source of information about the join.
int indexOffset
At what position the joined fields start.
void addJoinedAttributesCached(QgsFeature &f, const QVariant &joinValue) const
Contains join layer source information prepared in a thread-safe way, ready for vector layer feature ...
std::shared_ptr< QgsVectorLayerFeatureSource > joinSource
Feature source for join.