@@ -1052,13 +1052,38 @@ int QgsWMSServer::getFeatureInfo( QDomDocument& result, QString version )
1052
1052
1053
1053
if ( featuresRect )
1054
1054
{
1055
- QDomElement bBoxElem = result.createElement ( " BoundingBox" );
1056
- bBoxElem.setAttribute ( " CRS" , mMapRenderer ->destinationCrs ().authid () );
1057
- bBoxElem.setAttribute ( " minx" , QString::number ( featuresRect->xMinimum () ) );
1058
- bBoxElem.setAttribute ( " maxx" , QString::number ( featuresRect->xMaximum () ) );
1059
- bBoxElem.setAttribute ( " miny" , QString::number ( featuresRect->yMinimum () ) );
1060
- bBoxElem.setAttribute ( " maxy" , QString::number ( featuresRect->yMaximum () ) );
1061
- getFeatureInfoElement.insertBefore ( bBoxElem, QDomNode () ); // insert as first child
1055
+ if ( infoFormat.startsWith ( " application/vnd.ogc.gml" ) )
1056
+ {
1057
+ QDomElement bBoxElem = result.createElement ( " gml:boundedBy" );
1058
+ QDomElement boxElem;
1059
+ int gmlVersion = infoFormat.startsWith ( " application/vnd.ogc.gml/3" ) ? 3 : 2 ;
1060
+ if ( gmlVersion < 3 )
1061
+ {
1062
+ boxElem = QgsOgcUtils::rectangleToGMLBox ( featuresRect, result );
1063
+ }
1064
+ else
1065
+ {
1066
+ boxElem = QgsOgcUtils::rectangleToGMLEnvelope ( featuresRect, result );
1067
+ }
1068
+
1069
+ QgsCoordinateReferenceSystem crs = mMapRenderer ->destinationCrs ();
1070
+ if ( crs.isValid () )
1071
+ {
1072
+ boxElem.setAttribute ( " srsName" , crs.authid () );
1073
+ }
1074
+ bBoxElem.appendChild ( boxElem );
1075
+ getFeatureInfoElement.insertBefore ( bBoxElem, QDomNode () ); // insert as first child
1076
+ }
1077
+ else
1078
+ {
1079
+ QDomElement bBoxElem = result.createElement ( " BoundingBox" );
1080
+ bBoxElem.setAttribute ( " CRS" , mMapRenderer ->destinationCrs ().authid () );
1081
+ bBoxElem.setAttribute ( " minx" , QString::number ( featuresRect->xMinimum () ) );
1082
+ bBoxElem.setAttribute ( " maxx" , QString::number ( featuresRect->xMaximum () ) );
1083
+ bBoxElem.setAttribute ( " miny" , QString::number ( featuresRect->yMinimum () ) );
1084
+ bBoxElem.setAttribute ( " maxy" , QString::number ( featuresRect->yMaximum () ) );
1085
+ getFeatureInfoElement.insertBefore ( bBoxElem, QDomNode () ); // insert as first child
1086
+ }
1062
1087
}
1063
1088
1064
1089
if ( sia2045 && infoFormat.compare ( " text/xml" , Qt::CaseInsensitive ) == 0 )
@@ -1460,7 +1485,8 @@ int QgsWMSServer::featureInfoFromVectorLayer( QgsVectorLayer* layer,
1460
1485
const QSet<QString>& excludedAttributes = layer->excludeAttributesWMS ();
1461
1486
1462
1487
QgsFeatureRequest fReq ;
1463
- fReq .setFlags ((( addWktGeometry || featureBBox ) ? QgsFeatureRequest::NoFlags : QgsFeatureRequest::NoGeometry ) | QgsFeatureRequest::ExactIntersect );
1488
+ bool hasGeometry = addWktGeometry || featureBBox;
1489
+ fReq .setFlags ((( hasGeometry ) ? QgsFeatureRequest::NoFlags : QgsFeatureRequest::NoGeometry ) | QgsFeatureRequest::ExactIntersect );
1464
1490
if ( !searchRect.isEmpty () )
1465
1491
{
1466
1492
fReq .setFilterRect ( searchRect );
@@ -1491,12 +1517,34 @@ int QgsWMSServer::featureInfoFromVectorLayer( QgsVectorLayer* layer,
1491
1517
continue ;
1492
1518
}
1493
1519
1520
+ QgsRectangle box;
1521
+ if ( hasGeometry )
1522
+ {
1523
+ box = mapRender->layerExtentToOutputExtent ( layer, feature.geometry ()->boundingBox () );
1524
+ if ( featureBBox ) // extend feature info bounding box if requested
1525
+ {
1526
+ if ( featureBBox->isEmpty () )
1527
+ {
1528
+ *featureBBox = box;
1529
+ }
1530
+ else
1531
+ {
1532
+ featureBBox->combineExtentWith ( &box );
1533
+ }
1534
+ }
1535
+ }
1536
+
1537
+ QgsCoordinateReferenceSystem outputCrs = layer->crs ();
1538
+ if ( hasGeometry && layer->crs () != mapRender->destinationCrs () && mapRender->hasCrsTransformEnabled () )
1539
+ {
1540
+ outputCrs = mapRender->destinationCrs ();
1541
+ }
1542
+
1494
1543
if ( infoFormat == " application/vnd.ogc.gml" )
1495
1544
{
1496
- QgsCoordinateReferenceSystem layerCrs = layer->crs ();
1497
- bool withGeom = layer->wkbType () != QGis::WKBNoGeometry;
1545
+ bool withGeom = layer->wkbType () != QGis::WKBNoGeometry && addWktGeometry;
1498
1546
int version = infoFormat.startsWith ( " application/vnd.ogc.gml/3" ) ? 3 : 2 ;
1499
- QDomElement elem = createFeatureGML ( &feature, layer, infoDocument, layerCrs , layer->name (), withGeom, version );
1547
+ QDomElement elem = createFeatureGML ( &feature, layer, infoDocument, outputCrs , layer->name (), withGeom, version );
1500
1548
QDomElement featureMemberElem = infoDocument.createElement ( " gml:featureMember" /* wfs:FeatureMember*/ );
1501
1549
featureMemberElem.appendChild ( elem );
1502
1550
layerElement.appendChild ( featureMemberElem );
@@ -1527,37 +1575,36 @@ int QgsWMSServer::featureInfoFromVectorLayer( QgsVectorLayer* layer,
1527
1575
featureElement.appendChild ( attributeElement );
1528
1576
}
1529
1577
1530
- // also append the wkt geometry as an attribute
1531
- QgsGeometry* geom = feature.geometry ();
1532
- if ( addWktGeometry && geom )
1533
- {
1534
- QDomElement geometryElement = infoDocument.createElement ( " Attribute" );
1535
- geometryElement.setAttribute ( " name" , " geometry" );
1536
- geometryElement.setAttribute ( " value" , geom->exportToWkt () );
1537
- geometryElement.setAttribute ( " type" , " derived" );
1538
- featureElement.appendChild ( geometryElement );
1539
- }
1540
- if ( featureBBox && geom && mapRender ) // extend feature info bounding box if requested
1578
+ // append feature bounding box to feature info xml
1579
+ if ( hasGeometry && mapRender )
1541
1580
{
1542
- QgsRectangle box = mapRender->layerExtentToOutputExtent ( layer, geom->boundingBox () );
1543
- if ( featureBBox->isEmpty () )
1544
- {
1545
- *featureBBox = box;
1546
- }
1547
- else
1548
- {
1549
- featureBBox->combineExtentWith ( &box );
1550
- }
1551
-
1552
- // append feature bounding box to feature info xml
1553
1581
QDomElement bBoxElem = infoDocument.createElement ( " BoundingBox" );
1554
- bBoxElem.setAttribute ( version == " 1.1.1" ? " SRS" : " CRS" , mapRender-> destinationCrs () .authid () );
1582
+ bBoxElem.setAttribute ( version == " 1.1.1" ? " SRS" : " CRS" , outputCrs .authid () );
1555
1583
bBoxElem.setAttribute ( " minx" , QString::number ( box.xMinimum () ) );
1556
1584
bBoxElem.setAttribute ( " maxx" , QString::number ( box.xMaximum () ) );
1557
1585
bBoxElem.setAttribute ( " miny" , QString::number ( box.yMinimum () ) );
1558
1586
bBoxElem.setAttribute ( " maxy" , QString::number ( box.yMaximum () ) );
1559
1587
featureElement.appendChild ( bBoxElem );
1560
1588
}
1589
+
1590
+ // also append the wkt geometry as an attribute
1591
+ if ( addWktGeometry && hasGeometry )
1592
+ {
1593
+ QgsGeometry* geom = feature.geometry ();
1594
+ if ( layer->crs () != outputCrs )
1595
+ {
1596
+ const QgsCoordinateTransform *transform = mapRender->transformation ( layer );
1597
+ if ( transform )
1598
+ {
1599
+ geom->transform ( *transform );
1600
+ }
1601
+ }
1602
+ QDomElement geometryElement = infoDocument.createElement ( " Attribute" );
1603
+ geometryElement.setAttribute ( " name" , " geometry" );
1604
+ geometryElement.setAttribute ( " value" , geom->exportToWkt () );
1605
+ geometryElement.setAttribute ( " type" , " derived" );
1606
+ featureElement.appendChild ( geometryElement );
1607
+ }
1561
1608
}
1562
1609
}
1563
1610
@@ -2510,10 +2557,50 @@ QDomElement QgsWMSServer::createFeatureGML(
2510
2557
QDomElement typeNameElement = doc.createElement ( " qgs:" + typeName /* qgs:%TYPENAME%*/ );
2511
2558
typeNameElement.setAttribute ( " fid" , typeName + " ." + QString::number ( feat->id () ) );
2512
2559
2513
- if ( withGeom )
2560
+ const QgsCoordinateTransform* transform = 0 ;
2561
+ if ( layer && layer->crs () != crs)
2562
+ {
2563
+ transform = mMapRenderer ->transformation ( layer );
2564
+ }
2565
+
2566
+ QgsGeometry* geom = feat->geometry ();
2567
+
2568
+ // 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)
2514
2597
{
2515
2598
// add geometry column (as gml)
2516
- QgsGeometry* geom = feat->geometry ();
2599
+
2600
+ if ( transform )
2601
+ {
2602
+ geom->transform ( *transform );
2603
+ }
2517
2604
2518
2605
QDomElement geomElem = doc.createElement ( " qgs:geometry" );
2519
2606
QDomElement gmlElem;
@@ -2528,27 +2615,10 @@ QDomElement QgsWMSServer::createFeatureGML(
2528
2615
2529
2616
if ( !gmlElem.isNull () )
2530
2617
{
2531
- QgsRectangle box = geom->boundingBox ();
2532
- QDomElement bbElem = doc.createElement ( " gml:boundedBy" );
2533
- QDomElement boxElem;
2534
- if ( version < 3 )
2535
- {
2536
- boxElem = QgsOgcUtils::rectangleToGMLBox ( &box, doc );
2537
- }
2538
- else
2539
- {
2540
- boxElem = QgsOgcUtils::rectangleToGMLEnvelope ( &box, doc );
2541
- }
2542
-
2543
2618
if ( crs.isValid () )
2544
2619
{
2545
- boxElem.setAttribute ( " srsName" , crs.authid () );
2546
2620
gmlElem.setAttribute ( " srsName" , crs.authid () );
2547
2621
}
2548
-
2549
- bbElem.appendChild ( boxElem );
2550
- typeNameElement.appendChild ( bbElem );
2551
-
2552
2622
geomElem.appendChild ( gmlElem );
2553
2623
typeNameElement.appendChild ( geomElem );
2554
2624
}
0 commit comments