@@ -1460,6 +1460,17 @@ QImage* QgsWMSServer::getMap( HitTest* hitTest )
1460
1460
// theImage->save( QDir::tempPath() + QDir::separator() + "lastrender.png" );
1461
1461
// #endif
1462
1462
1463
+ thePainter.end ();
1464
+
1465
+ // test if width / height ratio of image is the same as the ratio of WIDTH / HEIGHT parameters. If not, the image has to be scaled (required by WMS spec)
1466
+ int widthParam = mParameters .value ( " WIDTH" , " 0" ).toInt ();
1467
+ int heightParam = mParameters .value ( " HEIGHT" , " 0" ).toInt ();
1468
+ if ( widthParam != theImage->width () || heightParam != theImage->height () )
1469
+ {
1470
+ // scale image
1471
+ *theImage = theImage->scaled ( widthParam, heightParam, Qt::IgnoreAspectRatio, Qt::SmoothTransformation );
1472
+ }
1473
+
1463
1474
return theImage;
1464
1475
}
1465
1476
@@ -1581,7 +1592,6 @@ int QgsWMSServer::getFeatureInfo( QDomDocument& result, const QString& version )
1581
1592
QgsRectangle mapExtent = mMapRenderer ->extent ();
1582
1593
double scaleDenominator = scaleCalc.calculate ( mapExtent, outputImage->width () );
1583
1594
mConfigParser ->setScaleDenominator ( scaleDenominator );
1584
- delete outputImage; // no longer needed for feature info
1585
1595
1586
1596
// read FEATURE_COUNT
1587
1597
int featureCount = 1 ;
@@ -1621,6 +1631,16 @@ int QgsWMSServer::getFeatureInfo( QDomDocument& result, const QString& version )
1621
1631
j = -1 ;
1622
1632
}
1623
1633
1634
+ // In case the output image is distorted (WIDTH/HEIGHT ratio not equal to BBOX width/height), I and J need to be adapted as well
1635
+ int widthParam = mParameters .value ( " WIDTH" , " -1" ).toInt ();
1636
+ int heightParam = mParameters .value ( " HEIGHT" , " -1" ).toInt ();
1637
+ if (( i != -1 && j != -1 && widthParam != -1 && heightParam != -1 ) && ( widthParam != outputImage->width () || heightParam != outputImage->height () ) )
1638
+ {
1639
+ i *= ( outputImage->width () / ( double )widthParam );
1640
+ j *= ( outputImage->height () / ( double )heightParam );
1641
+ }
1642
+ delete outputImage; // no longer needed for feature info
1643
+
1624
1644
// Normally, I/J or X/Y are mandatory parameters.
1625
1645
// However, in order to make attribute only queries via the FILTER parameter, it is allowed to skip them if the FILTER parameter is there
1626
1646
@@ -1957,6 +1977,29 @@ QImage* QgsWMSServer::createImage( int width, int height ) const
1957
1977
}
1958
1978
}
1959
1979
1980
+ // Adapt width / height if the aspect ratio does not correspond with the BBOX.
1981
+ // Required by WMS spec. 1.3.
1982
+ bool bboxOk;
1983
+ QgsRectangle mapExtent = _parseBBOX ( mParameters .value ( " BBOX" ), bboxOk );
1984
+ if ( bboxOk )
1985
+ {
1986
+ double mapWidthHeightRatio = mapExtent.width () / mapExtent.height ();
1987
+ double imageWidthHeightRatio = ( double )width / ( double )height;
1988
+ if ( !qgsDoubleNear ( mapWidthHeightRatio, imageWidthHeightRatio, 0.0001 ) )
1989
+ {
1990
+ if ( mapWidthHeightRatio >= imageWidthHeightRatio )
1991
+ {
1992
+ // decrease image height
1993
+ height = width / mapWidthHeightRatio;
1994
+ }
1995
+ else
1996
+ {
1997
+ // decrease image width
1998
+ width = height * mapWidthHeightRatio;
1999
+ }
2000
+ }
2001
+ }
2002
+
1960
2003
if ( width < 0 || height < 0 )
1961
2004
{
1962
2005
return nullptr ;
@@ -2039,7 +2082,7 @@ int QgsWMSServer::configureMapRender( const QPaintDevice* paintDevice ) const
2039
2082
throw QgsMapServiceException ( " InvalidParameterValue" , " Invalid BBOX parameter" );
2040
2083
}
2041
2084
2042
- if ( mapExtent.isEmpty () )
2085
+ if ( mParameters . contains ( " BBOX " ) && mapExtent.isEmpty () )
2043
2086
{
2044
2087
throw QgsMapServiceException ( " InvalidParameterValue" , " BBOX is empty" );
2045
2088
}
0 commit comments