-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqgswfsprovider.h
209 lines (160 loc) · 8.21 KB
/
qgswfsprovider.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/***************************************************************************
qgswfsprovider.h
-------------------
begin : July 25, 2006
copyright : (C) 2006 by Marco Hugentobler
(C) 2016 by Even Rouault
email : marco dot hugentobler at karto dot baug dot ethz dot ch
even.rouault at spatialys.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 QGSWFSPROVIDER_H
#define QGSWFSPROVIDER_H
#include "qgis.h"
#include "qgsrectangle.h"
#include "qgscoordinatereferencesystem.h"
#include "qgsvectordataprovider.h"
#include "qgswfscapabilities.h"
#include "qgswfsfeatureiterator.h"
#include "qgswfsdatasourceuri.h"
#include "qgsprovidermetadata.h"
class QgsRectangle;
class QgsWFSSharedData;
/**
* \ingroup WFSProvider
*
* A provider reading/write features from/into a WFS server.
*
* Below quick design notes on the whole provider.
*
* QgsWFSProvider class purpose:
* - in constructor, do a GetCapabilities request to determine server-side feature limit,
paging capabilities, WFS version, edition capabilities. Do a DescribeFeatureType request
to determine fields, geometry name and type.
* - in other methods, mostly WFS-T related operations.
*
* QgsWFSSharedData class purpose:
* - contains logic shared by QgsWFSProvider, QgsWFSFeatureIterator and QgsWFSFeatureDownloader.
* - one of its main function is to maintain a on-disk cache of the features retrieved
* from the server. This cache is a SpatiaLite database.
*
* QgsWFSRequest class purpose: abstract base class to create WFS network requests,
* such as QgsWFSCapabilities, QgsWFSDescribeFeatureType, QgsWFSFeatureDownloader,
* QgsWFSFeatureHitsAsyncRequest, QgsWFSFeatureHitsRequest, QgsWFSTransactionRequest
*
* QgsWFSDataSourceURI class purpose: wrapper above QgsDataSourceUri to get/set
* the specific attributes of a WFS URI.
*
*/
class QgsWFSProvider final: public QgsVectorDataProvider
{
Q_OBJECT
public:
static const QString WFS_PROVIDER_KEY;
static const QString WFS_PROVIDER_DESCRIPTION;
explicit QgsWFSProvider( const QString &uri, const QgsDataProvider::ProviderOptions &providerOptions, const QgsWfsCapabilities::Capabilities &caps = QgsWfsCapabilities::Capabilities() );
~QgsWFSProvider() override;
/* Inherited from QgsVectorDataProvider */
QgsAbstractFeatureSource *featureSource() const override;
QgsFeatureIterator getFeatures( const QgsFeatureRequest &request = QgsFeatureRequest() ) const override;
QgsWkbTypes::Type wkbType() const override;
long featureCount() const override;
QgsFields fields() const override;
QgsCoordinateReferenceSystem crs() const override;
QString subsetString() const override;
bool setSubsetString( const QString &theSQL, bool updateFeatureCount = true ) override;
bool supportsSubsetString() const override { return true; }
/* Inherited from QgsDataProvider */
QgsRectangle extent() const override;
bool isValid() const override;
QString name() const override;
QString description() const override;
QgsVectorDataProvider::Capabilities capabilities() const override;
QString storageType() const override { return QStringLiteral( "OGC WFS (Web Feature Service)" ); }
/* new functions */
QString geometryAttribute() const;
const QString processSQLErrorMsg() const { return mProcessSQLErrorMsg; }
const QString processSQLWarningMsg() const { return mProcessSQLWarningMsg; }
//Editing operations
bool addFeatures( QgsFeatureList &flist, QgsFeatureSink::Flags flags = nullptr ) override;
bool deleteFeatures( const QgsFeatureIds &id ) override;
bool changeGeometryValues( const QgsGeometryMap &geometry_map ) override;
bool changeAttributeValues( const QgsChangedAttributesMap &attr_map ) override;
QVariantMap metadata() const override;
QString translateMetadataKey( const QString &mdKey ) const override;
QString translateMetadataValue( const QString &mdKey, const QVariant &value ) const override;
bool empty() const override;
private slots:
void featureReceivedAnalyzeOneFeature( QVector<QgsFeatureUniqueIdPair> );
void pushErrorSlot( const QString &errorMsg );
private:
//! Mutable data shared between provider and feature sources
std::shared_ptr<QgsWFSSharedData> mShared;
/**
* Invalidates cache of shared object
*/
void reloadProviderData() override;
friend class QgsWFSFeatureSource;
protected:
//! String used to define a subset of the layer
QString mSubsetString;
//! Flag if provider is valid
bool mValid = true;
//! Namespace URL of the server (comes from DescribeFeatureDocument)
QString mApplicationNamespace;
//! Server capabilities for this layer (generated from capabilities document)
QgsVectorDataProvider::Capabilities mCapabilities = nullptr;
//! Fields of this typename. Might be different from mShared->mFields in case of SELECT
QgsFields mThisTypenameFields;
QString mProcessSQLErrorMsg;
QString mProcessSQLWarningMsg;
/**
* Collects information about the field types. Is called internally from QgsWFSProvider ctor.
The method gives back the name of
the geometry attribute and the thematic attributes with their types*/
bool describeFeatureType( QString &geometryAttribute,
QgsFields &fields, QgsWkbTypes::Type &geomType );
/**
* For a given typename, reads the name of the geometry attribute, the
thematic attributes and their types from a dom document. Returns true in case of success*/
bool readAttributesFromSchema( QDomDocument &schemaDoc,
const QString &prefixedTypename,
QString &geometryAttribute,
QgsFields &fields, QgsWkbTypes::Type &geomType, QString &errorMsg );
//helper methods for WFS-T
/**
* Sends the transaction document to the server using HTTP POST
\returns true if transmission to the server succeeded, otherwise false
note: true does not automatically mean that the transaction succeeded*/
bool sendTransactionDocument( const QDomDocument &doc, QDomDocument &serverResponse );
//! Creates a transaction element and adds it (normally as first element) to the document
QDomElement createTransactionElement( QDomDocument &doc ) const;
//! True if the server response means success
bool transactionSuccess( const QDomDocument &serverResponse ) const;
//! Returns the inserted ids
QStringList insertedFeatureIds( const QDomDocument &serverResponse ) const;
//! Retrieve version and capabilities for this layer from GetCapabilities document (will be stored in mCapabilities)
bool getCapabilities();
//! Records provider error
void handleException( const QDomDocument &serverResponse );
//! Converts DescribeFeatureType schema geometry property type to WKBType
QgsWkbTypes::Type geomTypeFromPropertyType( const QString &attName, const QString &propType );
//! Convert the value to its appropriate XML representation
QString convertToXML( const QVariant &value );
bool processSQL( const QString &sqlString, QString &errorMsg, QString &warningMsg );
};
class QgsWfsProviderMetadata final: public QgsProviderMetadata
{
public:
QgsWfsProviderMetadata();
QList<QgsDataItemProvider *> dataItemProviders() const override;
QgsWFSProvider *createProvider( const QString &uri, const QgsDataProvider::ProviderOptions &options ) override;
};
#endif /* QGSWFSPROVIDER_H */