Skip to content

Commit

Permalink
[Server] little WFS refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
rldhont committed May 2, 2017
1 parent b342acc commit 5664d3d
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 70 deletions.
2 changes: 1 addition & 1 deletion src/server/qgsserverprojectutils.cpp
Expand Up @@ -154,7 +154,7 @@ QStringList QgsServerProjectUtils::wfsLayerIds( const QgsProject &project )
return project.readListEntry( QStringLiteral( "WFSLayers" ), QStringLiteral( "/" ) );
}

int QgsServerProjectUtils::wfsLayerPrecision( const QString &layerId, const QgsProject &project )
int QgsServerProjectUtils::wfsLayerPrecision( const QgsProject &project, const QString &layerId )
{
return project.readNumEntry( QStringLiteral( "WFSLayersPrecision" ), "/" + layerId, 6 );
}
Expand Down
8 changes: 7 additions & 1 deletion src/server/qgsserverprojectutils.h
Expand Up @@ -185,7 +185,13 @@ namespace QgsServerProjectUtils
*/
SERVER_EXPORT QStringList wfsLayerIds( const QgsProject &project );

SERVER_EXPORT int wfsLayerPrecision( const QString &layerId, const QgsProject &project );
/** Returns the Layer precision defined in a QGIS project for the WFS GetFeature.
* @param project the QGIS project
* @param layerId the layer id in the project
* @return the layer precision for WFS GetFeature.
*/

SERVER_EXPORT int wfsLayerPrecision( const QgsProject &project, const QString &layerId );

/** Returns the Layer ids list defined in a QGIS project as published as WFS-T with update capabilities.
* @param project the QGIS project
Expand Down
138 changes: 72 additions & 66 deletions src/server/services/wfs/qgswfsgetcapabilities.cpp
Expand Up @@ -68,79 +68,17 @@ namespace QgsWfs
wfsCapabilitiesElement.setAttribute( QStringLiteral( "updateSequence" ), QStringLiteral( "0" ) );
doc.appendChild( wfsCapabilitiesElement );

//configParser->serviceCapabilities( wfsCapabilitiesElement, doc );
//INSERT Service
//wfs:Service
wfsCapabilitiesElement.appendChild( getServiceElement( doc, project ) );

//wfs:Capability element
QDomElement capabilityElement = doc.createElement( QStringLiteral( "Capability" )/*wfs:Capability*/ );
wfsCapabilitiesElement.appendChild( capabilityElement );

//wfs:Request element
QDomElement requestElement = doc.createElement( QStringLiteral( "Request" )/*wfs:Request*/ );
capabilityElement.appendChild( requestElement );
//wfs:GetCapabilities
QDomElement getCapabilitiesElement = doc.createElement( QStringLiteral( "GetCapabilities" )/*wfs:GetCapabilities*/ );
requestElement.appendChild( getCapabilitiesElement );

QDomElement dcpTypeElement = doc.createElement( QStringLiteral( "DCPType" )/*wfs:DCPType*/ );
getCapabilitiesElement.appendChild( dcpTypeElement );
QDomElement httpElement = doc.createElement( QStringLiteral( "HTTP" )/*wfs:HTTP*/ );
dcpTypeElement.appendChild( httpElement );

//Prepare url
QString hrefString = serviceUrl( request, project );

//only Get supported for the moment
QDomElement getElement = doc.createElement( QStringLiteral( "Get" )/*wfs:Get*/ );
httpElement.appendChild( getElement );
getElement.setAttribute( QStringLiteral( "onlineResource" ), hrefString );
QDomElement getCapabilitiesDhcTypePostElement = dcpTypeElement.cloneNode().toElement();//this is the same as for 'GetCapabilities'
getCapabilitiesDhcTypePostElement.firstChild().firstChild().toElement().setTagName( QStringLiteral( "Post" ) );
getCapabilitiesElement.appendChild( getCapabilitiesDhcTypePostElement );

//wfs:DescribeFeatureType
QDomElement describeFeatureTypeElement = doc.createElement( QStringLiteral( "DescribeFeatureType" )/*wfs:DescribeFeatureType*/ );
requestElement.appendChild( describeFeatureTypeElement );
QDomElement schemaDescriptionLanguageElement = doc.createElement( QStringLiteral( "SchemaDescriptionLanguage" )/*wfs:SchemaDescriptionLanguage*/ );
describeFeatureTypeElement.appendChild( schemaDescriptionLanguageElement );
QDomElement xmlSchemaElement = doc.createElement( QStringLiteral( "XMLSCHEMA" )/*wfs:XMLSCHEMA*/ );
schemaDescriptionLanguageElement.appendChild( xmlSchemaElement );
QDomElement describeFeatureTypeDhcTypeElement = dcpTypeElement.cloneNode().toElement();//this is the same as for 'GetCapabilities'
describeFeatureTypeElement.appendChild( describeFeatureTypeDhcTypeElement );
QDomElement describeFeatureTypeDhcTypePostElement = dcpTypeElement.cloneNode().toElement();//this is the same as for 'GetCapabilities'
describeFeatureTypeDhcTypePostElement.firstChild().firstChild().toElement().setTagName( QStringLiteral( "Post" ) );
describeFeatureTypeElement.appendChild( describeFeatureTypeDhcTypePostElement );

