QGIS API Documentation 3.39.0-Master (3aed037ce22)
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 "qgis_core.h"
19#include "qgis_sip.h"
20#include "qgsfeatureiterator.h"
21#include "qgsfields.h"
23#include "qgsfeaturesource.h"
26
27#include <QPointer>
28#include <QSet>
29#include <memory>
30
31typedef QMap<QgsFeatureId, QgsFeature> QgsFeatureMap SIP_SKIP;
32
34class QgsVectorLayer;
39
41
42#ifdef SIP_RUN
43% ModuleHeaderCode
44#include "qgsfeatureiterator.h"
45% End
46#endif
47
53{
54 public:
55
60 explicit QgsVectorLayerFeatureSource( const QgsVectorLayer *layer );
61
64
66
68
70
76 QgsFields fields() const;
77
82
88 QString id() const;
89
90 protected:
91
92 std::unique_ptr< QgsAbstractFeatureSource > mProviderFeatureSource;
93
94 std::unique_ptr< QgsVectorLayerJoinBuffer > mJoinBuffer;
95
96#ifndef SIP_RUN
97
105 {
106
110 std::shared_ptr< QgsVectorLayerFeatureSource > joinSource;
111
116 };
117
119 QMap< QString, JoinLayerSource > mJoinSources;
120#endif
121
122 std::unique_ptr< QgsExpressionFieldBuffer > mExpressionFieldBuffer;
123
125
126 QString mId;
127
129
131
132 // A deep-copy is only performed, if the original maps change
133 // see here https://github.com/qgis/Quantum-GIS/pull/673
134 // for explanation
138 QList<QgsField> mAddedAttributes;
141
143
144 private:
145#ifdef SIP_RUN
147#endif
148};
149
153class CORE_EXPORT QgsVectorLayerFeatureIterator : public QgsAbstractFeatureIteratorFromSource<QgsVectorLayerFeatureSource>
154{
155 public:
156 QgsVectorLayerFeatureIterator( QgsVectorLayerFeatureSource *source, bool ownSource, const QgsFeatureRequest &request );
157
159
161 bool rewind() override;
162
164 bool close() override;
165
166 void setInterruptionChecker( QgsFeedback *interruptionChecker ) override SIP_SKIP;
167
172 struct CORE_EXPORT FetchJoinInfo
173 {
179 QMap<int, int> attributesSourceToDestLayerMap SIP_SKIP;
182
183#ifndef SIP_RUN
184
191 std::shared_ptr< QgsVectorLayerFeatureSource > joinSource;
192
200#endif
201
204
207
208 void addJoinedAttributesCached( QgsFeature &f, const QVariant &joinValue ) const;
209 void addJoinedAttributesDirect( QgsFeature &f, const QVariant &joinValue ) const;
210 };
211
212 bool isValid() const override;
213
214 protected:
216 bool fetchFeature( QgsFeature &feature ) override;
217
222 bool nextFeatureFilterExpression( QgsFeature &f ) override { return fetchFeature( f ); }
223
225 bool prepareSimplification( const QgsSimplifyMethod &simplifyMethod ) override;
226
228 void rewindEditBuffer() SIP_SKIP;
229
231 void prepareJoin( int fieldIdx ) SIP_SKIP;
232
234 void prepareExpression( int fieldIdx ) SIP_SKIP;
235
237 void prepareFields() SIP_SKIP;
238
240 void prepareField( int fieldIdx ) SIP_SKIP;
241
243 bool fetchNextAddedFeature( QgsFeature &f ) SIP_SKIP;
245 bool fetchNextChangedGeomFeature( QgsFeature &f ) SIP_SKIP;
247 bool fetchNextChangedAttributeFeature( QgsFeature &f ) SIP_SKIP;
249 void useAddedFeature( const QgsFeature &src, QgsFeature &f ) SIP_SKIP;
251 void useChangedAttributeFeature( QgsFeatureId fid, const QgsGeometry &geom, QgsFeature &f ) SIP_SKIP;
253 bool nextFeatureFid( QgsFeature &f ) SIP_SKIP;
255 void addJoinedAttributes( QgsFeature &f ) SIP_SKIP;
256
267 void addVirtualAttributes( QgsFeature &f ) SIP_SKIP;
268
275 void addExpressionAttribute( QgsFeature &f, int attrIndex ) SIP_SKIP;
276
281 void updateChangedAttributes( QgsFeature &f ) SIP_SKIP;
282
287 void updateFeatureGeometry( QgsFeature &f ) SIP_SKIP;
288
289 QgsFeatureRequest mProviderRequest;
290 QgsFeatureIterator mProviderIterator;
291 QgsFeatureRequest mChangedFeaturesRequest;
292 QgsFeatureIterator mChangedFeaturesIterator;
293
294 // filter bounding box constraint, in SOURCE CRS
295 QgsRectangle mFilterRect;
296 bool mHasValidTransform = false;
298
299 // distance within constraint reference geometry and distance IN DESTINATION CRS
300 QgsGeometry mDistanceWithinGeom;
301 std::shared_ptr< QgsGeometryEngine > mDistanceWithinEngine;
302 double mDistanceWithin = 0;
303
304 // only related to editing
305 QSet<QgsFeatureId> mFetchConsidered;
306 QgsGeometryMap::ConstIterator mFetchChangedGeomIt;
307 QgsFeatureMap::ConstIterator mFetchAddedFeaturesIt;
308
309 bool mFetchedFid; // when iterating by FID: indicator whether it has been fetched yet or not
310
316
317 QMap<int, QgsExpression *> mExpressionFieldInfo;
318
319 bool mHasVirtualAttributes;
320
321 private:
322#ifdef SIP_RUN
324#endif
325
326 void createExpressionContext();
327 std::unique_ptr<QgsExpressionContext> mExpressionContext;
328
329 QgsFeedback *mInterruptionChecker = nullptr;
330
331 QList< int > mPreparedFields;
332 QList< int > mFieldsToPrepare;
333
335 QList< FetchJoinInfo > mOrderedJoinInfoList;
336
341 bool prepareOrderBy( const QList<QgsFeatureRequest::OrderByClause> &orderBys ) override;
342
344 bool providerCanSimplify( QgsSimplifyMethod::MethodType methodType ) const override;
345
346 void createOrderedJoinList();
347
351 bool postProcessFeature( QgsFeature &feature );
352
356 bool checkGeometryValidity( const QgsFeature &feature );
357
358 bool mDelegatedOrderByToProvider = false;
359};
360
361
362
369{
370 public:
371
378
381
382 QgsFeatureIterator getFeatures( const QgsFeatureRequest &request = QgsFeatureRequest() ) const override;
383 QgsCoordinateReferenceSystem sourceCrs() const override;
384 QgsFields fields() const override;
385 Qgis::WkbType wkbType() const override;
386 long long featureCount() const override;
387 QString sourceName() const override;
388 QgsExpressionContextScope *createExpressionContextScope() const override;
389 Qgis::SpatialIndexPresence hasSpatialIndex() const override;
390
391 private:
392
393#ifdef SIP_RUN
395#endif
396
397 // ideally this wouldn't be mutable, but QgsVectorLayerFeatureSource has non-const getFeatures()
398 mutable QgsVectorLayerFeatureSource mSource;
399 QgsFeatureIds mSelectedFeatureIds;
401 QString mName;
402 QPointer< QgsVectorLayer > mLayer;
403
404};
405
407
408#ifndef SIP_RUN
409class QgsVectorLayerSelectedFeatureIterator : public QgsAbstractFeatureIterator
410{
411 public:
412
413 QgsVectorLayerSelectedFeatureIterator( const QgsFeatureIds &selectedFeatureIds,
414 const QgsFeatureRequest &request,
416
417 bool rewind() override;
418 bool close() override;
419
420 protected:
421 bool fetchFeature( QgsFeature &f ) override;
422
423 private:
424 QgsFeatureIds mSelectedFeatureIds;
425 QgsFeatureIterator mIterator;
426
427};
428
429#endif
430
432
433#endif // QGSVECTORLAYERFEATUREITERATOR_H
SpatialIndexPresence
Enumeration of spatial index presence states.
Definition qgis.h:448
WkbType
The WKB type describes the number of dimensions a geometry has.
Definition qgis.h:201
@ Unknown
Unknown.
Helper template that cares of two things: 1.
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.
This class represents a coordinate reference system (CRS).
Class for doing transforms between two map 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.
Class for parsing and evaluation of expressions (formerly called "search strings").
Wrapper for iterator of features from vector data provider or vector layer.
This class 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:58
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:46
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.
This class contains information about how to simplify geometries fetched from a QgsFeatureIterator.
bool nextFeatureFilterExpression(QgsFeature &f) override
Overrides default method as we only need to filter features in the edit buffer while for others filte...
Partial snapshot of vector layer's state (only the members necessary for access to features)
QgsChangedAttributesMap mChangedAttributeValues
std::unique_ptr< QgsAbstractFeatureSource > mProviderFeatureSource
~QgsVectorLayerFeatureSource() override
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.
QgsFeatureSource subclass for the selected features from a QgsVectorLayer.
QgsVectorLayerSelectedFeatureSource(const QgsVectorLayerSelectedFeatureSource &other)=delete
QgsVectorLayerSelectedFeatureSource & operator==(const QgsVectorLayerSelectedFeatureSource &other)=delete
Represents a vector layer which manages a vector based data sets.
#define SIP_SKIP
Definition qgis_sip.h:126
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:27
QMap< QgsFeatureId, QgsFeature > QgsFeatureMap
QMap< QgsFeatureId, QgsFeature > QgsFeatureMap
const QgsCoordinateReferenceSystem & crs
Join information prepared for fast attribute id mapping in QgsVectorLayerJoinBuffer::updateFeatureAtt...
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.
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.