Skip to content

Commit

Permalink
Merge pull request #1857 from rldhont/server_wms_sld_describe_layer
Browse files Browse the repository at this point in the history
[SERVER][FEATURE] Add DescribeLayer Method to WMS
  • Loading branch information
mhugent committed Jan 23, 2015
2 parents 743f72d + 5c89fdf commit 1c71799
Show file tree
Hide file tree
Showing 10 changed files with 301 additions and 17 deletions.
99 changes: 99 additions & 0 deletions src/server/qgsserverprojectparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,48 @@ QString QgsServerProjectParser::serviceUrl() const
return url;
}

QString QgsServerProjectParser::wfsServiceUrl() const
{
QString url;

if ( !mXMLDoc )
{
return url;
}

QDomElement propertiesElement = propertiesElem();
if ( !propertiesElement.isNull() )
{
QDomElement wfsUrlElem = propertiesElement.firstChildElement( "WFSUrl" );
if ( !wfsUrlElem.isNull() )
{
url = wfsUrlElem.text();
}
}
return url;
}

QString QgsServerProjectParser::wcsServiceUrl() const
{
QString url;

if ( !mXMLDoc )
{
return url;
}

QDomElement propertiesElement = propertiesElem();
if ( !propertiesElement.isNull() )
{
QDomElement wcsUrlElem = propertiesElement.firstChildElement( "WCSUrl" );
if ( !wcsUrlElem.isNull() )
{
url = wcsUrlElem.text();
}
}
return url;
}

void QgsServerProjectParser::combineExtentAndCrsOfGroupChildren( QDomElement& groupElem, QDomDocument& doc, bool considerMapExtent ) const
{
QgsRectangle combinedBBox;
Expand Down Expand Up @@ -1139,6 +1181,32 @@ QStringList QgsServerProjectParser::wfsLayerNames() const
return layerNameList;
}

QStringList QgsServerProjectParser::wcsLayerNames() const
{
QStringList layerNameList;

QMap<QString, QgsMapLayer*> layerMap;
projectLayerMap( layerMap );

QgsMapLayer* currentLayer = 0;
QStringList wcsIdList = wcsLayers();
QStringList::const_iterator wcsIdIt = wcsIdList.constBegin();
for ( ; wcsIdIt != wcsIdList.constEnd(); ++wcsIdIt )
{
QMap<QString, QgsMapLayer*>::const_iterator layerMapIt = layerMap.find( *wcsIdIt );
if ( layerMapIt != layerMap.constEnd() )
{
currentLayer = layerMapIt.value();
if ( currentLayer )
{
layerNameList.append( mUseLayerIDs ? currentLayer->id() : currentLayer->name() );
}
}
}

return layerNameList;
}

QDomElement QgsServerProjectParser::firstComposerLegendElement() const
{
if ( !mXMLDoc )
Expand Down Expand Up @@ -1267,6 +1335,37 @@ QStringList QgsServerProjectParser::wfsLayers() const
return wfsList;
}

QStringList QgsServerProjectParser::wcsLayers() const
{
QStringList wcsList;
if ( !mXMLDoc )
{
return wcsList;
}

QDomElement qgisElem = mXMLDoc->documentElement();
if ( qgisElem.isNull() )
{
return wcsList;
}
QDomElement propertiesElem = qgisElem.firstChildElement( "properties" );
if ( propertiesElem.isNull() )
{
return wcsList;
}
QDomElement wcsLayersElem = propertiesElem.firstChildElement( "WCSLayers" );
if ( wcsLayersElem.isNull() )
{
return wcsList;
}
QDomNodeList valueList = wcsLayersElem.elementsByTagName( "value" );
for ( int i = 0; i < valueList.size(); ++i )
{
wcsList << valueList.at( i ).toElement().text();
}
return wcsList;
}

