QGIS API Documentation  3.6.0-Noosa (5873452)
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 : 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 : 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
Wrapper for iterator of features from vector data provider or vector layer.
A rectangle specified with double values.
Definition: qgsrectangle.h:41
virtual QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest())=0
Gets an iterator for features matching the specified request.
Container of fields for a vector layer.
Definition: qgsfields.h:42
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:106
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:55
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
This class wraps a request for features to a vector layer (or directly its vector data provider)...
Base class that can be used for any class that is capable of returning features.
QMap< QgsFeatureId, QgsFeature > QgsFeatureMap
A spatial index for QgsFeature objects.
This class represents a coordinate reference system (CRS).
Class for doing transforms between two map coordinate systems.
Helper template that cares of two things: 1.