Skip to content

Commit 1f3ff11

Browse files
authored
Merge pull request #4486 from rldhont/server-wfs-refactoring
[Server] little WFS refactoring
2 parents b342acc + 5664d3d commit 1f3ff11

File tree

5 files changed

+87
-70
lines changed

5 files changed

+87
-70
lines changed

src/server/qgsserverprojectutils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ QStringList QgsServerProjectUtils::wfsLayerIds( const QgsProject &project )
154154
return project.readListEntry( QStringLiteral( "WFSLayers" ), QStringLiteral( "/" ) );
155155
}
156156

157-
int QgsServerProjectUtils::wfsLayerPrecision( const QString &layerId, const QgsProject &project )
157+
int QgsServerProjectUtils::wfsLayerPrecision( const QgsProject &project, const QString &layerId )
158158
{
159159
return project.readNumEntry( QStringLiteral( "WFSLayersPrecision" ), "/" + layerId, 6 );
160160
}

src/server/qgsserverprojectutils.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,13 @@ namespace QgsServerProjectUtils
185185
*/
186186
SERVER_EXPORT QStringList wfsLayerIds( const QgsProject &project );
187187

188-
SERVER_EXPORT int wfsLayerPrecision( const QString &layerId, const QgsProject &project );
188+
/** Returns the Layer precision defined in a QGIS project for the WFS GetFeature.
189+
* @param project the QGIS project
190+
* @param layerId the layer id in the project
191+
* @return the layer precision for WFS GetFeature.
192+
*/
193+
194+
SERVER_EXPORT int wfsLayerPrecision( const QgsProject &project, const QString &layerId );
189195

