Skip to content
Permalink
Browse files

Other format for xml output GetFeatureInfo

  • Loading branch information
mhugent committed Jan 21, 2012
1 parent 778afc5 commit 70fd4ca006faf56e08bea505e5dd49ce55092117
@@ -116,7 +116,10 @@ class QgsConfigParser
/**Returns map with layer aliases for GetFeatureInfo (or 0 pointer if not supported). Key: layer name, Value: layer alias*/
virtual QHash<QString, QString> featureInfoLayerAliasMap() const { return QHash<QString, QString>(); }

virtual QString featureInfoDocumentName( const QString& defaultValue ) const { return defaultValue; }
/**Returns name of document element in GetFeatureInfo response*/
virtual QString featureInfoDocumentElement( const QString& defaultValue ) const { return defaultValue; }
/**Returns document element namespace in GetFeatureInfo response or empty string*/
virtual QString featureInfoDocumentElementNS() const { return ""; }

protected:
/**Parser to forward not resolved requests (e.g. SLD parser based on user request might have a fallback parser with admin configuration)*/
@@ -133,7 +133,72 @@ void QgsHttpRequestHandler::sendGetFeatureInfoResponse( const QDomDocument& info

if ( infoFormat == "text/xml" )
{
ba = infoDoc.toByteArray();
//ba = infoDoc.toByteArray();
//Modifications for SIA2045
QDomDocument outFeatureInfoDoc;
QDomElement infoDocElement = infoDoc.documentElement();
QDomElement outInfoDocElement = outFeatureInfoDoc.importNode( infoDocElement, false ).toElement();
outFeatureInfoDoc.appendChild( outInfoDocElement );

QString currentAttributeName;
QString currentAttributeValue;
QDomElement currentAttributeElem;
QString currentLayerName;
QDomElement currentLayerElem;
QDomNodeList layerNodeList = infoDocElement.elementsByTagName( "Layer" );
for ( int i = 0; i < layerNodeList.size(); ++i )
{
currentLayerElem = layerNodeList.at( i ).toElement();
currentLayerName = currentLayerElem.attribute( "name" );
QDomElement currentFeatureElem;

QDomNodeList featureList = currentLayerElem.elementsByTagName( "Feature" );
if ( featureList.size() < 1 )
{
//raster?
QDomNodeList attributeList = currentLayerElem.elementsByTagName( "Attribute" );
QDomElement rasterLayerElem;
if ( attributeList.size() > 0 )
{
rasterLayerElem = outFeatureInfoDoc.createElement( currentLayerName );
}
for ( int j = 0; j < attributeList.size(); ++j )
{
currentAttributeElem = attributeList.at( j ).toElement();
currentAttributeName = currentAttributeElem.attribute( "name" );
currentAttributeValue = currentAttributeElem.attribute( "value" );
QDomElement outAttributeElem = outFeatureInfoDoc.createElement( currentAttributeName );
QDomText outAttributeText = outFeatureInfoDoc.createTextNode( currentAttributeValue );
outAttributeElem.appendChild( outAttributeText );
rasterLayerElem.appendChild( outAttributeElem );
}
if ( attributeList.size() > 0 )
{
outInfoDocElement.appendChild( rasterLayerElem );
}
}
else //vector
{
for ( int j = 0; j < featureList.size(); ++j )
{
QDomElement outFeatureElem = outFeatureInfoDoc.createElement( currentLayerName );
currentFeatureElem = featureList.at( j ).toElement();
QDomNodeList attributeList = currentFeatureElem.elementsByTagName( "Attribute" );
for ( int k = 0; k < attributeList.size(); ++k )
{
currentAttributeElem = attributeList.at( k ).toElement();
currentAttributeName = currentAttributeElem.attribute( "name" );
currentAttributeValue = currentAttributeElem.attribute( "value" );
QDomElement outAttributeElem = outFeatureInfoDoc.createElement( currentAttributeName );
QDomText outAttributeText = outFeatureInfoDoc.createTextNode( currentAttributeValue );
outAttributeElem.appendChild( outAttributeText );
outFeatureElem.appendChild( outAttributeElem );
}
outInfoDocElement.appendChild( outFeatureElem );
}
}
}
ba = outFeatureInfoDoc.toByteArray();
}
else if ( infoFormat == "text/plain" || infoFormat == "text/html" )
{
@@ -1397,19 +1397,34 @@ QHash<QString, QString> QgsProjectParser::featureInfoLayerAliasMap() const
return aliasMap;
}

QString QgsProjectParser::featureInfoDocumentName( const QString& defaultValue ) const
QString QgsProjectParser::featureInfoDocumentElement( const QString& defaultValue ) const
{
QDomElement propertiesElem = mXMLDoc->documentElement().firstChildElement( "properties" );
if ( propertiesElem.isNull() )
{
return defaultValue;
}
QDomElement featureInfoDocumentNameElem = propertiesElem.firstChildElement( "WMSFeatureInfoDocumentName" );
if ( featureInfoDocumentNameElem.isNull() )
QDomElement featureInfoDocumentElem = propertiesElem.firstChildElement( "WMSFeatureInfoDocumentElement" );
if ( featureInfoDocumentElem.isNull() )
{
return defaultValue;
}
return featureInfoDocumentNameElem.text();
return featureInfoDocumentElem.text();
}

QString QgsProjectParser::featureInfoDocumentElementNS() const
{
QDomElement propertiesElem = mXMLDoc->documentElement().firstChildElement( "properties" );
if ( propertiesElem.isNull() )
{
return "";
}
QDomElement featureInfoDocumentNSElem = propertiesElem.firstChildElement( "WMSFeatureInfoDocumentElementNS" );
if ( featureInfoDocumentNSElem.isNull() )
{
return "";
}
return featureInfoDocumentNSElem.text();
}

QString QgsProjectParser::convertToAbsolutePath( const QString& file ) const
@@ -104,7 +104,9 @@ class QgsProjectParser: public QgsConfigParser
/**Returns map with layer aliases for GetFeatureInfo (or 0 pointer if not supported). Key: layer name, Value: layer alias*/
virtual QHash<QString, QString> featureInfoLayerAliasMap() const;

virtual QString featureInfoDocumentName( const QString& defaultValue ) const;
virtual QString featureInfoDocumentElement( const QString& defaultValue ) const;

virtual QString featureInfoDocumentElementNS() const;

private:

@@ -803,7 +803,17 @@ int QgsWMSServer::getFeatureInfo( QDomDocument& result, QString version )
QStringList layerIds = layerSet( layersList, stylesList, mMapRenderer->destinationCrs() );
QMap<QString, QString> originalLayerFilters = applyRequestedLayerFilters( layersList );

QDomElement getFeatureInfoElement = result.createElement( mConfigParser->featureInfoDocumentName( "GetFeatureInfoResponse" ) );
QString featureInfoElemName = mConfigParser->featureInfoDocumentElement( "GetFeatureInfoResponse" );
QString featureInfoElemNS = mConfigParser->featureInfoDocumentElementNS();
QDomElement getFeatureInfoElement;
if ( featureInfoElemNS.isEmpty() )
{
getFeatureInfoElement = result.createElement( featureInfoElemName );
}
else
{
getFeatureInfoElement = result.createElementNS( featureInfoElemNS, featureInfoElemName );
}
result.appendChild( getFeatureInfoElement );

QStringList nonIdentifiableLayers = mConfigParser->identifyDisabledLayers();

0 comments on commit 70fd4ca

Please sign in to comment.
You can’t perform that action at this time.