Skip to content

Commit 0fb435e

Browse files
committed
[FEATURE]: Consider ValueMap in GetFeatureInfo
1 parent 7264777 commit 0fb435e

File tree

2 files changed

+63
-32
lines changed

2 files changed

+63
-32
lines changed

src/mapserver/qgswmsserver.cpp

Lines changed: 60 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1571,7 +1571,7 @@ int QgsWMSServer::featureInfoFromVectorLayer( QgsVectorLayer* layer,
15711571

15721572
QDomElement attributeElement = infoDocument.createElement( "Attribute" );
15731573
attributeElement.setAttribute( "name", attributeName );
1574-
attributeElement.setAttribute( "value", QgsExpression::replaceExpressionText( featureAttributes[i].toString(), &feature, layer ) );
1574+
attributeElement.setAttribute( "value", replaceValueMapAndRelation( layer, i, QgsExpression::replaceExpressionText( featureAttributes[i].toString(), &feature, layer ) ) );
15751575
featureElement.appendChild( attributeElement );
15761576
}
15771577

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

25602560
const QgsCoordinateTransform* transform = 0;
2561-
if ( layer && layer->crs() != crs)
2561+
if ( layer && layer->crs() != crs )
25622562
{
25632563
transform = mMapRenderer->transformation( layer );
25642564
}
25652565

25662566
QgsGeometry* geom = feat->geometry();
25672567

25682568
// always add bounding box info if feature contains geometry
2569-
if ( geom && geom->type() != QGis::UnknownGeometry && geom->type() != QGis::NoGeometry)
2570-
{
2571-
QgsRectangle box = feat->geometry()->boundingBox();
2572-
if ( transform )
2573-
{
2574-
box = transform->transformBoundingBox( box );
2575-
}
2576-
2577-
QDomElement bbElem = doc.createElement( "gml:boundedBy" );
2578-
QDomElement boxElem;
2579-
if ( version < 3 )
2580-
{
2581-
boxElem = QgsOgcUtils::rectangleToGMLBox( &box, doc );
2582-
}
2583-
else
2584-
{
2585-
boxElem = QgsOgcUtils::rectangleToGMLEnvelope( &box, doc );
2586-
}
2587-
2588-
if ( crs.isValid() )
2589-
{
2590-
boxElem.setAttribute( "srsName", crs.authid() );
2591-
}
2592-
bbElem.appendChild( boxElem );
2593-
typeNameElement.appendChild( bbElem );
2594-
}
2595-
2596-
if ( withGeom)
2569+
if ( geom && geom->type() != QGis::UnknownGeometry && geom->type() != QGis::NoGeometry )
2570+
{
2571+
QgsRectangle box = feat->geometry()->boundingBox();
2572+
if ( transform )
2573+
{
2574+
box = transform->transformBoundingBox( box );
2575+
}
2576+
2577+
QDomElement bbElem = doc.createElement( "gml:boundedBy" );
2578+
QDomElement boxElem;
2579+
if ( version < 3 )
2580+
{
2581+
boxElem = QgsOgcUtils::rectangleToGMLBox( &box, doc );
2582+
}
2583+
else
2584+
{
2585+
boxElem = QgsOgcUtils::rectangleToGMLEnvelope( &box, doc );
2586+
}
2587+
2588+
if ( crs.isValid() )
2589+
{
2590+
boxElem.setAttribute( "srsName", crs.authid() );
2591+
}
2592+
bbElem.appendChild( boxElem );
2593+
typeNameElement.appendChild( bbElem );
2594+
}
2595+
2596+
if ( withGeom )
25972597
{
25982598
//add geometry column (as gml)
25992599

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

26442644
return typeNameElement;
26452645
}
2646+
2647+
QString QgsWMSServer::replaceValueMapAndRelation( QgsVectorLayer* vl, int idx, const QString& attributeVal )
2648+
{
2649+
if ( !vl )
2650+
{
2651+
return attributeVal;
2652+
}
2653+
2654+
QgsVectorLayer::EditType type = vl->editType( idx );
2655+
if ( type == QgsVectorLayer::ValueMap )
2656+
{
2657+
QMap<QString, QVariant> valueMap = vl->valueMap( idx );
2658+
QMap<QString, QVariant>::const_iterator vmapIt = valueMap.constBegin();
2659+
for ( ; vmapIt != valueMap.constEnd(); ++vmapIt )
2660+
{
2661+
if ( vmapIt.value().toString() == attributeVal )
2662+
{
2663+
return vmapIt.key();
2664+
}
2665+
}
2666+
}
2667+
else if ( type == QgsVectorLayer::ValueRelation )
2668+
{
2669+
QgsVectorLayer::ValueRelationData vrdata = vl->valueRelation( idx );
2670+
//todo...
2671+
}
2672+
return attributeVal;
2673+
}

src/mapserver/qgswmsserver.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,9 @@ class QgsWMSServer
232232
QString typeName,
233233
bool withGeom,
234234
int version ) const;
235+
236+
/**Replaces attribute value with ValueRelation or ValueRelation if defined. Otherwise returns the original value*/
237+
static QString replaceValueMapAndRelation( QgsVectorLayer* vl, int idx, const QString& attributeVal );
235238
};
236239

237240
#endif

0 commit comments

Comments
 (0)