Skip to content

Commit 1e54c6b

Browse files
committedMay 26, 2020
Server: respect "use layer ids" option in json getfeatureinfo
Fixes #36262
1 parent 24ec1d9 commit 1e54c6b

File tree

6 files changed

+2513
-4
lines changed

6 files changed

+2513
-4
lines changed
 

‎src/server/services/wms/qgswmsrenderer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2279,7 +2279,7 @@ namespace QgsWms
22792279

22802280
for ( const auto &feature : qgis::as_const( features ) )
22812281
{
2282-
const QString id = QStringLiteral( "%1.%2" ).arg( layer->name(), QgsJsonUtils::encodeValue( feature.id() ) );
2282+
const QString id = QStringLiteral( "%1.%2" ).arg( layerName ).arg( feature.id() );
22832283
json["features"].push_back( exporter.exportFeatureToJsonObject( feature, QVariantMap(), id ) );
22842284
}
22852285
}
@@ -2298,7 +2298,7 @@ namespace QgsWms
22982298
json["features"].push_back(
22992299
{
23002300
{"type", "Feature" },
2301-
{"id", layer->name().toStdString() },
2301+
{"id", layerName.toStdString() },
23022302
{"properties", properties }
23032303
} );
23042304
}

‎tests/src/python/test_qgsserver_wms_getfeatureinfo.py

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
class TestQgsServerWMSGetFeatureInfo(TestQgsServerWMSTestBase):
4141
"""QGIS Server WMS Tests for GetFeatureInfo request"""
4242

43-
# regenerate_reference = True
43+
#regenerate_reference = True
4444

4545
def testGetFeatureInfo(self):
4646
# Test getfeatureinfo response xml
@@ -752,6 +752,39 @@ def testGetFeatureInfoGroupedLayers(self):
752752
'test_project_wms_grouped_nested_layers.qgs',
753753
normalizeJson=True)
754754

755+
def testGetFeatureInfoJsonUseIdAsLayerName(self):
756+
"""Test GH #36262 where json response + use layer id"""
757+
758+
self.wms_request_compare('GetFeatureInfo',
759+
'&BBOX=44.90139177500000045,8.20335906129666981,44.90148522499999473,8.20364693870333284' +
760+
'&CRS=EPSG:4326' +
761+
'&WIDTH=1568&HEIGHT=509' +
762+
'&LAYERS=testlayer_%C3%A8%C3%A9_cf86cf11_222f_4b62_929c_12cfc82b9774' +
763+
'&STYLES=' +
764+
'&FORMAT=image/jpeg' +
765+
'&QUERY_LAYERS=testlayer_%C3%A8%C3%A9_cf86cf11_222f_4b62_929c_12cfc82b9774' +
766+
'&INFO_FORMAT=application/json' +
767+
'&I=1022&J=269' +
768+
'&FEATURE_COUNT=10',
769+
'wms_getfeatureinfo_json_layer_ids',
770+
'test_project_use_layer_ids.qgs',
771+
normalizeJson=True)
772+
773+
# Raster
774+
self.wms_request_compare('GetFeatureInfo',
775+
'&BBOX=30.1492201749999964,17.81444988978388722,30.2599248249999988,18.15548111021611533' +
776+
'&CRS=EPSG:4326' +
777+
'&WIDTH=1568&HEIGHT=509' +
778+
'&LAYERS=landsat_a7d15b35_ca83_4b23_a9fb_af3fbdd60d15' +
779+
'&STYLES=' +
780+
'&FORMAT=image/jpeg' +
781+
'&QUERY_LAYERS=landsat_a7d15b35_ca83_4b23_a9fb_af3fbdd60d15' +
782+
'&INFO_FORMAT=application/json' +
783+
'&I=769&J=275&FEATURE_COUNT=10',
784+
'wms_getfeatureinfo_json_layer_ids_raster',
785+
'test_project_use_layer_ids.qgs',
786+
normalizeJson=True)
787+
755788
@unittest.skipIf(os.environ.get('TRAVIS', '') == 'true',
756789
"This test cannot run in TRAVIS because it relies on cascading external services")
757790
def testGetFeatureInfoCascadingLayers(self):

‎tests/testdata/qgis_server/test_project_use_layer_ids.qgs

Lines changed: 2435 additions & 0 deletions
Large diffs are not rendered by default.

‎tests/testdata/qgis_server/wms_getfeatureinfo_group_name_areas.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Content-Type: application/json; charset=utf-8
55
"features": [
66
{
77
"geometry": null,
8-
"id": "as_areas.18",
8+
"id": "as-areas-short-name.18",
99
"properties": {
1010
"bearbeiter": "scholle-b",
1111
"bemerkung": "",
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Content-Length: 299
2+
Content-Type: application/json; charset=utf-8
3+
4+
{
5+
"features": [
6+
{
7+
"geometry": null,
8+
"id": "testlayer_èé_cf86cf11_222f_4b62_929c_12cfc82b9774.1",
9+
"properties": {
10+
"alias_id": 2,
11+
"alias_name": "two",
12+
"utf8nameè": "two àò"
13+
},
14+
"type": "Feature"
15+
}
16+
],
17+
"type": "FeatureCollection"
18+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
Content-Length: 402
2+
Content-Type: application/json; charset=utf-8
3+
4+
{
5+
"features": [
6+
{
7+
"id": "landsat_a7d15b35_ca83_4b23_a9fb_af3fbdd60d15",
8+
"properties": {
9+
"Band 1": "127",
10+
"Band 2": "142",
11+
"Band 3": "96",
12+
"Band 4": "70",
13+
"Band 5": "81",
14+
"Band 6": "119",
15+
"Band 7": "146",
16+
"Band 8": "199",
17+
"Band 9": "160"
18+
},
19+
"type": "Feature"
20+
}
21+
],
22+
"type": "FeatureCollection"
23+
}

0 commit comments

Comments
 (0)
Please sign in to comment.