QGIS API Documentation  3.18.1-Zürich (202f1bf7e5)
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  QgsExpressionContext *expressionContext();
42 
43  private:
44  QgsFields mFields;
45  QgsFeatureMap mFeatures;
46  std::unique_ptr< QgsSpatialIndex > mSpatialIndex;
47  QString mSubsetString;
48  std::unique_ptr< QgsExpressionContext > mExpressionContext;
50 
51  friend class QgsMemoryFeatureIterator;
52 };
53 
54 
55 class QgsMemoryFeatureIterator final: public QgsAbstractFeatureIteratorFromSource<QgsMemoryFeatureSource>
56 {
57  public:
58  QgsMemoryFeatureIterator( QgsMemoryFeatureSource *source, bool ownSource, const QgsFeatureRequest &request );
59 
60  ~QgsMemoryFeatureIterator() override;
61 
62  bool rewind() override;
63  bool close() override;
64 
65  protected:
66 
67  bool fetchFeature( QgsFeature &feature ) override;
68 
69  private:
70  bool nextFeatureUsingList( QgsFeature &feature );
71  bool nextFeatureTraverseAll( QgsFeature &feature );
72 
73  QgsGeometry mSelectRectGeom;
74  std::unique_ptr< QgsGeometryEngine > mSelectRectEngine;
75  QgsRectangle mFilterRect;
76  QgsFeatureMap::const_iterator mSelectIterator;
77  bool mUsingFeatureIdList = false;
78  QList<QgsFeatureId> mFeatureIdList;
79  QList<QgsFeatureId>::const_iterator mFeatureIdListIterator;
80  std::unique_ptr< QgsExpression > mSubsetExpression;
81  QgsCoordinateTransform mTransform;
82 
83 };
84 
86 
87 #endif // QGSMEMORYFEATUREITERATOR_H
Helper template that cares of two things: 1.
virtual bool rewind()=0
reset 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
end of iterating: free the resources / lock
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.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
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).
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:56
Container of fields for a vector layer.
Definition: qgsfields.h:45
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:124
A rectangle specified with double values.
Definition: qgsrectangle.h:42
A spatial index for QgsFeature objects.
QMap< QgsFeatureId, QgsFeature > QgsFeatureMap