Skip to content
Permalink
Browse files

[BUGFIX][Server] WMS compliance: stretched, distort, increase, decrease

The commit d44f1eb seems to break some WMS 1.3.0 client and WMS compliancy.
The commit d44f1eb 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 d44f1eb.
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.
  • Loading branch information
rldhont committed Jan 3, 2017
1 parent 47130a6 commit 454df31b17a5a135e7bbfa8136314588355fe2f6
@@ -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;
}
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit 454df31

Please sign in to comment.
You can’t perform that action at this time.