[BUGFIX][Server] WMS compliance: stretched, distort, increase, decrease
The commit d44f1eba2fed18b3fef8d8865d79b3b6d8bc4d69 seems to break some WMS 1.3.0 client and WMS compliancy. The commit d44f1eba2fed18b3fef8d8865d79b3b6d8bc4d69 has been written to fix an issue with QGIS WMS Client and to render image like other WMS Server. This commit has been written to fix issue introduce by d44f1eba2fed18b3fef8d8865d79b3b6d8bc4d69. It is based on MapServer code: * https://github.com/mapserver/mapserver/blob/master/mapdraw.c#L115 * https://github.com/mapserver/mapserver/blob/master/HISTORY.TXT#L3768 And take account of axis invertion for output CRS.
@ -1974,26 +1974,32 @@ QImage* QgsWmsServer::createImage( int width, int height, bool useBbox ) const
|
||||
|
||||
//Adapt width / height if the aspect ratio does not correspond with the BBOX.
|
||||
//Required by WMS spec. 1.3.
|
||||
if ( useBbox )
|
||||
QString version = mParameters.value( QStringLiteral( "VERSION" ), QStringLiteral( "1.3.0" ) );
|
||||
if ( useBbox && version != QLatin1String( "1.1.1" ) )
|
||||
{
|
||||
bool bboxOk;
|
||||
QgsRectangle mapExtent = _parseBBOX( mParameters.value( "BBOX" ), bboxOk );
|
||||
QString crs = mParameters.value( QStringLiteral( "CRS" ), mParameters.value( QStringLiteral( "SRS" ) ) );
|
||||
if ( crs.compare( "CRS:84", Qt::CaseInsensitive ) == 0 )
|
||||
{
|
||||
crs = QString( "EPSG:4326" );
|
||||
mapExtent.invert();
|
||||
}
|
||||
QgsCoordinateReferenceSystem outputCRS = QgsCoordinateReferenceSystem::fromOgcWmsCrs( crs );
|
||||
if ( outputCRS.hasAxisInverted() )
|
||||
{
|
||||
mapExtent.invert();
|
||||
}
|
||||
if ( bboxOk )
|
||||
{
|
||||
double mapWidthHeightRatio = mapExtent.width() / mapExtent.height();
|
||||
double imageWidthHeightRatio = ( double )width / ( double )height;
|
||||
if ( !qgsDoubleNear( mapWidthHeightRatio, imageWidthHeightRatio, 0.0001 ) )
|
||||
{
|
||||
if ( mapWidthHeightRatio >= imageWidthHeightRatio )
|
||||
{
|
||||
//increase image height
|
||||
height = width * mapWidthHeightRatio;
|
||||
}
|
||||
else
|
||||
{
|
||||
//increase image width
|
||||
width = height / mapWidthHeightRatio;
|
||||
}
|
||||
// inspired by MapServer, mapdraw.c L115
|
||||
double cellsize = ( mapExtent.width() / ( double )width ) * 0.5 + ( mapExtent.height() / ( double )height ) * 0.5;
|
||||
width = mapExtent.width() / cellsize;
|
||||
height = mapExtent.height() / cellsize;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Before Width: | Height: | Size: 33 KiB After Width: | Height: | Size: 32 KiB |
Before Width: | Height: | Size: 45 KiB After Width: | Height: | Size: 42 KiB |
Before Width: | Height: | Size: 59 KiB After Width: | Height: | Size: 59 KiB |
Before Width: | Height: | Size: 37 KiB After Width: | Height: | Size: 47 KiB |
Before Width: | Height: | Size: 55 KiB After Width: | Height: | Size: 52 KiB |
Before Width: | Height: | Size: 46 KiB After Width: | Height: | Size: 41 KiB |
Before Width: | Height: | Size: 36 KiB After Width: | Height: | Size: 32 KiB |