Skip to content

Commit 2acbbc3

Browse files
authoredMar 22, 2019
Merge pull request #9595 from rldhont/backport-9525-9526-forwardport-9418-on-release-3_6
Backport 9525 9526 forwardport 9418 on release 3 6 [Server]
2 parents fc258ab + 88fa485 commit 2acbbc3

12 files changed

+127
-28
lines changed
 

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

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,28 +35,36 @@ namespace QgsWms
3535
QgsWmsParameters wmsParameters( QUrlQuery( request.url() ) );
3636
QgsRenderer renderer( serverIface, project, wmsParameters );
3737

38-
QString format = params.value( "FORMAT" );
38+
QString format = params.value( QStringLiteral( "FORMAT" ) );
3939
QString contentType;
4040

4141
// GetPrint supports svg/png/pdf
4242
if ( format.compare( QLatin1String( "image/png" ), Qt::CaseInsensitive ) == 0 ||
4343
format.compare( QLatin1String( "png" ), Qt::CaseInsensitive ) == 0 )
4444
{
45-
format = "png";
46-
contentType = "image/png";
45+
format = QStringLiteral( "png" );
46+
contentType = QStringLiteral( "image/png" );
47+
}
48+
else if ( format.compare( QLatin1String( "image/jpg" ), Qt::CaseInsensitive ) == 0 ||
49+
format.compare( QLatin1String( "image/jpeg" ), Qt::CaseInsensitive ) == 0 ||
50+
format.compare( QLatin1String( "jpg" ), Qt::CaseInsensitive ) == 0 ||
51+
format.compare( QLatin1String( "jpeg" ), Qt::CaseInsensitive ) == 0 )
52+
{
53+
format = QStringLiteral( "jpg" );
54+
contentType = QStringLiteral( "image/jpeg" );
4755
}
4856
else if ( format.compare( QLatin1String( "image/svg" ), Qt::CaseInsensitive ) == 0 ||
4957
format.compare( QLatin1String( "image/svg+xml" ), Qt::CaseInsensitive ) == 0 ||
5058
format.compare( QLatin1String( "svg" ), Qt::CaseInsensitive ) == 0 )
5159
{
52-
format = "svg";
53-
contentType = "image/svg+xml";
60+
format = QStringLiteral( "svg" );
61+
contentType = QStringLiteral( "image/svg+xml" );
5462
}
5563
else if ( format.compare( QLatin1String( "application/pdf" ), Qt::CaseInsensitive ) == 0 ||
5664
format.compare( QLatin1String( "pdf" ), Qt::CaseInsensitive ) == 0 )
5765
{
58-
format = "pdf";
59-
contentType = "application/pdf";
66+
format = QStringLiteral( "pdf" );
67+
contentType = QStringLiteral( "application/pdf" );
6068
}
6169
else
6270
{

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,8 +1085,16 @@ namespace QgsWms
10851085
QgsMapSettings mapSettings;
10861086
std::unique_ptr<QImage> outputImage( createImage( imageWidth, imageHeight ) );
10871087

1088+
// The CRS parameter is considered as mandatory in configureMapSettings
1089+
// but in the case of filter parameter, CRS parameter has not to be mandatory
1090+
bool mandatoryCrsParam = true;
1091+
if ( filtersDefined && !ijDefined && !xyDefined && mWmsParameters.crs().isEmpty() )
1092+
{
1093+
mandatoryCrsParam = false;
1094+
}
1095+
10881096
// configure map settings (background, DPI, ...)
1089-
configureMapSettings( outputImage.get(), mapSettings );
1097+
configureMapSettings( outputImage.get(), mapSettings, mandatoryCrsParam );
10901098

10911099
QgsMessageLog::logMessage( "mapSettings.destinationCrs(): " + mapSettings.destinationCrs().authid() );
10921100
QgsMessageLog::logMessage( "mapSettings.extent(): " + mapSettings.extent().toString() );
@@ -1223,7 +1231,7 @@ namespace QgsWms
12231231
return image.release();
12241232
}
12251233

