Skip to content

Commit

Permalink
[FEATURE]: Consider ValueMap in GetFeatureInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
mhugent committed Mar 11, 2014
1 parent 7264777 commit 0fb435e
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 32 deletions.
92 changes: 60 additions & 32 deletions src/mapserver/qgswmsserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}

Expand All @@ -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 );
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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 );
Expand All @@ -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;
}
3 changes: 3 additions & 0 deletions src/mapserver/qgswmsserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.