Skip to content

Commit

Permalink
[Bugfix][Server] In WMS GetFeatureInfo CRS param not mandatory when F…
Browse files Browse the repository at this point in the history
…ILTER param

The CRS parameter is considered as mandatory in GetFeatureInfo even if the FILTER parameter is used without I and J parameters.

To fix it, set a fake CRS in the parameter when I/J and X/Y parameters are not defined and FILTER parameter is defined.
  • Loading branch information
rldhont committed Mar 21, 2019
1 parent abaa11d commit 98857af
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 3 deletions.
16 changes: 14 additions & 2 deletions src/server/services/wms/qgswmsrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -951,8 +951,16 @@ namespace QgsWms
QgsMapSettings mapSettings;
std::unique_ptr<QImage> outputImage( createImage( imageWidth, imageHeight ) );

// The CRS parameter is considered as mandatory in configureMapSettings
// but in the case of filter parameter, CRS parameter has not to be mandatory
bool mandatoryCrsParam = true;
if ( filtersDefined && !ijDefined && !xyDefined && mWmsParameters.crs().isEmpty() )
{
mandatoryCrsParam = false;
}

// configure map settings (background, DPI, ...)
configureMapSettings( outputImage.get(), mapSettings );
configureMapSettings( outputImage.get(), mapSettings, mandatoryCrsParam );

QgsMessageLog::logMessage( "mapSettings.destinationCrs(): " + mapSettings.destinationCrs().authid() );
QgsMessageLog::logMessage( "mapSettings.extent(): " + mapSettings.extent().toString() );
Expand Down Expand Up @@ -1087,7 +1095,7 @@ namespace QgsWms
return image.release();
}

void QgsRenderer::configureMapSettings( const QPaintDevice *paintDevice, QgsMapSettings &mapSettings ) const
void QgsRenderer::configureMapSettings( const QPaintDevice *paintDevice, QgsMapSettings &mapSettings, bool mandatoryCrsParam ) const
{
if ( !paintDevice )
{
Expand All @@ -1110,6 +1118,10 @@ namespace QgsWms
crs = QString( "EPSG:4326" );
mapExtent.invert();
}
else if ( crs.isEmpty() && !mandatoryCrsParam )
{
crs = QString( "EPSG:4326" );
}

QgsCoordinateReferenceSystem outputCRS;

Expand Down
3 changes: 2 additions & 1 deletion src/server/services/wms/qgswmsrenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,10 @@ namespace QgsWms
* Configures map settings according to WMS parameters.
* \param paintDevice The device that is used for painting (for dpi)
* \param mapSettings Map settings to use for rendering
* \param mandatoryCrsParam does the CRS parameter has to be considered mandatory
* may throw an exception
*/
void configureMapSettings( const QPaintDevice *paintDevice, QgsMapSettings &mapSettings ) const;
void configureMapSettings( const QPaintDevice *paintDevice, QgsMapSettings &mapSettings, bool mandatoryCrsParam = true ) const;

QDomDocument featureInfoDocument( QList<QgsMapLayer *> &layers, const QgsMapSettings &mapSettings,
const QImage *outputImage, const QString &version ) const;
Expand Down
10 changes: 10 additions & 0 deletions tests/src/python/test_qgsserver_wms_getfeatureinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,16 @@ def testGetFeatureInfoFilter(self):
urllib.parse.quote(':"NAME" = \'two\''),
'wms_getfeatureinfo_filter_no_width')

# Test a filter without CRS parameter
self.wms_request_compare('GetFeatureInfo',
'&layers=testlayer%20%C3%A8%C3%A9&' +
'INFO_FORMAT=text%2Fxml&' +
'width=600&height=400&' +
'query_layers=testlayer%20%C3%A8%C3%A9&' +
'FEATURE_COUNT=10&FILTER=testlayer%20%C3%A8%C3%A9' +
urllib.parse.quote(':"NAME" = \'two\''),
'wms_getfeatureinfo_filter_no_crs')

def testGetFeatureInfoTolerance(self):
self.wms_request_compare('GetFeatureInfo',
'&layers=layer3&styles=&' +
Expand Down
14 changes: 14 additions & 0 deletions tests/testdata/qgis_server/wms_getfeatureinfo_filter_no_crs.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Content-Length: 577
Content-Type: text/xml; charset=utf-8

<GetFeatureInfoResponse>
<BoundingBox maxy="44.90143568" maxx="8.20354699" miny="44.90143568" CRS="EPSG:4326" minx="8.20354699"/>
<Layer name="testlayer èé">
<Feature id="1">
<Attribute value="2" name="id"/>
<Attribute value="two" name="name"/>
<Attribute value="two àò" name="utf8nameè"/>
<BoundingBox maxy="44.9014" maxx="8.2035" miny="44.9014" CRS="EPSG:4326" minx="8.2035"/>
</Feature>
</Layer>
</GetFeatureInfoResponse>

0 comments on commit 98857af

Please sign in to comment.