QGIS API Documentation  3.14.0-Pi (9f7028fd23)
qgsmemoryfeatureiterator.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsmemoryfeatureiterator.h
3  ---------------------
4  begin : Juli 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 QGSMEMORYFEATUREITERATOR_H
16 #define QGSMEMORYFEATUREITERATOR_H
17 
18 #define SIP_NO_FILE
19 
20 #include "qgsfeatureiterator.h"
21 #include "qgsexpressioncontext.h"
22 #include "qgsfields.h"
23 #include "qgsgeometry.h"
24 
26 
27 class QgsMemoryProvider;
28 
29 typedef QMap<QgsFeatureId, QgsFeature> QgsFeatureMap;
30 
31 class QgsSpatialIndex;
32 
33 
34 class QgsMemoryFeatureSource final: public QgsAbstractFeatureSource
35 {
36  public:
37  explicit QgsMemoryFeatureSource( const QgsMemoryProvider *p );
38 
39  QgsFeatureIterator getFeatures( const QgsFeatureRequest &request ) override;
40 
41  private:
42  QgsFields mFields;
43  QgsFeatureMap mFeatures;
44  std::unique_ptr< QgsSpatialIndex > mSpatialIndex;
45  QString mSubsetString;
46  QgsExpressionContext mExpressionContext;
48 
49  friend class QgsMemoryFeatureIterator;
50 };
51 
52 
53 class QgsMemoryFeatureIterator final: public QgsAbstractFeatureIteratorFromSource<QgsMemoryFeatureSource>
54 {
55  public:
56  QgsMemoryFeatureIterator( QgsMemoryFeatureSource *source, bool ownSource, const QgsFeatureRequest &request );
57 
58  ~QgsMemoryFeatureIterator() override;
59 
60  bool rewind() override;
61  bool close() override;
62 
63  protected:
64 
65  bool fetchFeature( QgsFeature &feature ) override;
66 
67  private:
68  bool nextFeatureUsingList( QgsFeature &feature );
69  bool nextFeatureTraverseAll( QgsFeature &feature );
70 
71  QgsGeometry mSelectRectGeom;
72  std::unique_ptr< QgsGeometryEngine > mSelectRectEngine;
73  QgsRectangle mFilterRect;
74  QgsFeatureMap::const_iterator mSelectIterator;
75  bool mUsingFeatureIdList = false;
76  QList<QgsFeatureId> mFeatureIdList;
77  QList<QgsFeatureId>::const_iterator mFeatureIdListIterator;
78  std::unique_ptr< QgsExpression > mSubsetExpression;
79  QgsCoordinateTransform mTransform;
80 
81 };
82 
84 
85 #endif // QGSMEMORYFEATUREITERATOR_H
QgsExpressionContext
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Definition: qgsexpressioncontext.h:369
qgsfields.h
qgsfeatureiterator.h
QgsFields
Definition: qgsfields.h:44
QgsRectangle
Definition: qgsrectangle.h:41
QgsAbstractFeatureIteratorFromSource
Definition: qgsfeatureiterator.h:233
QgsFeatureRequest
Definition: qgsfeaturerequest.h:75
qgsexpressioncontext.h
QgsAbstractFeatureSource
Definition: qgsfeaturerequest.h:742
QgsSpatialIndex
Definition: qgsspatialindex.h:67
QgsFeatureMap
QMap< QgsFeatureId, QgsFeature > QgsFeatureMap
Definition: qgsvectorlayereditbuffer.h:30
QgsAbstractFeatureIterator::rewind
virtual bool rewind()=0
reset the iterator to the starting position
QgsCoordinateReferenceSystem
Definition: qgscoordinatereferencesystem.h:206
qgsgeometry.h
QgsGeometry
Definition: qgsgeometry.h:122
QgsAbstractFeatureIterator::fetchFeature
virtual bool fetchFeature(QgsFeature &f)=0
If you write a feature iterator for your provider, this is the method you need to implement!...
QgsAbstractFeatureSource::getFeatures
virtual QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest())=0
Gets an iterator for features matching the specified request.
QgsFeature
Definition: qgsfeature.h:55
QgsCoordinateTransform
Definition: qgscoordinatetransform.h:52
QgsFeatureIterator
Definition: qgsfeatureiterator.h:263
QgsAbstractFeatureIterator::close
virtual bool close()=0
end of iterating: free the resources / lock