1226-
void QgsRenderer::configureMapSettings( const QPaintDevice *paintDevice, QgsMapSettings &mapSettings ) const
1234+
void QgsRenderer::configureMapSettings( const QPaintDevice *paintDevice, QgsMapSettings &mapSettings, bool mandatoryCrsParam ) const
12271235
{
12281236
if ( !paintDevice )
12291237
{
@@ -1246,6 +1254,10 @@ namespace QgsWms
12461254
crs = QString( "EPSG:4326" );
12471255
mapExtent.invert();
12481256
}
1257+
else if ( crs.isEmpty() && !mandatoryCrsParam )
1258+
{
1259+
crs = QString( "EPSG:4326" );
1260+
}
12491261

12501262
QgsCoordinateReferenceSystem outputCRS;
12511263

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,10 @@ namespace QgsWms
188188
* Configures map settings according to WMS parameters.
189189
* \param paintDevice The device that is used for painting (for dpi)
190190
* \param mapSettings Map settings to use for rendering
191+
* \param mandatoryCrsParam does the CRS parameter has to be considered mandatory
191192
* may throw an exception
192193
*/
193-
void configureMapSettings( const QPaintDevice *paintDevice, QgsMapSettings &mapSettings ) const;
194+
void configureMapSettings( const QPaintDevice *paintDevice, QgsMapSettings &mapSettings, bool mandatoryCrsParam = true ) const;
194195

195196
QDomDocument featureInfoDocument( QList<QgsMapLayer *> &layers, const QgsMapSettings &mapSettings,
196197
const QImage *outputImage, const QString &version ) const;

‎tests/src/python/test_qgsserver.py

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -176,12 +176,20 @@ def _result(self, data):
176176

177177
return data[1], headers
178178

179-
def _img_diff(self, image, control_image, max_diff, max_size_diff=QSize()):
180-
temp_image = os.path.join(tempfile.gettempdir(), "%s_result.png" % control_image)
179+
def _img_diff(self, image, control_image, max_diff, max_size_diff=QSize(), outputJpg=False):
180+
181+
extFile = 'png'
182+
if outputJpg:
183+
extFile = 'jpg'
184+
185+
temp_image = os.path.join(tempfile.gettempdir(), "%s_result.%s" % (control_image, extFile))
181186

182187
with open(temp_image, "wb") as f:
183188
f.write(image)
184189

190+
if outputJpg:
191+
return (True, "QgsRenderChecker can't be used for JPG images")
192+
185193
control = QgsRenderChecker()
186194
control.setControlPathPrefix("qgis_server")
187195
control.setControlName(control_image)
@@ -190,35 +198,41 @@ def _img_diff(self, image, control_image, max_diff, max_size_diff=QSize()):
190198
control.setSizeTolerance(max_size_diff.width(), max_size_diff.height())
191199
return control.compareImages(control_image, max_diff), control.report()
192200

193-
def _img_diff_error(self, response, headers, image, max_diff=100, max_size_diff=QSize(), unittest_data_path='control_images'):
201+
def _img_diff_error(self, response, headers, image, max_diff=100, max_size_diff=QSize(), unittest_data_path='control_images', outputJpg=False):
202+
203+
extFile = 'png'
204+
contentType = 'image/png'
205+
if outputJpg:
206+
extFile = 'jpg'
207+
contentType = 'image/jpeg'
194208

195-
reference_path = unitTestDataPath(unittest_data_path) + '/qgis_server/' + image + '/' + image + '.png'
209+
reference_path = unitTestDataPath(unittest_data_path) + '/qgis_server/' + image + '/' + image + '.' + extFile
196210
self.store_reference(reference_path, response)
197211

198212
self.assertEqual(
199-
headers.get("Content-Type"), "image/png",
200-
"Content type is wrong: %s\n%s" % (headers.get("Content-Type"), response))
213+
headers.get("Content-Type"), contentType,
214+
"Content type is wrong: %s instead of %s\n%s" % (headers.get("Content-Type"), contentType, response))
201215

202-
test, report = self._img_diff(response, image, max_diff, max_size_diff)
216+
test, report = self._img_diff(response, image, max_diff, max_size_diff, outputJpg)
203217

