Skip to content
Permalink
Browse files
Server: only show wkt geometry in feature info response if selected b…
…y user

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@15557 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Mar 22, 2011
1 parent 5c794f6 commit b2608d50e74b205eff43a6260cadae3a19a106c1
@@ -212,6 +212,9 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas* mapCanvas, QWidget *pa

grpWMSList->setChecked( mWMSList->count() > 0 );

bool addWktGeometry = QgsProject::instance()->readBoolEntry( "WMSAddWktGeometry", "/" );
mAddWktGeometryCheckBox->setChecked( addWktGeometry );

restoreState();
}

@@ -408,6 +411,8 @@ void QgsProjectProperties::apply()
QgsProject::instance()->removeEntry( "WMSCrsList", "/" );
}

QgsProject::instance()->writeEntry( "WMSAddWktGeometry", "/", mAddWktGeometryCheckBox->isChecked() );

//todo XXX set canvas color
emit refresh();
}
@@ -85,6 +85,9 @@ class QgsConfigParser
that all possible CRS should be advertised (which could result in very long capabilities documents)*/
virtual QSet<QString> supportedOutputCrsSet() const { return QSet<QString>(); }

/**True if the feature info response should contain the wkt geometry for vector features*/
virtual bool featureInfoWithWktGeometry() const { return false; }

/**Returns information about vector layer aliases. First key is the layer id, (second) key is the field id, value the alias.
Default implementation returns an empty map*/
virtual QMap< QString, QMap< int, QString > > layerAliasInfo() const { return QMap< QString, QMap<int, QString> > (); }
@@ -451,6 +451,32 @@ QSet<QString> QgsProjectParser::supportedOutputCrsSet() const
return crsSet;
}

bool QgsProjectParser::featureInfoWithWktGeometry() const
{
if ( !mXMLDoc )
{
return false;
}

QDomElement qgisElem = mXMLDoc->documentElement();
if ( qgisElem.isNull() )
{
return false;
}
QDomElement propertiesElem = qgisElem.firstChildElement( "properties" );
if ( propertiesElem.isNull() )
{
return false;
}
QDomElement wktElem = propertiesElem.firstChildElement( "WMSAddWktGeometry" );
if ( wktElem.isNull() )
{
return false;
}

return ( wktElem.text().compare( "true", Qt::CaseInsensitive ) == 0 );
}

QMap< QString, QMap< int, QString > > QgsProjectParser::layerAliasInfo() const
{
QMap< QString, QMap< int, QString > > resultMap;
@@ -69,6 +69,9 @@ class QgsProjectParser: public QgsConfigParser
*/
virtual QSet<QString> supportedOutputCrsSet() const;

/**True if the feature info response should contain the wkt geometry for vector features*/
virtual bool featureInfoWithWktGeometry() const;

/**Returns information about vector layer aliases. First key is the layer id, (second) key is the field id, value the alias.
Default implementation returns an empty map*/
virtual QMap< QString, QMap< int, QString > > layerAliasInfo() const;
@@ -1552,6 +1552,15 @@ void QgsSLDParser::printCapabilities( QDomElement& parentElement, QDomDocument&
}
}

bool QgsSLDParser::featureInfoWithWktGeometry() const
{
if ( mFallbackParser )
{
return mFallbackParser->featureInfoWithWktGeometry();
}
return false;
}

#ifdef DIAGRAMSERVER
int QgsSLDParser::overlaysFromUserStyle( const QDomElement& userStyleElement, QgsVectorLayer* vec ) const
{
@@ -74,6 +74,9 @@ class QgsSLDParser: public QgsConfigParser
/**Adds print capabilities to xml document. Delegated to fallback parser*/
void printCapabilities( QDomElement& parentElement, QDomDocument& doc ) const;

/**True if the feature info response should contain the wkt geometry for vector features*/
virtual bool featureInfoWithWktGeometry() const;

private:
/**Don't use the default constructor*/
QgsSLDParser();
@@ -1063,8 +1063,9 @@ int QgsWMSServer::featureInfoFromVectorLayer( QgsVectorLayer* layer,
QgsAttributeMap featureAttributes;
int featureCounter = 0;
const QgsFieldMap& fields = provider->fields();
bool addWktGeometry = mConfigParser && mConfigParser->featureInfoWithWktGeometry();

provider->select( provider->attributeIndexes(), searchRect, true, true );
provider->select( provider->attributeIndexes(), searchRect, addWktGeometry, true );
while ( provider->nextFeature( feature ) )
{
if ( featureCounter > nFeatures )
@@ -1102,14 +1103,17 @@ int QgsWMSServer::featureInfoFromVectorLayer( QgsVectorLayer* layer,
}

//also append the wkt geometry as an attribute
QgsGeometry* geom = feature.geometry();
if ( geom )
if ( addWktGeometry )
{
QDomElement geometryElement = infoDocument.createElement( "Attribute" );
geometryElement.setAttribute( "name", "geometry" );
geometryElement.setAttribute( "value", geom->exportToWkt() );
geometryElement.setAttribute( "type", "derived" );
featureElement.appendChild( geometryElement );
QgsGeometry* geom = feature.geometry();
if ( geom )
{
QDomElement geometryElement = infoDocument.createElement( "Attribute" );
geometryElement.setAttribute( "name", "geometry" );
geometryElement.setAttribute( "value", geom->exportToWkt() );
geometryElement.setAttribute( "type", "derived" );
featureElement.appendChild( geometryElement );
}
}
}

@@ -367,7 +367,7 @@
<attribute name="title">
<string>WMS Server</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_3">
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0" colspan="2">
<widget class="QGroupBox" name="grpWMSServiceCapabilities">
<property name="title">
@@ -458,7 +458,7 @@
</layout>
</widget>
</item>
<item row="3" column="0">
<item row="1" column="0">
<widget class="QGroupBox" name="grpWMSExt">
<property name="title">
<string>Advertised Extent</string>
@@ -561,7 +561,7 @@
</layout>
</widget>
</item>
<item row="3" column="1">
<item row="1" column="1" rowspan="2">
<widget class="QGroupBox" name="grpWMSList">
<property name="title">
<string>Coordinate Systems Restrictions</string>
@@ -600,6 +600,13 @@
</layout>
</widget>
</item>
<item row="2" column="0">
<widget class="QCheckBox" name="mAddWktGeometryCheckBox">
<property name="text">
<string>Add WKT geometry to feature info response</string>
</property>
</widget>
</item>
</layout>
</widget>
</widget>

0 comments on commit b2608d5

Please sign in to comment.