Skip to content

Commit b2608d5

Browse files
author
mhugent
committedMar 22, 2011
Server: only show wkt geometry in feature info response if selected by user
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@15557 c8812cc2-4d05-0410-92ff-de0c093fc19c

File tree

8 files changed

+71
-11
lines changed

8 files changed

+71
-11
lines changed
 

‎src/app/qgsprojectproperties.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,9 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas* mapCanvas, QWidget *pa
212212

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

215+
bool addWktGeometry = QgsProject::instance()->readBoolEntry( "WMSAddWktGeometry", "/" );
216+
mAddWktGeometryCheckBox->setChecked( addWktGeometry );
217+
215218
restoreState();
216219
}
217220

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

414+
QgsProject::instance()->writeEntry( "WMSAddWktGeometry", "/", mAddWktGeometryCheckBox->isChecked() );
415+
411416
//todo XXX set canvas color
412417
emit refresh();
413418
}

‎src/mapserver/qgsconfigparser.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ class QgsConfigParser
8585
that all possible CRS should be advertised (which could result in very long capabilities documents)*/
8686
virtual QSet<QString> supportedOutputCrsSet() const { return QSet<QString>(); }
8787

88+
/**True if the feature info response should contain the wkt geometry for vector features*/
89+
virtual bool featureInfoWithWktGeometry() const { return false; }
90+
8891
/**Returns information about vector layer aliases. First key is the layer id, (second) key is the field id, value the alias.
8992
Default implementation returns an empty map*/
9093
virtual QMap< QString, QMap< int, QString > > layerAliasInfo() const { return QMap< QString, QMap<int, QString> > (); }

‎src/mapserver/qgsprojectparser.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,32 @@ QSet<QString> QgsProjectParser::supportedOutputCrsSet() const
451451
return crsSet;
452452
}
453453

454+
bool QgsProjectParser::featureInfoWithWktGeometry() const
455+
{
456+
if ( !mXMLDoc )
457+
{
458+
return false;
459+
}
460+
461+
QDomElement qgisElem = mXMLDoc->documentElement();
462+
if ( qgisElem.isNull() )
463+
{
464+
return false;
465+
}
466+
QDomElement propertiesElem = qgisElem.firstChildElement( "properties" );
467+
if ( propertiesElem.isNull() )
468+
{
469+
return false;
470+
}
471+
QDomElement wktElem = propertiesElem.firstChildElement( "WMSAddWktGeometry" );
472+
if ( wktElem.isNull() )
473+
{
474+
return false;
475+
}
476+
477+
return ( wktElem.text().compare( "true", Qt::CaseInsensitive ) == 0 );
478+
}
479+
454480
QMap< QString, QMap< int, QString > > QgsProjectParser::layerAliasInfo() const
455481
{
456482
QMap< QString, QMap< int, QString > > resultMap;

‎src/mapserver/qgsprojectparser.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ class QgsProjectParser: public QgsConfigParser
6969
*/
7070
virtual QSet<QString> supportedOutputCrsSet() const;
7171

72+
/**True if the feature info response should contain the wkt geometry for vector features*/
73+
virtual bool featureInfoWithWktGeometry() const;
74+
7275
/**Returns information about vector layer aliases. First key is the layer id, (second) key is the field id, value the alias.
7376
Default implementation returns an empty map*/
7477
virtual QMap< QString, QMap< int, QString > > layerAliasInfo() const;

‎src/mapserver/qgssldparser.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1552,6 +1552,15 @@ void QgsSLDParser::printCapabilities( QDomElement& parentElement, QDomDocument&
15521552
}
15531553
}
15541554

1555+
bool QgsSLDParser::featureInfoWithWktGeometry() const
1556+
{
1557+
if ( mFallbackParser )
1558+
{
1559+
return mFallbackParser->featureInfoWithWktGeometry();
1560+
}
1561+
return false;
1562+
}
1563+
15551564
#ifdef DIAGRAMSERVER
15561565
int QgsSLDParser::overlaysFromUserStyle( const QDomElement& userStyleElement, QgsVectorLayer* vec ) const
15571566
{

‎src/mapserver/qgssldparser.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ class QgsSLDParser: public QgsConfigParser
7474
/**Adds print capabilities to xml document. Delegated to fallback parser*/
7575
void printCapabilities( QDomElement& parentElement, QDomDocument& doc ) const;
7676

77+
/**True if the feature info response should contain the wkt geometry for vector features*/
78+
virtual bool featureInfoWithWktGeometry() const;
79+
7780
private:
7881
/**Don't use the default constructor*/
7982
QgsSLDParser();

‎src/mapserver/qgswmsserver.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,8 +1063,9 @@ int QgsWMSServer::featureInfoFromVectorLayer( QgsVectorLayer* layer,
10631063
QgsAttributeMap featureAttributes;
10641064
int featureCounter = 0;
10651065
const QgsFieldMap& fields = provider->fields();
1066+
bool addWktGeometry = mConfigParser && mConfigParser->featureInfoWithWktGeometry();
10661067

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

11041105
//also append the wkt geometry as an attribute
1105-
QgsGeometry* geom = feature.geometry();
1106-
if ( geom )
1106+
if ( addWktGeometry )
11071107
{
1108-
QDomElement geometryElement = infoDocument.createElement( "Attribute" );
1109-
geometryElement.setAttribute( "name", "geometry" );
1110-
geometryElement.setAttribute( "value", geom->exportToWkt() );
1111-
geometryElement.setAttribute( "type", "derived" );
1112-
featureElement.appendChild( geometryElement );
1108+
QgsGeometry* geom = feature.geometry();
1109+
if ( geom )
1110+
{
1111+
QDomElement geometryElement = infoDocument.createElement( "Attribute" );
1112+
geometryElement.setAttribute( "name", "geometry" );
1113+
geometryElement.setAttribute( "value", geom->exportToWkt() );
1114+
geometryElement.setAttribute( "type", "derived" );
1115+
featureElement.appendChild( geometryElement );
1116+
}
11131117
}
11141118
}
11151119

‎src/ui/qgsprojectpropertiesbase.ui

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@
367367
<attribute name="title">
368368
<string>WMS Server</string>
369369
</attribute>
370-
<layout class="QGridLayout" name="gridLayout_3">
370+
<layout class="QGridLayout" name="gridLayout">
371371
<item row="0" column="0" colspan="2">
372372
<widget class="QGroupBox" name="grpWMSServiceCapabilities">
373373
<property name="title">
@@ -458,7 +458,7 @@
458458
</layout>
459459
</widget>
460460
</item>
461-
<item row="3" column="0">
461+
<item row="1" column="0">
462462
<widget class="QGroupBox" name="grpWMSExt">
463463
<property name="title">
464464
<string>Advertised Extent</string>
@@ -561,7 +561,7 @@
561561
</layout>
562562
</widget>
563563
</item>
564-
<item row="3" column="1">
564+
<item row="1" column="1" rowspan="2">
565565
<widget class="QGroupBox" name="grpWMSList">
566566
<property name="title">
567567
<string>Coordinate Systems Restrictions</string>
@@ -600,6 +600,13 @@
600600
</layout>
601601
</widget>
602602
</item>
603+
<item row="2" column="0">
604+
<widget class="QCheckBox" name="mAddWktGeometryCheckBox">
605+
<property name="text">
606+
<string>Add WKT geometry to feature info response</string>
607+
</property>
608+
</widget>
609+
</item>
603610
</layout>
604611
</widget>
605612
</widget>

0 commit comments

Comments
 (0)
Please sign in to comment.