Skip to content

Commit

Permalink
Merge pull request #32386 from pblottiere/fix_crs_json
Browse files Browse the repository at this point in the history
Use CRS in WMS GetFeatureInfo when info_format is in json Fixes #32326
  • Loading branch information
pblottiere committed Oct 31, 2019
2 parents 2c65ac5 + 624ae03 commit 292008f
Show file tree
Hide file tree
Showing 12 changed files with 777 additions and 2 deletions.
8 changes: 8 additions & 0 deletions python/core/auto_generated/qgsjsonutils.sip.in
Expand Up @@ -160,6 +160,14 @@ Returns the source CRS for feature geometries. The source CRS must be set if geo
correctly automatically reprojected to WGS 84, to match GeoJSON specifications.

.. seealso:: :py:func:`setSourceCrs`
%End

void setTransformGeometries( bool activate );
%Docstring
Sets whether geometries should be transformed in EPSG 4326 (default
behavior) or just keep as it is.

.. versionadded:: 3.12
%End

void setAttributes( const QgsAttributeList &attributes );
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsjsonutils.cpp
Expand Up @@ -107,7 +107,7 @@ json QgsJsonExporter::exportFeatureToJsonObject( const QgsFeature &feature, cons
try
{
QgsGeometry transformed = geom;
if ( transformed.transform( mTransform ) == 0 )
if ( mTransformGeometries && transformed.transform( mTransform ) == 0 )
geom = transformed;
}
catch ( QgsCsException &cse )
Expand Down
9 changes: 9 additions & 0 deletions src/core/qgsjsonutils.h
Expand Up @@ -153,6 +153,13 @@ class CORE_EXPORT QgsJsonExporter
*/
QgsCoordinateReferenceSystem sourceCrs() const;

/**
* Sets whether geometries should be transformed in EPSG 4326 (default
* behavior) or just keep as it is.
* \since QGIS 3.12
*/
void setTransformGeometries( bool activate ) { mTransformGeometries = activate; }

/**
* Sets the list of attributes to include in the JSON exports.
* \param attributes list of attribute indexes, or an empty list to include all
Expand Down Expand Up @@ -270,6 +277,8 @@ class CORE_EXPORT QgsJsonExporter
QgsCoordinateTransform mTransform;

bool mAttributeDisplayName = false;

bool mTransformGeometries = true;
};

/**
Expand Down
1 change: 1 addition & 0 deletions src/server/services/wms/qgswmsrenderer.cpp
Expand Up @@ -2241,6 +2241,7 @@ namespace QgsWms
exporter.setAttributeDisplayName( true );
exporter.setAttributes( attributes );
exporter.setIncludeGeometry( withGeometry );
exporter.setTransformGeometries( false );

for ( const auto &feature : qgis::as_const( features ) )
{
Expand Down
15 changes: 14 additions & 1 deletion tests/src/python/test_qgsserver_wms_getfeatureinfo.py
Expand Up @@ -473,7 +473,7 @@ def testGetFeatureInfoJSON(self):
'wms_getfeatureinfo_multiple_json',
normalizeJson=True)

# simple test with geometry
# simple test with geometry with underlying layer in 3857
self.wms_request_compare('GetFeatureInfo',
'&layers=testlayer%20%C3%A8%C3%A9&styles=&' +
'info_format=application%2Fjson&transparent=true&' +
Expand All @@ -482,6 +482,19 @@ def testGetFeatureInfoJSON(self):
'query_layers=testlayer%20%C3%A8%C3%A9&X=190&Y=320&' +
'with_geometry=true',
'wms_getfeatureinfo_geometry_json',
'test_project_epsg3857.qgs',
normalizeJson=True)

# simple test with geometry with underlying layer in 4326
self.wms_request_compare('GetFeatureInfo',
'&layers=testlayer%20%C3%A8%C3%A9&styles=&' +
'info_format=application%2Fjson&transparent=true&' +
'width=600&height=400&srs=EPSG%3A3857&bbox=913190.6389747962%2C' +
'5606005.488876367%2C913235.426296057%2C5606035.347090538&' +
'query_layers=testlayer%20%C3%A8%C3%A9&X=190&Y=320&' +
'with_geometry=true',
'wms_getfeatureinfo_geometry_json',
'test_project.qgs',
normalizeJson=True)

# test with alias
Expand Down

0 comments on commit 292008f

Please sign in to comment.