Skip to content

Commit

Permalink
Merge pull request #36733 from elpaso/bugfix-36262-json-export-respec…
Browse files Browse the repository at this point in the history
…t-use-layer-ids

Server: respect "use layer ids" option in json getfeatureinfo
  • Loading branch information
elpaso committed May 27, 2020
2 parents 923072d + d859bb9 commit 2a70569
Show file tree
Hide file tree
Showing 9 changed files with 2,554 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/server/services/wms/qgswmsrenderer.cpp
Expand Up @@ -2279,7 +2279,7 @@ namespace QgsWms

for ( const auto &feature : qgis::as_const( features ) )
{
const QString id = QStringLiteral( "%1.%2" ).arg( layer->name(), QgsJsonUtils::encodeValue( feature.id() ) );
const QString id = QStringLiteral( "%1.%2" ).arg( layerName ).arg( feature.id() );
json["features"].push_back( exporter.exportFeatureToJsonObject( feature, QVariantMap(), id ) );
}
}
Expand All @@ -2298,7 +2298,7 @@ namespace QgsWms
json["features"].push_back(
{
{"type", "Feature" },
{"id", layer->name().toStdString() },
{"id", layerName.toStdString() },
{"properties", properties }
} );
}
Expand Down
37 changes: 35 additions & 2 deletions tests/src/python/test_qgsserver_wms_getfeatureinfo.py
Expand Up @@ -657,7 +657,7 @@ def testGetFeatureInfoGroupedLayers(self):
'&INFO_FORMAT=application/json' +
'&I=0&J=1' +
'&FEATURE_COUNT=10',
'wms_getfeatureinfo_group_name_areas',
'wms_getfeatureinfo_group_name_areas_nested',
'test_project_wms_grouped_nested_layers.qgs',
normalizeJson=True)

Expand All @@ -670,7 +670,7 @@ def testGetFeatureInfoGroupedLayers(self):
'&INFO_FORMAT=application/json' +
'&I=0&J=1' +
'&FEATURE_COUNT=10',
'wms_getfeatureinfo_group_name_areas',
'wms_getfeatureinfo_group_name_areas_nested',
'test_project_wms_grouped_nested_layers.qgs',
normalizeJson=True)

Expand Down Expand Up @@ -752,6 +752,39 @@ def testGetFeatureInfoGroupedLayers(self):
'test_project_wms_grouped_nested_layers.qgs',
normalizeJson=True)

def testGetFeatureInfoJsonUseIdAsLayerName(self):
"""Test GH #36262 where json response + use layer id"""

self.wms_request_compare('GetFeatureInfo',
'&BBOX=44.90139177500000045,8.20335906129666981,44.90148522499999473,8.20364693870333284' +
'&CRS=EPSG:4326' +
'&WIDTH=1568&HEIGHT=509' +
'&LAYERS=testlayer_%C3%A8%C3%A9_cf86cf11_222f_4b62_929c_12cfc82b9774' +
'&STYLES=' +
'&FORMAT=image/jpeg' +
'&QUERY_LAYERS=testlayer_%C3%A8%C3%A9_cf86cf11_222f_4b62_929c_12cfc82b9774' +
'&INFO_FORMAT=application/json' +
'&I=1022&J=269' +
'&FEATURE_COUNT=10',
'wms_getfeatureinfo_json_layer_ids',
'test_project_use_layer_ids.qgs',
normalizeJson=True)

# Raster
self.wms_request_compare('GetFeatureInfo',
'&BBOX=30.1492201749999964,17.81444988978388722,30.2599248249999988,18.15548111021611533' +
'&CRS=EPSG:4326' +
'&WIDTH=1568&HEIGHT=509' +
'&LAYERS=landsat_a7d15b35_ca83_4b23_a9fb_af3fbdd60d15' +
'&STYLES=' +
'&FORMAT=image/jpeg' +
'&QUERY_LAYERS=landsat_a7d15b35_ca83_4b23_a9fb_af3fbdd60d15' +
'&INFO_FORMAT=application/json' +
'&I=769&J=275&FEATURE_COUNT=10',
'wms_getfeatureinfo_json_layer_ids_raster',
'test_project_use_layer_ids.qgs',
normalizeJson=True)

