Skip to content

Commit

Permalink
[BUGFIX][Server] WMS compliance: stretched, distort, increase, decrease
Browse files Browse the repository at this point in the history
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 454df31
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions src/server/qgswmsserver.cpp
Expand Up @@ -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;
}
}
}
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 454df31

Please sign in to comment.