Skip to content
Permalink
Browse files

[FEATURE]: Consider ValueMap in GetFeatureInfo

  • Loading branch information
mhugent committed Mar 10, 2014
1 parent 7264777 commit 0fb435e7c9a3805bf12774d4c1d1749a7f97d7e5
Showing with 63 additions and 32 deletions.
  1. +60 −32 src/mapserver/qgswmsserver.cpp
  2. +3 −0 src/mapserver/qgswmsserver.h
@@ -1571,7 +1571,7 @@ int QgsWMSServer::featureInfoFromVectorLayer( QgsVectorLayer* layer,

QDomElement attributeElement = infoDocument.createElement( "Attribute" );
attributeElement.setAttribute( "name", attributeName );
attributeElement.setAttribute( "value", QgsExpression::replaceExpressionText( featureAttributes[i].toString(), &feature, layer ) );
attributeElement.setAttribute( "value", replaceValueMapAndRelation( layer, i, QgsExpression::replaceExpressionText( featureAttributes[i].toString(), &feature, layer ) ) );
featureElement.appendChild( attributeElement );
}

@@ -1590,7 +1590,7 @@ int QgsWMSServer::featureInfoFromVectorLayer( QgsVectorLayer* layer,
//also append the wkt geometry as an attribute
if ( addWktGeometry && hasGeometry )
{
QgsGeometry* geom = feature.geometry();
QgsGeometry* geom = feature.geometry();
if ( layer->crs() != outputCrs )
{
const QgsCoordinateTransform *transform = mapRender->transformation( layer );
@@ -2558,42 +2558,42 @@ QDomElement QgsWMSServer::createFeatureGML(
typeNameElement.setAttribute( "fid", typeName + "." + QString::number( feat->id() ) );

const QgsCoordinateTransform* transform = 0;
if ( layer && layer->crs() != crs)
if ( layer && layer->crs() != crs )
{
transform = mMapRenderer->transformation( layer );
}

QgsGeometry* geom = feat->geometry();

// always add bounding box info if feature contains geometry
if ( geom && geom->type() != QGis::UnknownGeometry && geom->type() != QGis::NoGeometry)
{
QgsRectangle box = feat->geometry()->boundingBox();
if ( transform )
{
box = transform->transformBoundingBox( box );
}

QDomElement bbElem = doc.createElement( "gml:boundedBy" );
QDomElement boxElem;
if ( version < 3 )
{
boxElem = QgsOgcUtils::rectangleToGMLBox( &box, doc );
}
else
{
boxElem = QgsOgcUtils::rectangleToGMLEnvelope( &box, doc );
}

if ( crs.isValid() )
{
boxElem.setAttribute( "srsName", crs.authid() );
}
bbElem.appendChild( boxElem );
typeNameElement.appendChild( bbElem );
}

if ( withGeom)
if ( geom && geom->type() != QGis::UnknownGeometry && geom->type() != QGis::NoGeometry )
{
QgsRectangle box = feat->geometry()->boundingBox();
if ( transform )
{
box = transform->transformBoundingBox( box );
}

QDomElement bbElem = doc.createElement( "gml:boundedBy" );
QDomElement boxElem;
if ( version < 3 )
{
boxElem = QgsOgcUtils::rectangleToGMLBox( &box, doc );
}
else
{
boxElem = QgsOgcUtils::rectangleToGMLEnvelope( &box, doc );
}

if ( crs.isValid() )
{
boxElem.setAttribute( "srsName", crs.authid() );
}
bbElem.appendChild( boxElem );
typeNameElement.appendChild( bbElem );
}

if ( withGeom )
{
//add geometry column (as gml)

@@ -2634,7 +2634,7 @@ QDomElement QgsWMSServer::createFeatureGML(
QString fieldTextString = featureAttributes[i].toString();
if ( layer )
{
fieldTextString = QgsExpression::replaceExpressionText( fieldTextString, feat, layer );
fieldTextString = replaceValueMapAndRelation( layer, i, QgsExpression::replaceExpressionText( fieldTextString, feat, layer ) );
}
QDomText fieldText = doc.createTextNode( fieldTextString );
fieldElem.appendChild( fieldText );
@@ -2643,3 +2643,31 @@ QDomElement QgsWMSServer::createFeatureGML(

return typeNameElement;
}

QString QgsWMSServer::replaceValueMapAndRelation( QgsVectorLayer* vl, int idx, const QString& attributeVal )
{
if ( !vl )
{
return attributeVal;
}

QgsVectorLayer::EditType type = vl->editType( idx );
if ( type == QgsVectorLayer::ValueMap )
{
QMap<QString, QVariant> valueMap = vl->valueMap( idx );
QMap<QString, QVariant>::const_iterator vmapIt = valueMap.constBegin();
for ( ; vmapIt != valueMap.constEnd(); ++vmapIt )
{
if ( vmapIt.value().toString() == attributeVal )
{
return vmapIt.key();
}
}
}
else if ( type == QgsVectorLayer::ValueRelation )
{
QgsVectorLayer::ValueRelationData vrdata = vl->valueRelation( idx );
//todo...
}
return attributeVal;
}
@@ -232,6 +232,9 @@ class QgsWMSServer
QString typeName,
bool withGeom,
int version ) const;

/**Replaces attribute value with ValueRelation or ValueRelation if defined. Otherwise returns the original value*/
static QString replaceValueMapAndRelation( QgsVectorLayer* vl, int idx, const QString& attributeVal );
};

#endif

0 comments on commit 0fb435e

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