190196
/** Returns the Layer ids list defined in a QGIS project as published as WFS-T with update capabilities.
191197
* @param project the QGIS project

src/server/services/wfs/qgswfsgetcapabilities.cpp

Lines changed: 72 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -68,79 +68,17 @@ namespace QgsWfs
6868
wfsCapabilitiesElement.setAttribute( QStringLiteral( "updateSequence" ), QStringLiteral( "0" ) );
6969
doc.appendChild( wfsCapabilitiesElement );
7070

71-
//configParser->serviceCapabilities( wfsCapabilitiesElement, doc );
72-
//INSERT Service
71+
//wfs:Service
7372
wfsCapabilitiesElement.appendChild( getServiceElement( doc, project ) );
7473

75-
//wfs:Capability element
76-
QDomElement capabilityElement = doc.createElement( QStringLiteral( "Capability" )/*wfs:Capability*/ );
77-
wfsCapabilitiesElement.appendChild( capabilityElement );
78-
79-
//wfs:Request element
80-
QDomElement requestElement = doc.createElement( QStringLiteral( "Request" )/*wfs:Request*/ );
81-
capabilityElement.appendChild( requestElement );
82-
//wfs:GetCapabilities
83-
QDomElement getCapabilitiesElement = doc.createElement( QStringLiteral( "GetCapabilities" )/*wfs:GetCapabilities*/ );
84-
requestElement.appendChild( getCapabilitiesElement );
85-
86-
QDomElement dcpTypeElement = doc.createElement( QStringLiteral( "DCPType" )/*wfs:DCPType*/ );
87-
getCapabilitiesElement.appendChild( dcpTypeElement );
88-
QDomElement httpElement = doc.createElement( QStringLiteral( "HTTP" )/*wfs:HTTP*/ );
89-
dcpTypeElement.appendChild( httpElement );
90-
91-
//Prepare url
92-
QString hrefString = serviceUrl( request, project );
93-
94-
//only Get supported for the moment
95-
QDomElement getElement = doc.createElement( QStringLiteral( "Get" )/*wfs:Get*/ );
96-
httpElement.appendChild( getElement );
97-
getElement.setAttribute( QStringLiteral( "onlineResource" ), hrefString );
98-
QDomElement getCapabilitiesDhcTypePostElement = dcpTypeElement.cloneNode().toElement();//this is the same as for 'GetCapabilities'
99-
getCapabilitiesDhcTypePostElement.firstChild().firstChild().toElement().setTagName( QStringLiteral( "Post" ) );
100-
getCapabilitiesElement.appendChild( getCapabilitiesDhcTypePostElement );
101-
102-
//wfs:DescribeFeatureType
103-
QDomElement describeFeatureTypeElement = doc.createElement( QStringLiteral( "DescribeFeatureType" )/*wfs:DescribeFeatureType*/ );
104-
requestElement.appendChild( describeFeatureTypeElement );
105-
QDomElement schemaDescriptionLanguageElement = doc.createElement( QStringLiteral( "SchemaDescriptionLanguage" )/*wfs:SchemaDescriptionLanguage*/ );
106-
describeFeatureTypeElement.appendChild( schemaDescriptionLanguageElement );
107-
QDomElement xmlSchemaElement = doc.createElement( QStringLiteral( "XMLSCHEMA" )/*wfs:XMLSCHEMA*/ );
108-
schemaDescriptionLanguageElement.appendChild( xmlSchemaElement );
109-
QDomElement describeFeatureTypeDhcTypeElement = dcpTypeElement.cloneNode().toElement();//this is the same as for 'GetCapabilities'
110-
describeFeatureTypeElement.appendChild( describeFeatureTypeDhcTypeElement );
111-
QDomElement describeFeatureTypeDhcTypePostElement = dcpTypeElement.cloneNode().toElement();//this is the same as for 'GetCapabilities'
112-
describeFeatureTypeDhcTypePostElement.firstChild().firstChild().toElement().setTagName( QStringLiteral( "Post" ) );
113-
describeFeatureTypeElement.appendChild( describeFeatureTypeDhcTypePostElement );
114-
115-
//wfs:GetFeature
116-
QDomElement getFeatureElement = doc.createElement( QStringLiteral( "GetFeature" )/*wfs:GetFeature*/ );
117-
requestElement.appendChild( getFeatureElement );
118-
QDomElement getFeatureFormatElement = doc.createElement( QStringLiteral( "ResultFormat" ) );/*wfs:ResultFormat*/
119-
getFeatureElement.appendChild( getFeatureFormatElement );
120-
QDomElement gmlFormatElement = doc.createElement( QStringLiteral( "GML2" ) );/*wfs:GML2*/
121-
getFeatureFormatElement.appendChild( gmlFormatElement );
122-
QDomElement gml3FormatElement = doc.createElement( QStringLiteral( "GML3" ) );/*wfs:GML3*/
123-
getFeatureFormatElement.appendChild( gml3FormatElement );
124-
QDomElement geojsonFormatElement = doc.createElement( QStringLiteral( "GeoJSON" ) );/*wfs:GeoJSON*/
125-
getFeatureFormatElement.appendChild( geojsonFormatElement );
126-
QDomElement getFeatureDhcTypeGetElement = dcpTypeElement.cloneNode().toElement();//this is the same as for 'GetCapabilities'
127-
getFeatureElement.appendChild( getFeatureDhcTypeGetElement );
128-
QDomElement getFeatureDhcTypePostElement = dcpTypeElement.cloneNode().toElement();//this is the same as for 'GetCapabilities'
129-
getFeatureDhcTypePostElement.firstChild().firstChild().toElement().setTagName( QStringLiteral( "Post" ) );
130-
getFeatureElement.appendChild( getFeatureDhcTypePostElement );
131-
132-
//wfs:Transaction
133-
QDomElement transactionElement = doc.createElement( QStringLiteral( "Transaction" )/*wfs:Transaction*/ );
134-
requestElement.appendChild( transactionElement );
135-
QDomElement transactionDhcTypeElement = dcpTypeElement.cloneNode().toElement();//this is the same as for 'GetCapabilities'
136-
transactionDhcTypeElement.firstChild().firstChild().toElement().setTagName( QStringLiteral( "Post" ) );
137-
transactionElement.appendChild( transactionDhcTypeElement );
74+
//wfs:Capability
75+
wfsCapabilitiesElement.appendChild( getCapabilityElement( doc, project, request ) );
13876

