Merge pull request #9545 from signedav/getlegendgraphics_HEIGHTWIDTH

SRCHEIGHT/SRCWIDTH for GetLegendGraphic request
This commit is contained in:
Blottiere Paul 2019-03-27 14:27:27 +01:00 committed by GitHub
commit 51ab846d8e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 161 additions and 27 deletions

View File

@ -363,6 +363,16 @@ namespace QgsWms
QVariant( 0 ) );
save( pWidth );
const QgsWmsParameter pSrcHeight( QgsWmsParameter::SRCHEIGHT,
QVariant::Int,
QVariant( 0 ) );
save( pSrcHeight );
const QgsWmsParameter pSrcWidth( QgsWmsParameter::SRCWIDTH,
QVariant::Int,
QVariant( 0 ) );
save( pSrcWidth );
const QgsWmsParameter pBbox( QgsWmsParameter::BBOX );
save( pBbox );
@ -686,6 +696,26 @@ namespace QgsWms
return mWmsParameters[ QgsWmsParameter::WIDTH ].toInt();
}
QString QgsWmsParameters::srcHeight() const
{
return mWmsParameters[ QgsWmsParameter::SRCHEIGHT ].toString();
}
QString QgsWmsParameters::srcWidth() const
{
return mWmsParameters[ QgsWmsParameter::SRCWIDTH ].toString();
}
int QgsWmsParameters::srcHeightAsInt() const
{
return mWmsParameters[ QgsWmsParameter::SRCHEIGHT ].toInt();
}
int QgsWmsParameters::srcWidthAsInt() const
{
return mWmsParameters[ QgsWmsParameter::SRCWIDTH ].toInt();
}
QString QgsWmsParameters::dpi() const
{
return mWmsParameters[ QgsWmsParameter::DPI ].toString();

View File

@ -176,7 +176,9 @@ namespace QgsWms
WITH_MAPTIP,
WMTVER,
ATLAS_PK,
FORMAT_OPTIONS
FORMAT_OPTIONS,
SRCWIDTH,
SRCHEIGHT
};
Q_ENUM( Name )
@ -390,6 +392,40 @@ namespace QgsWms
*/
int heightAsInt() const;
/**
* Returns SRCWIDTH parameter or an empty string if not defined.
* \returns srcWidth parameter
* \since QGIS 3.8
*/
QString srcWidth() const;
/**
* Returns SRCWIDTH parameter as an int or its default value if not
* defined. An exception is raised if SRCWIDTH is defined and cannot be
* converted.
* \returns srcWidth parameter
* \throws QgsBadRequestException
* \since QGIS 3.8
*/
int srcWidthAsInt() const;
/**
* Returns SRCHEIGHT parameter or an empty string if not defined.
* \returns srcHeight parameter
* \since QGIS 3.8
*/
QString srcHeight() const;
/**
* Returns SRCHEIGHT parameter as an int or its default value if not
* defined. An exception is raised if SRCHEIGHT is defined and cannot be
* converted.
* \returns srcHeight parameter
* \throws QgsBadRequestException
* \since QGIS 3.8
*/
int srcHeightAsInt() const;
/**
* Returns VERSION parameter if defined or its default value.
* \returns version

View File

@ -187,7 +187,7 @@ namespace QgsWms
if ( !mWmsParameters.bbox().isEmpty() )
{
QgsMapSettings mapSettings;
image.reset( createImage( mWmsParameters.widthAsInt(), mWmsParameters.heightAsInt(), false ) );
image.reset( createImage( width(), height(), false ) );
configureMapSettings( image.get(), mapSettings );
legendSettings.setMapScale( mapSettings.scale() );
legendSettings.setMapUnitsPerPixel( mapSettings.mapUnitsPerPixel() );
@ -1123,10 +1123,10 @@ namespace QgsWms
QImage *QgsRenderer::createImage( int width, int height, bool useBbox ) const
{
if ( width < 0 )
width = mWmsParameters.widthAsInt();
width = this->width();
if ( height < 0 )
height = mWmsParameters.heightAsInt();
height = this->height();
//Adapt width / height if the aspect ratio does not correspond with the BBOX.
//Required by WMS spec. 1.3.
@ -1994,14 +1994,14 @@ namespace QgsWms
{
//test if maxWidth / maxHeight set and WIDTH / HEIGHT parameter is in the range
int wmsMaxWidth = QgsServerProjectUtils::wmsMaxWidth( *mProject );
int width = mWmsParameters.widthAsInt();
int width = this->width();
if ( wmsMaxWidth != -1 && width > wmsMaxWidth )
{
return false;
}
int wmsMaxHeight = QgsServerProjectUtils::wmsMaxHeight( *mProject );
int height = mWmsParameters.heightAsInt();
int height = this->height();
if ( wmsMaxHeight != -1 && height > wmsMaxHeight )
{
return false;
@ -3206,8 +3206,8 @@ namespace QgsWms
// WIDTH / HEIGHT parameters. If not, the image has to be scaled (required
// by WMS spec)
QImage *scaledImage = nullptr;
int width = mWmsParameters.widthAsInt();
int height = mWmsParameters.heightAsInt();
int width = this->width();
int height = this->height();
if ( width != image->width() || height != image->height() )
{
scaledImage = new QImage( image->scaled( width, height, Qt::IgnoreAspectRatio, Qt::SmoothTransformation ) );
@ -3418,4 +3418,22 @@ namespace QgsWms
}
}
int QgsRenderer::height() const
{
if ( ( mWmsParameters.request().compare( QStringLiteral( "GetLegendGraphic" ), Qt::CaseInsensitive ) == 0 ||
mWmsParameters.request().compare( QStringLiteral( "GetLegendGraphics" ), Qt::CaseInsensitive ) == 0 ) &&
mWmsParameters.srcHeightAsInt() > 0 )
return mWmsParameters.srcHeightAsInt();
return mWmsParameters.heightAsInt();
}
int QgsRenderer::width() const
{
if ( ( mWmsParameters.request().compare( QStringLiteral( "GetLegendGraphic" ), Qt::CaseInsensitive ) == 0 ||
mWmsParameters.request().compare( QStringLiteral( "GetLegendGraphics" ), Qt::CaseInsensitive ) == 0 ) &&
mWmsParameters.srcWidthAsInt() > 0 )
return mWmsParameters.srcWidthAsInt();
return mWmsParameters.widthAsInt();
}
} // namespace QgsWms

View File

@ -297,6 +297,20 @@ namespace QgsWms
void handlePrintErrors( const QgsLayout *layout ) const;
/**
* Returns QgsWmsParameter SRCWIDTH if it's a GetLegendGraphics request and otherwise HEIGHT parameter
* \returns height parameter
* \since QGIS 3.8
*/
int height() const;
/**
* Returns QgsWmsParameter SRCWIDTH parameter if it's a GetLegendGraphics request and otherwise WIDTH parameter
* \returns width parameter
* \since QGIS 3.8
*/
int width() const;
const QgsWmsParameters &mWmsParameters;
#ifdef HAVE_SERVER_PYTHON_PLUGINS