204-
with open(os.path.join(tempfile.gettempdir(), image + "_result.png"), "rb") as rendered_file:
218+
with open(os.path.join(tempfile.gettempdir(), image + "_result." + extFile), "rb") as rendered_file:
205219
encoded_rendered_file = base64.b64encode(rendered_file.read())
206220
if not os.environ.get('ENCODED_OUTPUT'):
207-
message = "Image is wrong\: rendered file %s/%s_result.png" % (tempfile.gettempdir(), image)
221+
message = "Image is wrong\: rendered file %s/%s_result.%s" % (tempfile.gettempdir(), image, extFile)
208222
else:
209-
message = "Image is wrong\n%s\nImage:\necho '%s' | base64 -d >%s/%s_result.png" % (
210-
report, encoded_rendered_file.strip().decode('utf8'), tempfile.gettempdir(), image
223+
message = "Image is wrong\n%s\nImage:\necho '%s' | base64 -d >%s/%s_result.%s" % (
224+
report, encoded_rendered_file.strip().decode('utf8'), tempfile.gettempdir(), image, extFile
211225
)
212226

213227
# If the failure is in image sizes the diff file will not exists.
214-
if os.path.exists(os.path.join(tempfile.gettempdir(), image + "_result_diff.png")):
215-
with open(os.path.join(tempfile.gettempdir(), image + "_result_diff.png"), "rb") as diff_file:
228+
if os.path.exists(os.path.join(tempfile.gettempdir(), image + "_result_diff." + extFile)):
229+
with open(os.path.join(tempfile.gettempdir(), image + "_result_diff." + extFile), "rb") as diff_file:
216230
if not os.environ.get('ENCODED_OUTPUT'):
217-
message = "Image is wrong\: diff file %s/%s_result_diff.png" % (tempfile.gettempdir(), image)
231+
message = "Image is wrong\: diff file %s/%s_result_diff.%s" % (tempfile.gettempdir(), image, extFile)
218232
else:
219233
encoded_diff_file = base64.b64encode(diff_file.read())
220-
message += "\nDiff:\necho '%s' | base64 -d > %s/%s_result_diff.png" % (
221-
encoded_diff_file.strip().decode('utf8'), tempfile.gettempdir(), image
234+
message += "\nDiff:\necho '%s' | base64 -d > %s/%s_result_diff.%s" % (
235+
encoded_diff_file.strip().decode('utf8'), tempfile.gettempdir(), image, extFile
222236
)
223237

224238
self.assertTrue(test, message)

‎tests/src/python/test_qgsserver_accesscontrol.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,13 @@ def _post_restricted(self, data, query_string=None):
202202
self._server.putenv("QGIS_PROJECT_FILE", '')
203203
return result
204204

205-
def _img_diff(self, image, control_image, max_diff, max_size_diff=QSize()):
206-
temp_image = os.path.join(tempfile.gettempdir(), "%s_result.png" % control_image)
205+
def _img_diff(self, image, control_image, max_diff, max_size_diff=QSize(), outputJpg=False):
206+
207+
extFile = 'png'
208+
if outputJpg:
209+
extFile = 'jpg'
210+
211+
temp_image = os.path.join(tempfile.gettempdir(), "%s_result.%s" % (control_image, extFile))
207212

208213
with open(temp_image, "wb") as f:
209214
f.write(image)

‎tests/src/python/test_qgsserver_wfs.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,13 @@ def test_getfeature_post(self):
374374
def test_getFeatureBBOX(self):
375375
"""Test with (1.1.0) and without (1.0.0) CRS"""
376376

377+
# Tests without CRS
378+
self.wfs_request_compare(
379+
"GetFeature", '1.0.0', "TYPENAME=testlayer&RESULTTYPE=hits&BBOX=8.20347,44.901471,8.2035354,44.901493", 'wfs_getFeature_1_0_0_bbox_1_feature')
380+
self.wfs_request_compare(
381+
"GetFeature", '1.0.0', "TYPENAME=testlayer&RESULTTYPE=hits&BBOX=8.203127,44.9012765,8.204138,44.901632", 'wfs_getFeature_1_0_0_bbox_3_feature')
382+
383+
# Tests with CRS
377384
self.wfs_request_compare(
378385
"GetFeature", '1.0.0', "SRSNAME=EPSG:4326&TYPENAME=testlayer&RESULTTYPE=hits&BBOX=8.20347,44.901471,8.2035354,44.901493,EPSG:4326", 'wfs_getFeature_1_0_0_epsgbbox_1_feature')
379386
self.wfs_request_compare(

‎tests/src/python/test_qgsserver_wms_getfeatureinfo.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,16 @@ def testGetFeatureInfoFilter(self):
347347
urllib.parse.quote(':"NAME" = \'two\''),
348348
'wms_getfeatureinfo_filter_no_width')
349349

350+
# Test a filter without CRS parameter
351+
self.wms_request_compare('GetFeatureInfo',
352+
'&layers=testlayer%20%C3%A8%C3%A9&' +
353+
'INFO_FORMAT=text%2Fxml&' +
354+
'width=600&height=400&' +
355+
'query_layers=testlayer%20%C3%A8%C3%A9&' +
356+
'FEATURE_COUNT=10&FILTER=testlayer%20%C3%A8%C3%A9' +
357+
urllib.parse.quote(':"NAME" = \'two\''),
358+
'wms_getfeatureinfo_filter_no_crs')
359+
350360
def testGetFeatureInfoTolerance(self):
351361
self.wms_request_compare('GetFeatureInfo',
352362
'&layers=layer3&styles=&' +

‎tests/src/python/test_qgsserver_wms_getprint.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,22 @@ def test_wms_getprint_basic(self):
9191
r, h = self._result(self._execute_request(qs))
9292
self._img_diff_error(r, h, "WMS_GetPrint_Basic")
9393

94+
# Output JPEG
95+
qs = "?" + "&".join(["%s=%s" % i for i in list({
96+
"MAP": urllib.parse.quote(self.projectPath),
97+
"SERVICE": "WMS",
98+
"VERSION": "1.1.1",
99+
"REQUEST": "GetPrint",
100+
"TEMPLATE": "layoutA4",
101+
"FORMAT": "jpeg",
102+
"map0:EXTENT": "-33626185.498,-13032965.185,33978427.737,16020257.031",
103+
"LAYERS": "Country,Hello",
104+
"CRS": "EPSG:3857"
105+
}.items())])
106+
107+
r, h = self._result(self._execute_request(qs))
108+
self._img_diff_error(r, h, "WMS_GetPrint_Basic", outputJpg=True)
109+
94110
def test_wms_getprint_style(self):
95111
# default style
96112
qs = "?" + "&".join(["%s=%s" % i for i in list({
Loading
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Content-Type: text/xml; subtype=gml/2.1.2; charset=utf-8
2+
3+
<wfs:FeatureCollection xmlns:wfs="http://www.opengis.net/wfs" xmlns:ogc="http://www.opengis.net/ogc" xmlns:gml="http://www.opengis.net/gml" xmlns:ows="http://www.opengis.net/ows" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:qgs="http://www.qgis.org/gml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/wfs.xsd http://www.qgis.org/gml ?MAP=/home/ale/dev/QGIS/tests/testdata/qgis_server/test_project_wfs.qgs&amp;SRSNAME=EPSG:4326&amp;RESULTTYPE=hits&amp;SERVICE=WFS&amp;VERSION=1.0.0&amp;REQUEST=DescribeFeatureType&amp;TYPENAME=testlayer&amp;OUTPUTFORMAT=XMLSCHEMA"
4+
timeStamp="2019-01-23T12:09:05"
5+
numberOfFeatures="1">
6+
</wfs:FeatureCollection>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Content-Type: text/xml; subtype=gml/2.1.2; charset=utf-8
2+
3+
<wfs:FeatureCollection xmlns:wfs="http://www.opengis.net/wfs" xmlns:ogc="http://www.opengis.net/ogc" xmlns:gml="http://www.opengis.net/gml" xmlns:ows="http://www.opengis.net/ows" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:qgs="http://www.qgis.org/gml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/wfs.xsd http://www.qgis.org/gml ?MAP=/home/ale/dev/QGIS/tests/testdata/qgis_server/test_project_wfs.qgs&amp;SRSNAME=EPSG:4326&amp;RESULTTYPE=hits&amp;SERVICE=WFS&amp;VERSION=1.0.0&amp;REQUEST=DescribeFeatureType&amp;TYPENAME=testlayer&amp;OUTPUTFORMAT=XMLSCHEMA"
4+
timeStamp="2019-01-23T12:09:05"
5+
numberOfFeatures="3">
6+
</wfs:FeatureCollection>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Content-Length: 577
2+
Content-Type: text/xml; charset=utf-8
3+
4+
<GetFeatureInfoResponse>
5+
<BoundingBox maxy="44.90143568" maxx="8.20354699" miny="44.90143568" CRS="EPSG:4326" minx="8.20354699"/>
6+
<Layer name="testlayer èé">
7+
<Feature id="1">
8+
<Attribute value="2" name="id"/>
9+
<Attribute value="two" name="name"/>
10+
<Attribute value="two àò" name="utf8nameè"/>
11+
<BoundingBox maxy="44.9014" maxx="8.2035" miny="44.9014" CRS="EPSG:4326" minx="8.2035"/>
12+
</Feature>
13+
</Layer>
14+
</GetFeatureInfoResponse>

0 commit comments

Comments
 (0)
Please sign in to comment.