//wfs:GetFeature
QDomElement getFeatureElement = doc.createElement( QStringLiteral( "GetFeature" )/*wfs:GetFeature*/ );
requestElement.appendChild( getFeatureElement );
QDomElement getFeatureFormatElement = doc.createElement( QStringLiteral( "ResultFormat" ) );/*wfs:ResultFormat*/
getFeatureElement.appendChild( getFeatureFormatElement );
QDomElement gmlFormatElement = doc.createElement( QStringLiteral( "GML2" ) );/*wfs:GML2*/
getFeatureFormatElement.appendChild( gmlFormatElement );
QDomElement gml3FormatElement = doc.createElement( QStringLiteral( "GML3" ) );/*wfs:GML3*/
getFeatureFormatElement.appendChild( gml3FormatElement );
QDomElement geojsonFormatElement = doc.createElement( QStringLiteral( "GeoJSON" ) );/*wfs:GeoJSON*/
getFeatureFormatElement.appendChild( geojsonFormatElement );
QDomElement getFeatureDhcTypeGetElement = dcpTypeElement.cloneNode().toElement();//this is the same as for 'GetCapabilities'
getFeatureElement.appendChild( getFeatureDhcTypeGetElement );
QDomElement getFeatureDhcTypePostElement = dcpTypeElement.cloneNode().toElement();//this is the same as for 'GetCapabilities'
getFeatureDhcTypePostElement.firstChild().firstChild().toElement().setTagName( QStringLiteral( "Post" ) );
getFeatureElement.appendChild( getFeatureDhcTypePostElement );

//wfs:Transaction
QDomElement transactionElement = doc.createElement( QStringLiteral( "Transaction" )/*wfs:Transaction*/ );
requestElement.appendChild( transactionElement );
QDomElement transactionDhcTypeElement = dcpTypeElement.cloneNode().toElement();//this is the same as for 'GetCapabilities'
transactionDhcTypeElement.firstChild().firstChild().toElement().setTagName( QStringLiteral( "Post" ) );
transactionElement.appendChild( transactionDhcTypeElement );
//wfs:Capability
wfsCapabilitiesElement.appendChild( getCapabilityElement( doc, project, request ) );

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

/*
* Adding ogc:Filter_Capabilities in capabilityElement
* Adding ogc:Filter_Capabilities in wfsCapabilitiesElement
*/
//ogc:Filter_Capabilities element
QDomElement filterCapabilitiesElement = doc.createElement( QStringLiteral( "ogc:Filter_Capabilities" )/*ogc:Filter_Capabilities*/ );
Expand Down Expand Up @@ -238,6 +176,74 @@ namespace QgsWfs

}