View File

@ -460,6 +460,42 @@ class TestQgsServerWMSGetLegendGraphic(QgsServerTestBase):
self._img_diff_error(r, h, "WMS_GetLegendGraphic_ItemFont", max_size_diff=QSize(1, 1))
def test_wms_GetLegendGraphic_BBox(self):
qs = "?" + "&".join(["%s=%s" % i for i in list({
"MAP": urllib.parse.quote(self.projectPath),
"SERVICE": "WMS",
"VERSION": "1.1.1",
"REQUEST": "GetLegendGraphic",
"LAYER": "Country,Hello,db_point",
"LAYERTITLE": "FALSE",
"FORMAT": "image/png",
"SRCHEIGHT": "500",
"SRCWIDTH": "500",
"BBOX": "-151.7,-38.9,51.0,78.0",
"CRS": "EPSG:4326"
}.items())])
r, h = self._result(self._execute_request(qs))
self._img_diff_error(r, h, "WMS_GetLegendGraphic_BBox")
def test_wms_GetLegendGraphic_BBox2(self):
qs = "?" + "&".join(["%s=%s" % i for i in list({
"MAP": urllib.parse.quote(self.projectPath),
"SERVICE": "WMS",
"VERSION": "1.1.1",
"REQUEST": "GetLegendGraphic",
"LAYER": "Country,Hello,db_point",
"LAYERTITLE": "FALSE",
"FORMAT": "image/png",
"SRCHEIGHT": "500",
"SRCWIDTH": "500",
"BBOX": "-76.08,-6.4,-19.38,38.04",
"SRS": "EPSG:4326"
}.items())])
r, h = self._result(self._execute_request(qs))
self._img_diff_error(r, h, "WMS_GetLegendGraphic_BBox2")
def test_wms_GetLegendGraphic_BBox_Fallback(self):
qs = "?" + "&".join(["%s=%s" % i for i in list({
"MAP": urllib.parse.quote(self.projectPath),
"SERVICE": "WMS",
@ -477,7 +513,7 @@ class TestQgsServerWMSGetLegendGraphic(QgsServerTestBase):
r, h = self._result(self._execute_request(qs))
self._img_diff_error(r, h, "WMS_GetLegendGraphic_BBox")
def test_wms_GetLegendGraphic_BBox2(self):
def test_wms_GetLegendGraphic_BBox2_Fallback(self):
qs = "?" + "&".join(["%s=%s" % i for i in list({
"MAP": urllib.parse.quote(self.projectPath),
"SERVICE": "WMS",
@ -503,8 +539,8 @@ class TestQgsServerWMSGetLegendGraphic(QgsServerTestBase):
"REQUEST": "GetLegendGraphic",
"LAYER": "QGIS%20Server%20Hello%20World",
"FORMAT": "image/png",
"HEIGHT": "840",
"WIDTH": "1226",
"SRCHEIGHT": "840",
"SRCWIDTH": "1226",
"BBOX": "10.38450,-49.6370,73.8183,42.9461",
"SRS": "EPSG:4326",
"SCALE": "15466642"
@ -525,8 +561,8 @@ class TestQgsServerWMSGetLegendGraphic(QgsServerTestBase):
"REQUEST": "GetLegendGraphic",
"LAYER": "QGIS%20Server%20-%20Grouped%20Layer",
"FORMAT": "image/png",
"HEIGHT": "840",
"WIDTH": "1226",
"SRCHEIGHT": "840",
"SRCWIDTH": "1226",
"BBOX": "609152,5808188,625492,5814318",
"SRS": "EPSG:25832",
"SCALE": "38976"
@ -544,8 +580,8 @@ class TestQgsServerWMSGetLegendGraphic(QgsServerTestBase):
"REQUEST": "GetLegendGraphic",
"LAYER": "All_grouped_layers",
"FORMAT": "image/png",
"HEIGHT": "840",
"WIDTH": "1226",
"SRCHEIGHT": "840",
"SRCWIDTH": "1226",
"BBOX": "609152,5808188,625492,5814318",
"SRS": "EPSG:25832",
"SCALE": "38976"
@ -563,8 +599,8 @@ class TestQgsServerWMSGetLegendGraphic(QgsServerTestBase):
"REQUEST": "GetLegendGraphic",
"LAYER": "testlayer",
"FORMAT": "image/png",
"HEIGHT": "550",
"WIDTH": "850",
"SRCHEIGHT": "550",
"SRCWIDTH": "850",
"BBOX": "-608.4,-1002.6,698.2,1019.0",
"CRS": "EPSG:4326"
}.items())])
@ -579,8 +615,8 @@ class TestQgsServerWMSGetLegendGraphic(QgsServerTestBase):
"REQUEST": "GetLegendGraphic",
"LAYER": "testlayer",
"FORMAT": "image/png",
"HEIGHT": "550",
"WIDTH": "850",
"SRCHEIGHT": "550",
"SRCWIDTH": "850",
"BBOX": "-1261.7,-2013.5,1351.5,2029.9",
"CRS": "EPSG:4326"
}.items())])
@ -596,8 +632,8 @@ class TestQgsServerWMSGetLegendGraphic(QgsServerTestBase):
"REQUEST": "GetLegendGraphic",
"LAYER": "testlayer",
"FORMAT": "image/png",
"HEIGHT": "550",
"WIDTH": "850",
"SRCHEIGHT": "550",
"SRCWIDTH": "850",
"BBOX": "31.8,-12.0,58.0,28.4",
"CRS": "EPSG:4326"
}.items())])
@ -613,8 +649,8 @@ class TestQgsServerWMSGetLegendGraphic(QgsServerTestBase):
"REQUEST": "GetLegendGraphic",
"LAYER": "testlayer",
"FORMAT": "image/png",
"HEIGHT": "550",
"WIDTH": "850",
"SRCHEIGHT": "550",
"SRCWIDTH": "850",
"BBOX": "25.3,-22.1,64.5,38.5",
"CRS": "EPSG:4326"
}.items())])
@ -630,8 +666,8 @@ class TestQgsServerWMSGetLegendGraphic(QgsServerTestBase):
"REQUEST": "GetLegendGraphic",
"LAYER": "testlayer",
"FORMAT": "image/png",
"HEIGHT": "550",
"WIDTH": "850",
"SRCHEIGHT": "550",
"SRCWIDTH": "850",
"BBOX": "44.8,8.0,45.0,8.4",
"CRS": "EPSG:4326"
}.items())])
@ -646,8 +682,8 @@ class TestQgsServerWMSGetLegendGraphic(QgsServerTestBase):
"REQUEST": "GetLegendGraphic",
"LAYER": "testlayer",
"FORMAT": "image/png",
"HEIGHT": "550",
"WIDTH": "850",
"SRCHEIGHT": "550",
"SRCWIDTH": "850",
"BBOX": "43.6,6.2,46.2,10.2",
"CRS": "EPSG:4326"
}.items())])