void QgsServerProjectParser::addJoinLayersForElement( const QDomElement& layerElem, bool useCache ) const
{
QDomElement vectorJoinsElem = layerElem.firstChildElement( "vectorjoins" );
Expand Down
4 changes: 4 additions & 0 deletions src/server/qgsserverprojectparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ class QgsServerProjectParser
void layerFromLegendLayer( const QDomElement& legendLayerElem, QMap< int, QgsMapLayer*>& layers, bool useCache = true ) const;

QStringList wfsLayerNames() const;
QStringList wcsLayerNames() const;

QDomElement firstComposerLegendElement() const;

Expand All @@ -103,8 +104,11 @@ class QgsServerProjectParser
QString layerName( const QDomElement& layerElem ) const;

QString serviceUrl() const;
QString wfsServiceUrl() const;
QString wcsServiceUrl() const;

QStringList wfsLayers() const;
QStringList wcsLayers() const;

void addJoinLayersForElement( const QDomElement& layerElem, bool useCache = true ) const;

Expand Down
9 changes: 9 additions & 0 deletions src/server/qgssldconfigparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,15 @@ QDomDocument QgsSLDConfigParser::getStyles( QStringList& layerList ) const
return styleDoc;
}

QDomDocument QgsSLDConfigParser::describeLayer( QStringList& layerList, const QString& hrefString ) const
{
if ( mFallbackParser )
{
return mFallbackParser->describeLayer( layerList, hrefString );
}
return QDomDocument();
}

QgsMapRenderer::OutputUnits QgsSLDConfigParser::outputUnits() const
{
return mOutputUnits;
Expand Down
3 changes: 3 additions & 0 deletions src/server/qgssldconfigparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ class QgsSLDConfigParser : public QgsWMSConfigParser

/**Returns the xml fragment of layers styles*/
QDomDocument getStyles( QStringList& layerList ) const override;

/**Returns the xml fragment of layers styles description*/
QDomDocument describeLayer( QStringList& layerList, const QString& hrefString ) const override;

/**Returns if output are MM or PIXEL*/
QgsMapRenderer::OutputUnits outputUnits() const override;
Expand Down
18 changes: 1 addition & 17 deletions src/server/qgswfsprojectparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,7 @@ QString QgsWFSProjectParser::serviceUrl() const

QString QgsWFSProjectParser::wfsServiceUrl() const
{
QString url;

if ( !mProjectParser->xmlDocument() )
{
return url;
}

QDomElement propertiesElem = mProjectParser->propertiesElem();
if ( !propertiesElem.isNull() )
{
QDomElement wfsUrlElem = propertiesElem.firstChildElement( "WFSUrl" );
if ( !wfsUrlElem.isNull() )
{
url = wfsUrlElem.text();
}
}
return url;
return mProjectParser->wfsServiceUrl();
}

void QgsWFSProjectParser::featureTypeList( QDomElement& parentElement, QDomDocument& doc ) const
Expand Down
3 changes: 3 additions & 0 deletions src/server/qgswmsconfigparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ class QgsWMSConfigParser

/**Returns the xml fragment of layers styles*/
virtual QDomDocument getStyles( QStringList& layerList ) const = 0;

/**Returns the xml fragment of layers styles description*/
virtual QDomDocument describeLayer( QStringList& layerList, const QString& hrefString ) const = 0;

/**Returns if output are MM or PIXEL*/
virtual QgsMapRenderer::OutputUnits outputUnits() const = 0;
Expand Down
102 changes: 102 additions & 0 deletions src/server/qgswmsprojectparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1674,6 +1674,108 @@ QDomDocument QgsWMSProjectParser::getStyles( QStringList& layerList ) const
return myDocument;
}