QDomElement getCapabilityElement( QDomDocument &doc, const QgsProject *project, const QgsServerRequest &request )
{
//wfs:Capability element
QDomElement capabilityElement = doc.createElement( QStringLiteral( "Capability" )/*wfs:Capability*/ );

//wfs:Request element
QDomElement requestElement = doc.createElement( QStringLiteral( "Request" )/*wfs:Request*/ );
capabilityElement.appendChild( requestElement );
//wfs:GetCapabilities
QDomElement getCapabilitiesElement = doc.createElement( QStringLiteral( "GetCapabilities" )/*wfs:GetCapabilities*/ );
requestElement.appendChild( getCapabilitiesElement );

QDomElement dcpTypeElement = doc.createElement( QStringLiteral( "DCPType" )/*wfs:DCPType*/ );
getCapabilitiesElement.appendChild( dcpTypeElement );
QDomElement httpElement = doc.createElement( QStringLiteral( "HTTP" )/*wfs:HTTP*/ );
dcpTypeElement.appendChild( httpElement );

//Prepare url
QString hrefString = serviceUrl( request, project );

//only Get supported for the moment
QDomElement getElement = doc.createElement( QStringLiteral( "Get" )/*wfs:Get*/ );
httpElement.appendChild( getElement );
getElement.setAttribute( QStringLiteral( "onlineResource" ), hrefString );
QDomElement getCapabilitiesDhcTypePostElement = dcpTypeElement.cloneNode().toElement();//this is the same as for 'GetCapabilities'
getCapabilitiesDhcTypePostElement.firstChild().firstChild().toElement().setTagName( QStringLiteral( "Post" ) );
getCapabilitiesElement.appendChild( getCapabilitiesDhcTypePostElement );

//wfs:DescribeFeatureType
QDomElement describeFeatureTypeElement = doc.createElement( QStringLiteral( "DescribeFeatureType" )/*wfs:DescribeFeatureType*/ );
requestElement.appendChild( describeFeatureTypeElement );
QDomElement schemaDescriptionLanguageElement = doc.createElement( QStringLiteral( "SchemaDescriptionLanguage" )/*wfs:SchemaDescriptionLanguage*/ );
describeFeatureTypeElement.appendChild( schemaDescriptionLanguageElement );
QDomElement xmlSchemaElement = doc.createElement( QStringLiteral( "XMLSCHEMA" )/*wfs:XMLSCHEMA*/ );
schemaDescriptionLanguageElement.appendChild( xmlSchemaElement );
QDomElement describeFeatureTypeDhcTypeElement = dcpTypeElement.cloneNode().toElement();//this is the same as for 'GetCapabilities'
describeFeatureTypeElement.appendChild( describeFeatureTypeDhcTypeElement );
QDomElement describeFeatureTypeDhcTypePostElement = dcpTypeElement.cloneNode().toElement();//this is the same as for 'GetCapabilities'
describeFeatureTypeDhcTypePostElement.firstChild().firstChild().toElement().setTagName( QStringLiteral( "Post" ) );
describeFeatureTypeElement.appendChild( describeFeatureTypeDhcTypePostElement );

//wfs:GetFeature
QDomElement getFeatureElement = doc.createElement( QStringLiteral( "GetFeature" )/*wfs:GetFeature*/ );
requestElement.appendChild( getFeatureElement );
QDomElement getFeatureFormatElement = doc.createElement( QStringLiteral( "ResultFormat" ) );/*wfs:ResultFormat*/
getFeatureElement.appendChild( getFeatureFormatElement );
QDomElement gmlFormatElement = doc.createElement( QStringLiteral( "GML2" ) );/*wfs:GML2*/
getFeatureFormatElement.appendChild( gmlFormatElement );
QDomElement gml3FormatElement = doc.createElement( QStringLiteral( "GML3" ) );/*wfs:GML3*/
getFeatureFormatElement.appendChild( gml3FormatElement );
QDomElement geojsonFormatElement = doc.createElement( QStringLiteral( "GeoJSON" ) );/*wfs:GeoJSON*/
getFeatureFormatElement.appendChild( geojsonFormatElement );
QDomElement getFeatureDhcTypeGetElement = dcpTypeElement.cloneNode().toElement();//this is the same as for 'GetCapabilities'
getFeatureElement.appendChild( getFeatureDhcTypeGetElement );
QDomElement getFeatureDhcTypePostElement = dcpTypeElement.cloneNode().toElement();//this is the same as for 'GetCapabilities'
getFeatureDhcTypePostElement.firstChild().firstChild().toElement().setTagName( QStringLiteral( "Post" ) );
getFeatureElement.appendChild( getFeatureDhcTypePostElement );

//wfs:Transaction
QDomElement transactionElement = doc.createElement( QStringLiteral( "Transaction" )/*wfs:Transaction*/ );
requestElement.appendChild( transactionElement );
QDomElement transactionDhcTypeElement = dcpTypeElement.cloneNode().toElement();//this is the same as for 'GetCapabilities'
transactionDhcTypeElement.firstChild().firstChild().toElement().setTagName( QStringLiteral( "Post" ) );
transactionElement.appendChild( transactionDhcTypeElement );

return capabilityElement;
}

QDomElement getFeatureTypeListElement( QDomDocument &doc, QgsServerInterface *serverIface, const QgsProject *project )
{
QgsAccessControl *accessControl = serverIface->accessControls();
Expand Down
5 changes: 5 additions & 0 deletions src/server/services/wfs/qgswfsgetcapabilities.h
Expand Up @@ -32,6 +32,11 @@ namespace QgsWfs
*/
QDomElement getFeatureTypeListElement( QDomDocument &doc, QgsServerInterface *serverIface, const QgsProject *project );

/**
* Create Capability element for get capabilities document
*/
QDomElement getCapabilityElement( QDomDocument &doc, const QgsProject *project, const QgsServerRequest &request );

/**
* Create Service element for get capabilities document
*/
Expand Down
4 changes: 2 additions & 2 deletions src/server/services/wfs/qgswfsgetfeature.cpp
Expand Up @@ -282,7 +282,7 @@ namespace QgsWfs

if ( onlyOneLayer )
{
requestPrecision = QgsServerProjectUtils::wfsLayerPrecision( vlayer->id(), *project );
requestPrecision = QgsServerProjectUtils::wfsLayerPrecision( *project, vlayer->id() );
}

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

0 comments on commit 5664d3d

Please sign in to comment.