Skip to content

Commit 4c161c9

Browse files
committedOct 22, 2012
Merge branch for sia2045 GetFeatureInfo output
2 parents dbab4a2 + feec5f0 commit 4c161c9

File tree

8 files changed

+247
-3
lines changed

8 files changed

+247
-3
lines changed
 

‎src/mapserver/qgis_map_serv.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,8 @@ int main( int argc, char * argv[] )
165165
}
166166
#endif
167167

168+
QDomImplementation::setInvalidDataPolicy( QDomImplementation::DropInvalidChars );
169+
168170
// Instantiate the plugin directory so that providers are loaded
169171
QgsProviderRegistry::instance( QgsApplication::pluginPath() );
170172
QgsDebugMsg( "Prefix PATH: " + QgsApplication::prefixPath() );
@@ -522,7 +524,15 @@ int main( int argc, char * argv[] )
522524
}
523525

524526
//info format for GetFeatureInfo
525-
theRequestHandler->sendGetFeatureInfoResponse( featureInfoDoc, parameterMap.value( "INFO_FORMAT" ) );
527+
528+
//additionally support text/xml; format=sia2045
529+
QString infoFormat = parameterMap.value( "INFO_FORMAT" );
530+
if ( infoFormat.compare( "text/xml", Qt::CaseInsensitive ) == 0 && adminConfigParser->featureInfoFormatSIA2045() )
531+
{
532+
infoFormat = "text/xml; format=sia2045";
533+
}
534+
535+
theRequestHandler->sendGetFeatureInfoResponse( featureInfoDoc, infoFormat );
526536
delete theRequestHandler;
527537
delete theServer;
528538
continue;

‎src/mapserver/qgsconfigparser.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,17 @@ class QgsConfigParser
129129
int maxWidth() const { return mMaxWidth; }
130130
int maxHeight() const { return mMaxHeight; }
131131

132+
/**Returns map with layer aliases for GetFeatureInfo (or 0 pointer if not supported). Key: layer name, Value: layer alias*/
133+
virtual QHash<QString, QString> featureInfoLayerAliasMap() const { return QHash<QString, QString>(); }
134+
135+
/**Returns name of document element in GetFeatureInfo response*/
136+
virtual QString featureInfoDocumentElement( const QString& defaultValue ) const { return defaultValue; }
137+
/**Returns document element namespace in GetFeatureInfo response or empty string*/
138+
virtual QString featureInfoDocumentElementNS() const { return ""; }
139+
140+
/**Return feature info in format SIA2045?*/
141+
virtual bool featureInfoFormatSIA2045() const { return false; }
142+
132143
protected:
133144
/**Parser to forward not resolved requests (e.g. SLD parser based on user request might have a fallback parser with admin configuration)*/
134145
QgsConfigParser* mFallbackParser;