QDomDocument QgsWMSProjectParser::describeLayer( QStringList& layerList, const QString& hrefString ) const
{
QDomDocument myDocument = QDomDocument();

QDomNode header = myDocument.createProcessingInstruction( "xml", "version=\"1.0\" encoding=\"UTF-8\"" );
myDocument.appendChild( header );

// Create the root element
QDomElement root = myDocument.createElementNS( "http://www.opengis.net/sld", "DescribeLayerResponse" );
root.setAttribute( "xsi:schemaLocation", "http://www.opengis.net/sld http://schemas.opengis.net/sld/1.1.0/DescribeLayer.xsd" );
root.setAttribute( "xmlns:ows", "http://www.opengis.net/ows" );
root.setAttribute( "xmlns:se", "http://www.opengis.net/se" );
root.setAttribute( "xmlns:xlink", "http://www.w3.org/1999/xlink" );
root.setAttribute( "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance" );
myDocument.appendChild( root );

// store the Version element
QDomElement versionNode = myDocument.createElement( "Version" );
versionNode.appendChild( myDocument.createTextNode( "1.1.0" ) );
root.appendChild( versionNode );

//Prepare url
QString wfsHrefString = mProjectParser->wfsServiceUrl();
if ( wfsHrefString.isEmpty() )
{
wfsHrefString = hrefString;
}
QString wcsHrefString = mProjectParser->wcsServiceUrl();
if ( wcsHrefString.isEmpty() )
{
wcsHrefString = hrefString;
}

//WFS layers
QStringList wfsLayers = wfsLayerNames();
//WCS layers
QStringList wcsLayers = mProjectParser->wcsLayerNames();

for ( int i = 0; i < layerList.size(); i++ )
{
QString layerName;
layerName = layerList.at( i );
// don't use a cache - we may be changing styles
QList<QgsMapLayer*> currentLayerList = mapLayerFromStyle( layerName, "", false );
if ( currentLayerList.size() < 1 )
{
throw QgsMapServiceException( "InvalidParameterValue", QString( "The layer '%1' is not found" ).arg( layerName ) );
}
for ( int j = 0; j < currentLayerList.size(); j++ )
{
QgsMapLayer* currentLayer = currentLayerList.at( j );
QString layerTypeName = mProjectParser->useLayerIDs() ? currentLayer->id() : currentLayer->name();

// Create the NamedLayer element
QDomElement layerNode = myDocument.createElement( "LayerDescription" );
root.appendChild( layerNode );

// store the owsType element
QDomElement typeNode = myDocument.createElement( "owsType" );
// store the se:OnlineResource element
QDomElement oResNode = myDocument.createElement( "se:OnlineResource" );
oResNode.setAttribute( "xlink:type", "simple" );
// store the TypeName element
QDomElement nameNode = myDocument.createElement( "TypeName" );
if ( currentLayer->type() == QgsMapLayer::VectorLayer )
{
typeNode.appendChild( myDocument.createTextNode( "wfs" ) );

if ( wfsLayers.indexOf( layerTypeName ) != -1 )
{
oResNode.setAttribute( "xlink:href", wfsHrefString );
}

// store the se:FeatureTypeName element
QDomElement typeNameNode = myDocument.createElement( "se:FeatureTypeName" );
typeNameNode.appendChild( myDocument.createTextNode( layerTypeName ) );
nameNode.appendChild( typeNameNode );
}
else if ( currentLayer->type() == QgsMapLayer::RasterLayer )
{
typeNode.appendChild( myDocument.createTextNode( "wcs" ) );

if ( wcsLayers.indexOf( layerTypeName ) != -1 )
{
oResNode.setAttribute( "xlink:href", wcsHrefString );
}

// store the se:CoverageTypeName element
QDomElement typeNameNode = myDocument.createElement( "se:CoverageTypeName" );
typeNameNode.appendChild( myDocument.createTextNode( layerTypeName ) );
nameNode.appendChild( typeNameNode );
}
layerNode.appendChild( typeNode );
layerNode.appendChild( oResNode );
layerNode.appendChild( nameNode );

}
}

return myDocument;
}

QgsMapRenderer::OutputUnits QgsWMSProjectParser::outputUnits() const
{
return QgsMapRenderer::Millimeters;
Expand Down
3 changes: 3 additions & 0 deletions src/server/qgswmsprojectparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ class QgsWMSProjectParser : public QgsWMSConfigParser
/**Returns the xml fragment of layers styles*/
QDomDocument getStyles( QStringList& layerList ) const override;

/**Returns the xml fragment of layers styles description*/
QDomDocument describeLayer( QStringList& layerList, const QString& hrefString ) const override;

/**Returns if output are MM or PIXEL*/
QgsMapRenderer::OutputUnits outputUnits() const override;

Expand Down
Loading

0 comments on commit 1c71799

Please sign in to comment.