/
qgsogrfeatureiterator.h
95 lines (72 loc) · 2.99 KB
/
qgsogrfeatureiterator.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/***************************************************************************
qgsogrfeatureiterator.h
---------------------
begin : Juli 2012
copyright : (C) 2012 by Martin Dobias
email : wonder dot sk at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef QGSOGRFEATUREITERATOR_H
#define QGSOGRFEATUREITERATOR_H
#include "qgsfeatureiterator.h"
#include "qgsogrconnpool.h"
#include <ogr_api.h>
class QgsOgrFeatureIterator;
class QgsOgrProvider;
class QgsOgrFeatureSource : public QgsAbstractFeatureSource
{
public:
explicit QgsOgrFeatureSource( const QgsOgrProvider* p );
~QgsOgrFeatureSource();
virtual QgsFeatureIterator getFeatures( const QgsFeatureRequest& request ) override;
protected:
const QgsOgrProvider* mProvider;
QString mDataSource;
QString mLayerName;
int mLayerIndex;
QString mSubsetString;
QTextCodec* mEncoding;
QgsFields mFields;
bool mFirstFieldIsFid;
QgsFields mFieldsWithoutFid;
OGRwkbGeometryType mOgrGeometryTypeFilter;
QString mDriverName;
friend class QgsOgrFeatureIterator;
friend class QgsOgrExpressionCompiler;
};
class QgsOgrFeatureIterator : public QgsAbstractFeatureIteratorFromSource<QgsOgrFeatureSource>
{
public:
QgsOgrFeatureIterator( QgsOgrFeatureSource* source, bool ownSource, const QgsFeatureRequest& request );
~QgsOgrFeatureIterator();
//! reset the iterator to the starting position
virtual bool rewind() override;
//! end of iterating: free the resources / lock
virtual bool close() override;
protected:
//! fetch next feature, return true on success
virtual bool fetchFeature( QgsFeature& feature ) override;
//! fetch next feature filter expression
bool nextFeatureFilterExpression( QgsFeature& f ) override;
bool readFeature( OGRFeatureH fet, QgsFeature& feature ) const;
//! Get an attribute associated with a feature
void getFeatureAttribute( OGRFeatureH ogrFet, QgsFeature & f, int attindex ) const;
bool mFeatureFetched;
QgsOgrConn* mConn;
OGRLayerH ogrLayer;
bool mSubsetStringSet;
//! Set to true, if geometry is in the requested columns
bool mFetchGeometry;
private:
bool mExpressionCompiled;
QgsFeatureIds mFilterFids;
QgsFeatureIds::const_iterator mFilterFidsIt;
bool fetchFeatureWithId( QgsFeatureId id, QgsFeature& feature ) const;
};
#endif // QGSOGRFEATUREITERATOR_H