Skip to content

Commit 2a70569

Browse files
authoredMay 27, 2020
Merge pull request #36733 from elpaso/bugfix-36262-json-export-respect-use-layer-ids
Server: respect "use layer ids" option in json getfeatureinfo
2 parents 923072d + d859bb9 commit 2a70569

9 files changed

+2554
-8
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: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,7 @@ def testGetFeatureInfoGroupedLayers(self):
657657
'&INFO_FORMAT=application/json' +
658658
'&I=0&J=1' +
659659
'&FEATURE_COUNT=10',
660-
'wms_getfeatureinfo_group_name_areas',
660+
'wms_getfeatureinfo_group_name_areas_nested',
661661
'test_project_wms_grouped_nested_layers.qgs',
662662
normalizeJson=True)
663663

@@ -670,7 +670,7 @@ def testGetFeatureInfoGroupedLayers(self):
670670
'&INFO_FORMAT=application/json' +
671671
'&I=0&J=1' +
672672
'&FEATURE_COUNT=10',
673-
'wms_getfeatureinfo_group_name_areas',
673+
'wms_getfeatureinfo_group_name_areas_nested',
674674
'test_project_wms_grouped_nested_layers.qgs',
675675
normalizeJson=True)
676676

@@ -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_cities.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: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
*****
2+
Content-Type: application/json; charset=utf-8
3+
4+
{
5+
"features": [
6+
{
7+
"geometry": null,
8+
"id": "as-areas-short-name.18",
9+
"properties": {
10+
"bearbeiter": "scholle-b",
11+
"bemerkung": "",
12+
"beschriftung": "",
13+
"datum": "2013-06-11",
14+
"farbe": "255 0 0",
15+
"fid": 18,
16+
"flaeche": 12879.0,
17+
"flaechentyp": "Schraffur",
18+
"gid": 34,
19+
"last_change": "2013-06-11 10:03:45.52301+02",
20+
"name": "",
21+
"schraff_size": "10",
22+
"schraff_size_prt": "30.00",
23+
"schraff_width": "2",
24+
"schraff_width_prt": "6.00",
25+
"schraff_winkel": "45",
26+
"umfang": 758.4703,
27+
"umrissfarbe": "0 0 0",
28+
"umrissstaerke": "1",
29+
"umrissstaerke_prt": "3.00",
30+
"umrisstyp": "durchgezogen",
31+
"veranstaltung": ""
32+
},
33+
"type": "Feature"
34+
}
35+
],
36+
"type": "FeatureCollection"
37+
}

‎tests/testdata/qgis_server/wms_getfeatureinfo_group_name_top.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Content-Type: application/json; charset=utf-8
1818
},
1919
{
2020
"geometry": null,
21-
"id": "as_areas.18",
21+
"id": "as-areas-short-name.18",
2222
"properties": {
2323
"bearbeiter": "scholle-b",
2424
"bemerkung": "",
@@ -47,7 +47,7 @@ Content-Type: application/json; charset=utf-8
4747
},
4848
{
4949
"geometry": null,
50-
"id": "as_areas_query_copy.18",
50+
"id": "as-areas-short-name-query-copy.18",
5151
"properties": {
5252
"bearbeiter": "scholle-b",
5353
"bemerkung": "",

‎tests/testdata/qgis_server/wms_getfeatureinfo_group_query_child.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_query_copy.18",
8+
"id": "as-areas-short-name-query-copy.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.