Skip to content

Commit

Permalink
backport of SRCWIDTH/SRCHEIGHT
Browse files Browse the repository at this point in the history
it takes these values as map size in case of GetLegendGraphics Request and still HEIGHT and WIDTH if not a GetLegendGraphics Request

(cherry-picked commits 4c667ad e184772 6722ad5 61a89af$)
  • Loading branch information
signedav committed Apr 11, 2019
1 parent e445a25 commit 7426110
Show file tree
Hide file tree
Showing 5 changed files with 160 additions and 27 deletions.
30 changes: 30 additions & 0 deletions src/server/services/wms/qgswmsparameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,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 );

Expand Down Expand Up @@ -681,6 +691,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();
Expand Down
38 changes: 37 additions & 1 deletion src/server/services/wms/qgswmsparameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,9 @@ namespace QgsWms
GRID_INTERVAL_Y,
WITH_GEOMETRY,
WITH_MAPTIP,
WMTVER
WMTVER,
SRCWIDTH,
SRCHEIGHT
};
Q_ENUM( Name )

Expand Down Expand Up @@ -376,6 +378,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
Expand Down
31 changes: 24 additions & 7 deletions src/server/services/wms/qgswmsrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,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() );
Expand Down Expand Up @@ -1015,10 +1015,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.
Expand Down Expand Up @@ -1919,14 +1919,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;
Expand Down Expand Up @@ -2986,8 +2986,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 ) );
Expand Down Expand Up @@ -3210,4 +3210,21 @@ namespace QgsWms
return result;
}

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
14 changes: 14 additions & 0 deletions src/server/services/wms/qgswmsrenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,20 @@ namespace QgsWms

private:

/**
* 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
Expand Down
74 changes: 55 additions & 19 deletions tests/src/python/test_qgsserver_wms_getlegendgraphic.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,42 @@ def test_wms_GetLegendGraphic_ItemFont(self):
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",
Expand All @@ -451,7 +487,7 @@ def test_wms_GetLegendGraphic_BBox(self):
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",
Expand All @@ -477,8 +513,8 @@ def test_wms_GetLegendGraphic_EmptyLegend(self):
"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"
Expand All @@ -499,8 +535,8 @@ def test_wms_GetLegendGraphic_wmsRootName(self):
"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"
Expand All @@ -518,8 +554,8 @@ def test_wms_GetLegendGraphic_wmsRootName(self):
"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"
Expand All @@ -537,8 +573,8 @@ def test_wms_GetLegendGraphic_ScaleSymbol_Min(self):
"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())])
Expand All @@ -553,8 +589,8 @@ def test_wms_GetLegendGraphic_ScaleSymbol_Min(self):
"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())])
Expand All @@ -570,8 +606,8 @@ def test_wms_GetLegendGraphic_ScaleSymbol_Scaled_01(self):
"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())])
Expand All @@ -587,8 +623,8 @@ def test_wms_GetLegendGraphic_ScaleSymbol_Scaled_02(self):
"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())])
Expand All @@ -604,8 +640,8 @@ def test_wms_GetLegendGraphic_ScaleSymbol_Max(self):
"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())])
Expand All @@ -620,8 +656,8 @@ def test_wms_GetLegendGraphic_ScaleSymbol_Max(self):
"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())])
Expand Down

0 comments on commit 7426110

Please sign in to comment.