@@ -1453,6 +1453,17 @@ QImage* QgsWMSServer::getMap( HitTest* hitTest )
1453
1453
// theImage->save( QDir::tempPath() + QDir::separator() + "lastrender.png" );
1454
1454
// #endif
1455
1455
1456
+ thePainter.end ();
1457
+
1458
+ // 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)
1459
+ int widthParam = mParameters .value ( " WIDTH" , " 0" ).toInt ();
1460
+ int heightParam = mParameters .value ( " HEIGHT" , " 0" ).toInt ();
1461
+ if ( widthParam != theImage->width () || heightParam != theImage->height () )
1462
+ {
1463
+ // scale image
1464
+ *theImage = theImage->scaled ( widthParam, heightParam, Qt::IgnoreAspectRatio, Qt::SmoothTransformation );
1465
+ }
1466
+
1456
1467
return theImage;
1457
1468
}
1458
1469
@@ -1574,7 +1585,6 @@ int QgsWMSServer::getFeatureInfo( QDomDocument& result, const QString& version )
1574
1585
QgsRectangle mapExtent = mMapRenderer ->extent ();
1575
1586
double scaleDenominator = scaleCalc.calculate ( mapExtent, outputImage->width () );
1576
1587
mConfigParser ->setScaleDenominator ( scaleDenominator );
1577
- delete outputImage; // no longer needed for feature info
1578
1588
1579
1589
// read FEATURE_COUNT
1580
1590
int featureCount = 1 ;
@@ -1614,6 +1624,16 @@ int QgsWMSServer::getFeatureInfo( QDomDocument& result, const QString& version )
1614
1624
j = -1 ;
1615
1625
}
1616
1626
1627
+ // 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
1628
+ int widthParam = mParameters .value ( " WIDTH" , " -1" ).toInt ();
1629
+ int heightParam = mParameters .value ( " HEIGHT" , " -1" ).toInt ();
1630
+ if (( i != -1 && j != -1 && widthParam != -1 && heightParam != -1 ) && ( widthParam != outputImage->width () || heightParam != outputImage->height () ) )
1631
+ {
1632
+ i *= ( outputImage->width () / ( double )widthParam );
1633
+ j *= ( outputImage->height () / ( double )heightParam );
1634
+ }
1635
+ delete outputImage; // no longer needed for feature info
1636
+
1617
1637
// Normally, I/J or X/Y are mandatory parameters.
1618
1638
// However, in order to make attribute only queries via the FILTER parameter, it is allowed to skip them if the FILTER parameter is there
1619
1639
@@ -1950,6 +1970,29 @@ QImage* QgsWMSServer::createImage( int width, int height ) const
1950
1970
}
1951
1971
}
1952
1972
1973
+ // Adapt width / height if the aspect ratio does not correspond with the BBOX.
1974
+ // Required by WMS spec. 1.3.
1975
+ bool bboxOk;
1976
+ QgsRectangle mapExtent = _parseBBOX ( mParameters .value ( " BBOX" ), bboxOk );
1977
+ if ( bboxOk )
1978
+ {
1979
+ double mapWidthHeightRatio = mapExtent.width () / mapExtent.height ();
1980
+ double imageWidthHeightRatio = ( double )width / ( double )height;
1981
+ if ( !qgsDoubleNear ( mapWidthHeightRatio, imageWidthHeightRatio, 0.0001 ) )
1982
+ {
1983
+ if ( mapWidthHeightRatio >= imageWidthHeightRatio )
1984
+ {
1985
+ // decrease image height
1986
+ height = width / mapWidthHeightRatio;
1987
+ }
1988
+ else
1989
+ {
1990
+ // decrease image width
1991
+ width = height * mapWidthHeightRatio;
1992
+ }
1993
+ }
1994
+ }
1995
+
1953
1996
if ( width < 0 || height < 0 )
1954
1997
{
1955
1998
return nullptr ;
@@ -2032,7 +2075,7 @@ int QgsWMSServer::configureMapRender( const QPaintDevice* paintDevice ) const
2032
2075
throw QgsMapServiceException ( " InvalidParameterValue" , " Invalid BBOX parameter" );
2033
2076
}
2034
2077
2035
- if ( mapExtent.isEmpty () )
2078
+ if ( mParameters . contains ( " BBOX " ) && mapExtent.isEmpty () )
2036
2079
{
2037
2080
throw QgsMapServiceException ( " InvalidParameterValue" , " BBOX is empty" );
2038
2081
}
0 commit comments