@unittest.skipIf(os.environ.get('TRAVIS', '') == 'true',
"This test cannot run in TRAVIS because it relies on cascading external services")
def testGetFeatureInfoCascadingLayers(self):
Expand Down
2,435 changes: 2,435 additions & 0 deletions tests/testdata/qgis_server/test_project_use_layer_ids.qgs

Large diffs are not rendered by default.

Expand Up @@ -5,7 +5,7 @@ Content-Type: application/json; charset=utf-8
"features": [
{
"geometry": null,
"id": "as_areas.18",
"id": "as-areas-short-name.18",
"properties": {
"bearbeiter": "scholle-b",
"bemerkung": "",
Expand Down
@@ -0,0 +1,37 @@
*****
Content-Type: application/json; charset=utf-8

{
"features": [
{
"geometry": null,
"id": "as-areas-short-name.18",
"properties": {
"bearbeiter": "scholle-b",
"bemerkung": "",
"beschriftung": "",
"datum": "2013-06-11",
"farbe": "255 0 0",
"fid": 18,
"flaeche": 12879.0,
"flaechentyp": "Schraffur",
"gid": 34,
"last_change": "2013-06-11 10:03:45.52301+02",
"name": "",
"schraff_size": "10",
"schraff_size_prt": "30.00",
"schraff_width": "2",
"schraff_width_prt": "6.00",
"schraff_winkel": "45",
"umfang": 758.4703,
"umrissfarbe": "0 0 0",
"umrissstaerke": "1",
"umrissstaerke_prt": "3.00",
"umrisstyp": "durchgezogen",
"veranstaltung": ""
},
"type": "Feature"
}
],
"type": "FeatureCollection"
}
Expand Up @@ -18,7 +18,7 @@ Content-Type: application/json; charset=utf-8
},
{
"geometry": null,
"id": "as_areas.18",
"id": "as-areas-short-name.18",
"properties": {
"bearbeiter": "scholle-b",
"bemerkung": "",
Expand Down Expand Up @@ -47,7 +47,7 @@ Content-Type: application/json; charset=utf-8
},
{
"geometry": null,
"id": "as_areas_query_copy.18",
"id": "as-areas-short-name-query-copy.18",
"properties": {
"bearbeiter": "scholle-b",
"bemerkung": "",
Expand Down
Expand Up @@ -5,7 +5,7 @@ Content-Type: application/json; charset=utf-8
"features": [
{
"geometry": null,
"id": "as_areas_query_copy.18",
"id": "as-areas-short-name-query-copy.18",
"properties": {
"bearbeiter": "scholle-b",
"bemerkung": "",
Expand Down
18 changes: 18 additions & 0 deletions tests/testdata/qgis_server/wms_getfeatureinfo_json_layer_ids.txt
@@ -0,0 +1,18 @@
Content-Length: 299
Content-Type: application/json; charset=utf-8

{
"features": [
{
"geometry": null,
"id": "testlayer_èé_cf86cf11_222f_4b62_929c_12cfc82b9774.1",
"properties": {
"alias_id": 2,
"alias_name": "two",
"utf8nameè": "two àò"
},
"type": "Feature"
}
],
"type": "FeatureCollection"
}
@@ -0,0 +1,23 @@
Content-Length: 402
Content-Type: application/json; charset=utf-8

{
"features": [
{
"id": "landsat_a7d15b35_ca83_4b23_a9fb_af3fbdd60d15",
"properties": {
"Band 1": "127",
"Band 2": "142",
"Band 3": "96",
"Band 4": "70",
"Band 5": "81",
"Band 6": "119",
"Band 7": "146",
"Band 8": "199",
"Band 9": "160"
},
"type": "Feature"
}
],
"type": "FeatureCollection"
}

0 comments on commit 2a70569

Please sign in to comment.