13977
//wfs:FeatureTypeList
14078
wfsCapabilitiesElement.appendChild( getFeatureTypeListElement( doc, serverIface, project ) );
14179

14280
/*
143-
* Adding ogc:Filter_Capabilities in capabilityElement
81+
* Adding ogc:Filter_Capabilities in wfsCapabilitiesElement
14482
*/
14583
//ogc:Filter_Capabilities element
14684
QDomElement filterCapabilitiesElement = doc.createElement( QStringLiteral( "ogc:Filter_Capabilities" )/*ogc:Filter_Capabilities*/ );
@@ -238,6 +176,74 @@ namespace QgsWfs
238176

239177
}
240178

179+
QDomElement getCapabilityElement( QDomDocument &doc, const QgsProject *project, const QgsServerRequest &request )
180+
{
181+
//wfs:Capability element
182+
QDomElement capabilityElement = doc.createElement( QStringLiteral( "Capability" )/*wfs:Capability*/ );
183+
184+
//wfs:Request element
185+
QDomElement requestElement = doc.createElement( QStringLiteral( "Request" )/*wfs:Request*/ );
186+
capabilityElement.appendChild( requestElement );
187+
//wfs:GetCapabilities
188+
QDomElement getCapabilitiesElement = doc.createElement( QStringLiteral( "GetCapabilities" )/*wfs:GetCapabilities*/ );
189+
requestElement.appendChild( getCapabilitiesElement );
190+
191+
QDomElement dcpTypeElement = doc.createElement( QStringLiteral( "DCPType" )/*wfs:DCPType*/ );
192+
getCapabilitiesElement.appendChild( dcpTypeElement );
193+
QDomElement httpElement = doc.createElement( QStringLiteral( "HTTP" )/*wfs:HTTP*/ );
194+
dcpTypeElement.appendChild( httpElement );
195+
196+
//Prepare url
197+
QString hrefString = serviceUrl( request, project );
198+
199+
//only Get supported for the moment
200+
QDomElement getElement = doc.createElement( QStringLiteral( "Get" )/*wfs:Get*/ );
201+
httpElement.appendChild( getElement );
202+
getElement.setAttribute( QStringLiteral( "onlineResource" ), hrefString );
203+
QDomElement getCapabilitiesDhcTypePostElement = dcpTypeElement.cloneNode().toElement();//this is the same as for 'GetCapabilities'
204+
getCapabilitiesDhcTypePostElement.firstChild().firstChild().toElement().setTagName( QStringLiteral( "Post" ) );
205+
getCapabilitiesElement.appendChild( getCapabilitiesDhcTypePostElement );
206+
207+
//wfs:DescribeFeatureType
208+
QDomElement describeFeatureTypeElement = doc.createElement( QStringLiteral( "DescribeFeatureType" )/*wfs:DescribeFeatureType*/ );
209+
requestElement.appendChild( describeFeatureTypeElement );
210+
QDomElement schemaDescriptionLanguageElement = doc.createElement( QStringLiteral( "SchemaDescriptionLanguage" )/*wfs:SchemaDescriptionLanguage*/ );
211+
describeFeatureTypeElement.appendChild( schemaDescriptionLanguageElement );
212+
QDomElement xmlSchemaElement = doc.createElement( QStringLiteral( "XMLSCHEMA" )/*wfs:XMLSCHEMA*/ );
213+
schemaDescriptionLanguageElement.appendChild( xmlSchemaElement );
214+
QDomElement describeFeatureTypeDhcTypeElement = dcpTypeElement.cloneNode().toElement();//this is the same as for 'GetCapabilities'
215+
describeFeatureTypeElement.appendChild( describeFeatureTypeDhcTypeElement );
216+
QDomElement describeFeatureTypeDhcTypePostElement = dcpTypeElement.cloneNode().toElement();//this is the same as for 'GetCapabilities'
217+
describeFeatureTypeDhcTypePostElement.firstChild().firstChild().toElement().setTagName( QStringLiteral( "Post" ) );
218+
describeFeatureTypeElement.appendChild( describeFeatureTypeDhcTypePostElement );
219+
220+
//wfs:GetFeature
221+
QDomElement getFeatureElement = doc.createElement( QStringLiteral( "GetFeature" )/*wfs:GetFeature*/ );
222+
requestElement.appendChild( getFeatureElement );
223+
QDomElement getFeatureFormatElement = doc.createElement( QStringLiteral( "ResultFormat" ) );/*wfs:ResultFormat*/
224+
getFeatureElement.appendChild( getFeatureFormatElement );
225+
QDomElement gmlFormatElement = doc.createElement( QStringLiteral( "GML2" ) );/*wfs:GML2*/
226+
getFeatureFormatElement.appendChild( gmlFormatElement );
227+
QDomElement gml3FormatElement = doc.createElement( QStringLiteral( "GML3" ) );/*wfs:GML3*/
228+
getFeatureFormatElement.appendChild( gml3FormatElement );
229+
QDomElement geojsonFormatElement = doc.createElement( QStringLiteral( "GeoJSON" ) );/*wfs:GeoJSON*/
230+
getFeatureFormatElement.appendChild( geojsonFormatElement );
231+
QDomElement getFeatureDhcTypeGetElement = dcpTypeElement.cloneNode().toElement();//this is the same as for 'GetCapabilities'
232+
getFeatureElement.appendChild( getFeatureDhcTypeGetElement );
233+
QDomElement getFeatureDhcTypePostElement = dcpTypeElement.cloneNode().toElement();//this is the same as for 'GetCapabilities'
234+
getFeatureDhcTypePostElement.firstChild().firstChild().toElement().setTagName( QStringLiteral( "Post" ) );
235+
getFeatureElement.appendChild( getFeatureDhcTypePostElement );
236+
237+
//wfs:Transaction
238+
QDomElement transactionElement = doc.createElement( QStringLiteral( "Transaction" )/*wfs:Transaction*/ );
239+
requestElement.appendChild( transactionElement );
240+
QDomElement transactionDhcTypeElement = dcpTypeElement.cloneNode().toElement();//this is the same as for 'GetCapabilities'
241+
transactionDhcTypeElement.firstChild().firstChild().toElement().setTagName( QStringLiteral( "Post" ) );
242+
transactionElement.appendChild( transactionDhcTypeElement );
243+
244+
return capabilityElement;
245+
}
246+
241247
QDomElement getFeatureTypeListElement( QDomDocument &doc, QgsServerInterface *serverIface, const QgsProject *project )
242248
{
243249
QgsAccessControl *accessControl = serverIface->accessControls();

src/server/services/wfs/qgswfsgetcapabilities.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ namespace QgsWfs
3232
*/
3333
QDomElement getFeatureTypeListElement( QDomDocument &doc, QgsServerInterface *serverIface, const QgsProject *project );
3434

35+
/**
36+
* Create Capability element for get capabilities document
37+
*/
38+
QDomElement getCapabilityElement( QDomDocument &doc, const QgsProject *project, const QgsServerRequest &request );
39+
3540
/**
3641
* Create Service element for get capabilities document
3742
*/

src/server/services/wfs/qgswfsgetfeature.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ namespace QgsWfs
282282

283283
if ( onlyOneLayer )
284284
{
285-
requestPrecision = QgsServerProjectUtils::wfsLayerPrecision( vlayer->id(), *project );
285+
requestPrecision = QgsServerProjectUtils::wfsLayerPrecision( *project, vlayer->id() );
286286
}
287287

288288
if ( onlyOneLayer && !featureRequest.filterRect().isEmpty() )
@@ -295,7 +295,7 @@ namespace QgsWfs
295295
featureRequest.setLimit( aRequest.maxFeatures + aRequest.startIndex - sentFeatures );
296296
}
297297
// specific layer precision
298-
int layerPrecision = QgsServerProjectUtils::wfsLayerPrecision( vlayer->id(), *project );
298+
int layerPrecision = QgsServerProjectUtils::wfsLayerPrecision( *project, vlayer->id() );
299299
// specific layer crs
300300
QgsCoordinateReferenceSystem layerCrs = vlayer->crs();
301301
//excluded attributes for this layer

0 commit comments

Comments
 (0)