‎src/mapserver/qgshttprequesthandler.cpp

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,73 @@ void QgsHttpRequestHandler::sendGetFeatureInfoResponse( const QDomDocument& info
147147
{
148148
ba = infoDoc.toByteArray();
149149
}
150+
else if ( infoFormat == "text/xml; format=sia2045" )
151+
{
152+
QDomDocument outFeatureInfoDoc;
153+
QDomElement infoDocElement = infoDoc.documentElement();
154+
QDomElement outInfoDocElement = outFeatureInfoDoc.importNode( infoDocElement, false ).toElement();
155+
outFeatureInfoDoc.appendChild( outInfoDocElement );
156+
157+
QString currentAttributeName;
158+
QString currentAttributeValue;
159+
QDomElement currentAttributeElem;
160+
QString currentLayerName;
161+
QDomElement currentLayerElem;
162+
QDomNodeList layerNodeList = infoDocElement.elementsByTagName( "Layer" );
163+
for ( int i = 0; i < layerNodeList.size(); ++i )
164+
{
165+
currentLayerElem = layerNodeList.at( i ).toElement();
166+
currentLayerName = currentLayerElem.attribute( "name" );
167+
QDomElement currentFeatureElem;
168+
169+
QDomNodeList featureList = currentLayerElem.elementsByTagName( "Feature" );
170+
if ( featureList.size() < 1 )
171+
{
172+
//raster?
173+
QDomNodeList attributeList = currentLayerElem.elementsByTagName( "Attribute" );
174+
QDomElement rasterLayerElem;
175+
if ( attributeList.size() > 0 )
176+
{
177+
rasterLayerElem = outFeatureInfoDoc.createElement( currentLayerName );
178+
}
179+
for ( int j = 0; j < attributeList.size(); ++j )
180+
{
181+
currentAttributeElem = attributeList.at( j ).toElement();
182+
currentAttributeName = currentAttributeElem.attribute( "name" );
183+
currentAttributeValue = currentAttributeElem.attribute( "value" );
184+
QDomElement outAttributeElem = outFeatureInfoDoc.createElement( currentAttributeName );
185+
QDomText outAttributeText = outFeatureInfoDoc.createTextNode( currentAttributeValue );
186+
outAttributeElem.appendChild( outAttributeText );
187+
rasterLayerElem.appendChild( outAttributeElem );
188+
}
189+
if ( attributeList.size() > 0 )
190+
{
191+
outInfoDocElement.appendChild( rasterLayerElem );
192+
}
193+
}
194+
else //vector
195+
{
196+
for ( int j = 0; j < featureList.size(); ++j )
197+
{
198+
QDomElement outFeatureElem = outFeatureInfoDoc.createElement( currentLayerName );
199+
currentFeatureElem = featureList.at( j ).toElement();
200+
QDomNodeList attributeList = currentFeatureElem.elementsByTagName( "Attribute" );
201+
for ( int k = 0; k < attributeList.size(); ++k )
202+
{
203+
currentAttributeElem = attributeList.at( k ).toElement();
204+
currentAttributeName = currentAttributeElem.attribute( "name" );
205+
currentAttributeValue = currentAttributeElem.attribute( "value" );
206+
QDomElement outAttributeElem = outFeatureInfoDoc.createElement( currentAttributeName );
207+
QDomText outAttributeText = outFeatureInfoDoc.createTextNode( currentAttributeValue );
208+
outAttributeElem.appendChild( outAttributeText );
209+
outFeatureElem.appendChild( outAttributeElem );
210+
}
211+
outInfoDocElement.appendChild( outFeatureElem );
212+
}
213+
}
214+
}
215+
ba = outFeatureInfoDoc.toByteArray();
216+
}
150217
else if ( infoFormat == "text/plain" || infoFormat == "text/html" )
151218
{
152219
//create string

‎src/mapserver/qgsprojectparser.cpp

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1855,6 +1855,107 @@ QStringList QgsProjectParser::wfsLayerNames() const
18551855
return layerNameList;
18561856
}
18571857

1858+
QHash<QString, QString> QgsProjectParser::featureInfoLayerAliasMap() const
1859+
{
1860+
QHash<QString, QString> aliasMap;
1861+
QDomElement propertiesElem = mXMLDoc->documentElement().firstChildElement( "properties" );
1862+
if ( propertiesElem.isNull() )
1863+
{
1864+
return aliasMap;
1865+
}
1866+
1867+
//WMSFeatureInfoAliasLayers
1868+
QStringList aliasLayerStringList;
1869+
QDomElement featureInfoAliasLayersElem = propertiesElem.firstChildElement( "WMSFeatureInfoAliasLayers" );
1870+
if ( featureInfoAliasLayersElem.isNull() )
1871+
{
1872+
return aliasMap;
1873+
}
1874+
QDomNodeList aliasLayerValueList = featureInfoAliasLayersElem.elementsByTagName( "value" );
1875+
for ( int i = 0; i < aliasLayerValueList.size(); ++i )
1876+
{
1877+
aliasLayerStringList << aliasLayerValueList.at( i ).toElement().text();
1878+
}
1879+
1880+
//WMSFeatureInfoLayerAliases
1881+
QStringList layerAliasStringList;
1882+
QDomElement featureInfoLayerAliasesElem = propertiesElem.firstChildElement( "WMSFeatureInfoLayerAliases" );
1883+
if ( featureInfoLayerAliasesElem.isNull() )
1884+
{
1885+
return aliasMap;
1886+
}
1887+
QDomNodeList layerAliasesValueList = featureInfoLayerAliasesElem.elementsByTagName( "value" );
1888+
for ( int i = 0; i < layerAliasesValueList.size(); ++i )
1889+
{
1890+
layerAliasStringList << layerAliasesValueList.at( i ).toElement().text();
1891+
}
1892+
1893+
int nMapEntries = qMin( aliasLayerStringList.size(), layerAliasStringList.size() );
1894+
for ( int i = 0; i < nMapEntries; ++i )
1895+
{
1896+
aliasMap.insert( aliasLayerStringList.at( i ), layerAliasStringList.at( i ) );
1897+
}
1898+
1899+
return aliasMap;
1900+
}
1901+
1902+
QString QgsProjectParser::featureInfoDocumentElement( const QString& defaultValue ) const
1903+
{
1904+
QDomElement propertiesElem = mXMLDoc->documentElement().firstChildElement( "properties" );
1905+
if ( propertiesElem.isNull() )
1906+
{
1907+
return defaultValue;
1908+
}
1909+
QDomElement featureInfoDocumentElem = propertiesElem.firstChildElement( "WMSFeatureInfoDocumentElement" );
1910+
if ( featureInfoDocumentElem.isNull() )
1911+
{
1912+
return defaultValue;
1913+
}
1914+
return featureInfoDocumentElem.text();
1915+
}
1916+
1917+
QString QgsProjectParser::featureInfoDocumentElementNS() const
1918+
{
1919+
QDomElement propertiesElem = mXMLDoc->documentElement().firstChildElement( "properties" );
1920+
if ( propertiesElem.isNull() )
1921+
{
1922+
return "";
1923+
}
1924+
QDomElement featureInfoDocumentNSElem = propertiesElem.firstChildElement( "WMSFeatureInfoDocumentElementNS" );
1925+
if ( featureInfoDocumentNSElem.isNull() )
1926+
{
1927+
return "";
1928+
}
1929+
return featureInfoDocumentNSElem.text();
1930+
}
1931+
1932+
bool QgsProjectParser::featureInfoFormatSIA2045() const
1933+
{
1934+
if ( !mXMLDoc )
1935+
{
1936+
return false;
1937+
}
1938+
1939+
QDomElement propertiesElem = mXMLDoc->documentElement().firstChildElement( "properties" );
1940+
if ( propertiesElem.isNull() )
1941+
{
1942+
return false;
1943+
}
1944+
1945+
QDomElement sia2045Elem = propertiesElem.firstChildElement( "WMSInfoFormatSIA2045" );
1946+
if ( sia2045Elem.isNull() )
1947+
{
1948+
return false;
1949+
}
1950+
1951+
if ( sia2045Elem.text().compare( "enabled", Qt::CaseInsensitive ) == 0
1952+
|| sia2045Elem.text().compare( "true", Qt::CaseInsensitive ) == 0 )
1953+
{
1954+
return true;
1955+
}
1956+
return false;
1957+
}
1958+
18581959
QString QgsProjectParser::convertToAbsolutePath( const QString& file ) const
18591960
{
18601961
if ( !file.startsWith( "./" ) && !file.startsWith( "../" ) )

‎src/mapserver/qgsprojectparser.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,16 @@ class QgsProjectParser: public QgsConfigParser
111111
/**Returns the names of the published wfs layers (not the ids as in wfsLayers() )*/
112112
QStringList wfsLayerNames() const;
113113

114+
/**Returns map with layer aliases for GetFeatureInfo (or 0 pointer if not supported). Key: layer name, Value: layer alias*/
115+
virtual QHash<QString, QString> featureInfoLayerAliasMap() const;
116+
117+
virtual QString featureInfoDocumentElement( const QString& defaultValue ) const;
118+
119+
virtual QString featureInfoDocumentElementNS() const;
120+
121+
/**Return feature info in format SIA2045?*/
122+
bool featureInfoFormatSIA2045() const;
123+
114124
private:
115125

116126
//forbidden

‎src/mapserver/qgssldparser.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1546,6 +1546,24 @@ bool QgsSLDParser::featureInfoWithWktGeometry() const
15461546
return false;
15471547
}
15481548

1549+
QHash<QString, QString> QgsSLDParser::featureInfoLayerAliasMap() const
1550+
{
1551+
if ( mFallbackParser )
1552+
{
1553+
return mFallbackParser->featureInfoLayerAliasMap();
1554+
}
1555+
return QHash<QString, QString>();
1556+
}
1557+
1558+
bool QgsSLDParser::featureInfoFormatSIA2045() const
1559+
{
1560+
if ( mFallbackParser )
1561+
{
1562+
return mFallbackParser->featureInfoFormatSIA2045();
1563+
}
1564+
return false;
1565+
}
1566+
15491567
#ifdef DIAGRAMSERVER
15501568
int QgsSLDParser::overlaysFromUserStyle( const QDomElement& userStyleElement, QgsVectorLayer* vec ) const
15511569
{

‎src/mapserver/qgssldparser.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@ class QgsSLDParser: public QgsConfigParser
8383
/**True if the feature info response should contain the wkt geometry for vector features*/
8484
virtual bool featureInfoWithWktGeometry() const;
8585

86+
/**Returns map with layer aliases for GetFeatureInfo (or 0 pointer if not supported). Key: layer name, Value: layer alias*/
87+
virtual QHash<QString, QString> featureInfoLayerAliasMap() const;
88+
89+
/**Return feature info in format SIA2045?*/
90+
bool featureInfoFormatSIA2045() const;
91+
8692
private:
8793
/**Don't use the default constructor*/
8894
QgsSLDParser();

‎src/mapserver/qgswmsserver.cpp

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,17 @@ int QgsWMSServer::getFeatureInfo( QDomDocument& result, QString version )
729729
QStringList layerIds = layerSet( layersList, stylesList, mMapRenderer->destinationCrs() );
730730
QMap<QString, QString> originalLayerFilters = applyRequestedLayerFilters( layersList );
731731

732-
QDomElement getFeatureInfoElement = result.createElement( "GetFeatureInfoResponse" );
732+
QString featureInfoElemName = mConfigParser->featureInfoDocumentElement( "GetFeatureInfoResponse" );
733+
QString featureInfoElemNS = mConfigParser->featureInfoDocumentElementNS();
734+
QDomElement getFeatureInfoElement;
735+
if ( featureInfoElemNS.isEmpty() )
736+
{
737+
getFeatureInfoElement = result.createElement( featureInfoElemName );
738+
}
739+
else
740+
{
741+
getFeatureInfoElement = result.createElementNS( featureInfoElemNS, featureInfoElemName );
742+
}
733743
result.appendChild( getFeatureInfoElement );
734744

735745
QStringList nonIdentifiableLayers = mConfigParser->identifyDisabledLayers();
@@ -746,6 +756,9 @@ int QgsWMSServer::getFeatureInfo( QDomDocument& result, QString version )
746756
renderContext.setPainter( 0 );
747757
}
748758

759+
//layers can have assigned a different name for GetCapabilities
760+
QHash<QString, QString> layerAliasMap = mConfigParser->featureInfoLayerAliasMap();
761+
749762
QList<QgsMapLayer*> layerList;
750763
QgsMapLayer* currentLayer = 0;
751764
QStringList::const_iterator layerIt;
@@ -774,7 +787,15 @@ int QgsWMSServer::getFeatureInfo( QDomDocument& result, QString version )
774787
}
775788

776789
QDomElement layerElement = result.createElement( "Layer" );
777-
layerElement.setAttribute( "name", currentLayer->name() );
790+
QString layerName = currentLayer->name();
791+
792+
//check if the layer is given a different name for GetFeatureInfo output
793+
QHash<QString, QString>::const_iterator layerAliasIt = layerAliasMap.find( layerName );
794+
if ( layerAliasIt != layerAliasMap.constEnd() )
795+
{
796+
layerName = layerAliasIt.value();
797+
}
798+
layerElement.setAttribute( "name", layerName );
778799
getFeatureInfoElement.appendChild( layerElement );
779800

780801
//switch depending on vector or raster

0 commit comments

Comments
 (0)
Please sign in to comment.