/
qgsdelimitedtextfeatureiterator.h
103 lines (85 loc) · 3.56 KB
/
qgsdelimitedtextfeatureiterator.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
96
97
98
99
100
101
102
103
/***************************************************************************
qgsdelimitedtextfeatureiterator.h
---------------------
begin : Oktober 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 QGSDELIMITEDTEXTFEATUREITERATOR_H
#define QGSDELIMITEDTEXTFEATUREITERATOR_H
#include <QList>
#include "qgsfeatureiterator.h"
#include "qgsfeature.h"
#include "qgsexpressioncontext.h"
#include "qgsdelimitedtextprovider.h"
class QgsDelimitedTextFeatureSource : public QgsAbstractFeatureSource
{
public:
explicit QgsDelimitedTextFeatureSource( const QgsDelimitedTextProvider *p );
~QgsDelimitedTextFeatureSource();
virtual QgsFeatureIterator getFeatures( const QgsFeatureRequest &request ) override;
private:
QgsDelimitedTextProvider::GeomRepresentationType mGeomRep;
std::unique_ptr< QgsExpression > mSubsetExpression;
QgsExpressionContext mExpressionContext;
QgsRectangle mExtent;
bool mUseSpatialIndex;
std::unique_ptr< QgsSpatialIndex > mSpatialIndex;
bool mUseSubsetIndex;
QList<quintptr> mSubsetIndex;
std::unique_ptr< QgsDelimitedTextFile > mFile;
QgsFields mFields;
int mFieldCount; // Note: this includes field count for wkt field
int mXFieldIndex;
int mYFieldIndex;
int mWktFieldIndex;
bool mWktHasPrefix;
QgsWkbTypes::GeometryType mGeometryType;
QString mDecimalPoint;
bool mXyDms;
QList<int> attributeColumns;
QgsCoordinateReferenceSystem mCrs;
friend class QgsDelimitedTextFeatureIterator;
};
class QgsDelimitedTextFeatureIterator : public QgsAbstractFeatureIteratorFromSource<QgsDelimitedTextFeatureSource>
{
enum IteratorMode
{
FileScan,
SubsetIndex,
FeatureIds
};
public:
QgsDelimitedTextFeatureIterator( QgsDelimitedTextFeatureSource *source, bool ownSource, const QgsFeatureRequest &request );
~QgsDelimitedTextFeatureIterator();
virtual bool rewind() override;
virtual bool close() override;
// Tests whether the geometry is required, given that testGeometry is true.
bool wantGeometry( const QgsPointXY &point ) const;
bool wantGeometry( const QgsGeometry &geom ) const;
protected:
virtual bool fetchFeature( QgsFeature &feature ) override;
private:
bool setNextFeatureId( qint64 fid );
bool nextFeatureInternal( QgsFeature &feature );
QgsGeometry loadGeometryWkt( const QStringList &tokens, bool &isNull );
QgsGeometry loadGeometryXY( const QStringList &tokens, bool &isNull );
void fetchAttribute( QgsFeature &feature, int fieldIdx, const QStringList &tokens );
QList<QgsFeatureId> mFeatureIds;
IteratorMode mMode = FileScan;
long mNextId = 0;
bool mTestSubset = false;
bool mTestGeometry = false;
bool mTestGeometryExact = false;
bool mLoadGeometry = false;
QgsRectangle mFilterRect;
QgsCoordinateTransform mTransform;
};
#endif // QGSDELIMITEDTEXTFEATUREITERATOR_H