Skip to content

Commit 88768c7

Browse files
committed
Implement bag of properties for SIA2045 feature info output
1 parent 73a5cc9 commit 88768c7

File tree

2 files changed

+124
-64
lines changed

2 files changed

+124
-64
lines changed

src/mapserver/qgswmsserver.cpp

Lines changed: 121 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -766,6 +766,8 @@ int QgsWMSServer::getFeatureInfo( QDomDocument& result, QString version )
766766

767767
//layers can have assigned a different name for GetCapabilities
768768
QHash<QString, QString> layerAliasMap = mConfigParser->featureInfoLayerAliasMap();
769+
//collect layer name / maplayer for potential later modifications of the xml
770+
QMap< QString, QgsMapLayer* > layerNameMap;
769771

770772
QList<QgsMapLayer*> layerList;
771773
QgsMapLayer* currentLayer = 0;
@@ -805,6 +807,7 @@ int QgsWMSServer::getFeatureInfo( QDomDocument& result, QString version )
805807
}
806808
layerElement.setAttribute( "name", layerName );
807809
getFeatureInfoElement.appendChild( layerElement );
810+
layerNameMap.insert( layerName, currentLayer );
808811

809812
//switch depending on vector or raster
810813
QgsVectorLayer* vectorLayer = dynamic_cast<QgsVectorLayer*>( currentLayer );
@@ -848,71 +851,8 @@ int QgsWMSServer::getFeatureInfo( QDomDocument& result, QString version )
848851
if ( mConfigParser->featureInfoFormatSIA2045()
849852
&& mParameterMap.value( "INFO_FORMAT" ).compare( "text/xml", Qt::CaseInsensitive ) == 0 )
850853
{
851-
//infoFormat = "text/xml; format=sia2045";
852-
QDomDocument outFeatureInfoDoc;
853-
QDomElement infoDocElement = result.documentElement();
854-
QDomElement outInfoDocElement = outFeatureInfoDoc.importNode( infoDocElement, false ).toElement();
855-
outFeatureInfoDoc.appendChild( outInfoDocElement );
856-
857-
QString currentAttributeName;
858-
QString currentAttributeValue;
859-
QDomElement currentAttributeElem;
860-
QString currentLayerName;
861-
QDomElement currentLayerElem;
862-
QDomNodeList layerNodeList = infoDocElement.elementsByTagName( "Layer" );
863-
for ( int i = 0; i < layerNodeList.size(); ++i )
864-
{
865-
currentLayerElem = layerNodeList.at( i ).toElement();
866-
currentLayerName = currentLayerElem.attribute( "name" );
867-
QDomElement currentFeatureElem;
868854

869-
QDomNodeList featureList = currentLayerElem.elementsByTagName( "Feature" );
870-
if ( featureList.size() < 1 )
871-
{
872-
//raster?
873-
QDomNodeList attributeList = currentLayerElem.elementsByTagName( "Attribute" );
874-
QDomElement rasterLayerElem;
875-
if ( attributeList.size() > 0 )
876-
{
877-
rasterLayerElem = outFeatureInfoDoc.createElement( currentLayerName );
878-
}
879-
for ( int j = 0; j < attributeList.size(); ++j )
880-
{
881-
currentAttributeElem = attributeList.at( j ).toElement();
882-
currentAttributeName = currentAttributeElem.attribute( "name" );
883-
currentAttributeValue = currentAttributeElem.attribute( "value" );
884-
QDomElement outAttributeElem = outFeatureInfoDoc.createElement( currentAttributeName );
885-
QDomText outAttributeText = outFeatureInfoDoc.createTextNode( currentAttributeValue );
886-
outAttributeElem.appendChild( outAttributeText );
887-
rasterLayerElem.appendChild( outAttributeElem );
888-
}
889-
if ( attributeList.size() > 0 )
890-
{
891-
outInfoDocElement.appendChild( rasterLayerElem );
892-
}
893-
}
894-
else //vector
895-
{
896-
for ( int j = 0; j < featureList.size(); ++j )
897-
{
898-
QDomElement outFeatureElem = outFeatureInfoDoc.createElement( currentLayerName );
899-
currentFeatureElem = featureList.at( j ).toElement();
900-
QDomNodeList attributeList = currentFeatureElem.elementsByTagName( "Attribute" );
901-
for ( int k = 0; k < attributeList.size(); ++k )
902-
{
903-
currentAttributeElem = attributeList.at( k ).toElement();
904-
currentAttributeName = currentAttributeElem.attribute( "name" );
905-
currentAttributeValue = currentAttributeElem.attribute( "value" );
906-
QDomElement outAttributeElem = outFeatureInfoDoc.createElement( currentAttributeName );
907-
QDomText outAttributeText = outFeatureInfoDoc.createTextNode( currentAttributeValue );
908-
outAttributeElem.appendChild( outAttributeText );
909-
outFeatureElem.appendChild( outAttributeElem );
910-
}
911-
outInfoDocElement.appendChild( outFeatureElem );
912-
}
913-
}
914-
}
915-
result = outFeatureInfoDoc;
855+
convertFeatureInfoToSIA2045( result, layerNameMap );
916856
}
917857

918858
restoreLayerFilters( originalLayerFilters );
@@ -2128,3 +2068,120 @@ void QgsWMSServer::addXMLDeclaration( QDomDocument& doc ) const
21282068
QDomProcessingInstruction xmlDeclaration = doc.createProcessingInstruction( "xml", "version=\"1.0\"" );
21292069
doc.appendChild( xmlDeclaration );
21302070
}
2071+
2072+
void QgsWMSServer::convertFeatureInfoToSIA2045( QDomDocument& doc, const QMap< QString, QgsMapLayer* >& layerNameMap )
2073+
{
2074+
QDomDocument SIAInfoDoc;
2075+
QDomElement infoDocElement = doc.documentElement();
2076+
QDomElement SIAInfoDocElement = SIAInfoDoc.importNode( infoDocElement, false ).toElement();
2077+
SIAInfoDoc.appendChild( SIAInfoDocElement );
2078+
2079+
QString currentAttributeName;
2080+
QString currentAttributeValue;
2081+
QDomElement currentAttributeElem;
2082+
QString currentLayerName;
2083+
QDomElement currentLayerElem;
2084+
QDomNodeList layerNodeList = infoDocElement.elementsByTagName( "Layer" );
2085+
for ( int i = 0; i < layerNodeList.size(); ++i )
2086+
{
2087+
currentLayerElem = layerNodeList.at( i ).toElement();
2088+
currentLayerName = currentLayerElem.attribute( "name" );
2089+
2090+
QDomElement currentFeatureElem;
2091+
2092+
QDomNodeList featureList = currentLayerElem.elementsByTagName( "Feature" );
2093+
if ( featureList.size() < 1 )
2094+
{
2095+
//raster?
2096+
QDomNodeList attributeList = currentLayerElem.elementsByTagName( "Attribute" );
2097+
QDomElement rasterLayerElem;
2098+
if ( attributeList.size() > 0 )
2099+
{
2100+
rasterLayerElem = SIAInfoDoc.createElement( currentLayerName );
2101+
}
2102+
for ( int j = 0; j < attributeList.size(); ++j )
2103+
{
2104+
currentAttributeElem = attributeList.at( j ).toElement();
2105+
currentAttributeName = currentAttributeElem.attribute( "name" );
2106+
currentAttributeValue = currentAttributeElem.attribute( "value" );
2107+
QDomElement outAttributeElem = SIAInfoDoc.createElement( currentAttributeName );
2108+
QDomText outAttributeText = SIAInfoDoc.createTextNode( currentAttributeValue );
2109+
outAttributeElem.appendChild( outAttributeText );
2110+
rasterLayerElem.appendChild( outAttributeElem );
2111+
}
2112+
if ( attributeList.size() > 0 )
2113+
{
2114+
SIAInfoDocElement.appendChild( rasterLayerElem );
2115+
}
2116+
}
2117+
else //vector
2118+
{
2119+
2120+
//property attributes
2121+
QSet<QString> layerPropertyAttributes;
2122+
QMap< QString, QgsMapLayer* >::const_iterator layerNameMapIt = layerNameMap.find( currentLayerName );
2123+
if ( layerNameMapIt != layerNameMap.constEnd() )
2124+
{
2125+
QgsMapLayer* currentLayer = layerNameMapIt.value();
2126+
if ( currentLayer )
2127+
{
2128+
QString WMSPropertyAttributesString = currentLayer->customProperty( "WMSPropertyAttributes" ).toString();
2129+
if ( !WMSPropertyAttributesString.isEmpty() )
2130+
{
2131+
QStringList propertyList = WMSPropertyAttributesString.split( "//" );
2132+
QStringList::const_iterator propertyIt = propertyList.constBegin();
2133+
for ( ; propertyIt != propertyList.constEnd(); ++propertyIt )
2134+
{
2135+
layerPropertyAttributes.insert( *propertyIt );
2136+
}
2137+
}
2138+
}
2139+
}
2140+
2141+
QDomElement propertyRefChild; //child to insert the next property after (or
2142+
for ( int j = 0; j < featureList.size(); ++j )
2143+
{
2144+
QDomElement SIAFeatureElem = SIAInfoDoc.createElement( currentLayerName );
2145+
currentFeatureElem = featureList.at( j ).toElement();
2146+
QDomNodeList attributeList = currentFeatureElem.elementsByTagName( "Attribute" );
2147+
2148+
for ( int k = 0; k < attributeList.size(); ++k )
2149+
{
2150+
currentAttributeElem = attributeList.at( k ).toElement();
2151+
currentAttributeName = currentAttributeElem.attribute( "name" );
2152+
currentAttributeValue = currentAttributeElem.attribute( "value" );
2153+
if ( layerPropertyAttributes.contains( currentAttributeName ) )
2154+
{
2155+
QDomElement propertyElem = SIAInfoDoc.createElement( "property" );
2156+
QDomElement identifierElem = SIAInfoDoc.createElement( "identifier" );
2157+
QDomText identifierText = SIAInfoDoc.createTextNode( currentAttributeName );
2158+
identifierElem.appendChild( identifierText );
2159+
QDomElement valueElem = SIAInfoDoc.createElement( "value" );
2160+
QDomText valueText = SIAInfoDoc.createTextNode( currentAttributeValue );
2161+
valueElem.appendChild( valueText );
2162+
propertyElem.appendChild( identifierElem );
2163+
propertyElem.appendChild( valueElem );
2164+
if ( propertyRefChild.isNull() )
2165+
{
2166+
SIAFeatureElem.insertBefore( propertyElem, QDomNode() );
2167+
propertyRefChild = propertyElem;
2168+
}
2169+
else
2170+
{
2171+
SIAFeatureElem.insertAfter( propertyElem, propertyRefChild );
2172+
}
2173+
}
2174+
else
2175+
{
2176+
QDomElement SIAAttributeElem = SIAInfoDoc.createElement( currentAttributeName );
2177+
QDomText SIAAttributeText = SIAInfoDoc.createTextNode( currentAttributeValue );
2178+
SIAAttributeElem.appendChild( SIAAttributeText );
2179+
SIAFeatureElem.appendChild( SIAAttributeElem );
2180+
}
2181+
}
2182+
SIAInfoDocElement.appendChild( SIAFeatureElem );
2183+
}
2184+
}
2185+
}
2186+
doc = SIAInfoDoc;
2187+
}

src/mapserver/qgswmsserver.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,9 @@ class QgsWMSServer
176176
/**Add '<?xml version="1.0" ?>'. Some clients need an xml declaration (though it is not strictly required)*/
177177
void addXMLDeclaration( QDomDocument& doc ) const;
178178

179+
/**Converts a feature info xml document to SIA2045 norm*/
180+
void convertFeatureInfoToSIA2045( QDomDocument& doc, const QMap< QString, QgsMapLayer* >& layerNameMap );
181+
179182
/**Map containing the WMS parameters*/
180183
QMap<QString, QString> mParameterMap;
181184
QgsConfigParser* mConfigParser;

0 commit comments

Comments
 (0)