Skip to content

Commit 6140cb6

Browse files
committed
[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.
1 parent 60ee82a commit 6140cb6

1 file changed

Lines changed: 17 additions & 11 deletions

File tree

‎src/server/qgswmsserver.cpp‎

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2001,26 +2001,32 @@ QImage* QgsWMSServer::createImage( int width, int height, bool useBbox ) const
20012001

20022002
//Adapt width / height if the aspect ratio does not correspond with the BBOX.
20032003
//Required by WMS spec. 1.3.
2004-
if ( useBbox )
2004+
QString version = mParameters.value( QStringLiteral( "VERSION" ), QStringLiteral( "1.3.0" ) );
2005+
if ( useBbox && version != QLatin1String( "1.1.1" ) )
20052006
{
20062007
bool bboxOk;
20072008
QgsRectangle mapExtent = _parseBBOX( mParameters.value( "BBOX" ), bboxOk );
2009+
QString crs = mParameters.value( QStringLiteral( "CRS" ), mParameters.value( QStringLiteral( "SRS" ) ) );
2010+
if ( crs.compare( "CRS:84", Qt::CaseInsensitive ) == 0 )
2011+
{
2012+
crs = QString( "EPSG:4326" );
2013+
mapExtent.invert();
2014+
}
2015+
QgsCoordinateReferenceSystem outputCRS = QgsCoordinateReferenceSystem::fromOgcWmsCrs( crs );
2016+
if ( outputCRS.hasAxisInverted() )
2017+
{
2018+
mapExtent.invert();
2019+
}
20082020
if ( bboxOk )
20092021
{
20102022
double mapWidthHeightRatio = mapExtent.width() / mapExtent.height();
20112023
double imageWidthHeightRatio = ( double )width / ( double )height;
20122024
if ( !qgsDoubleNear( mapWidthHeightRatio, imageWidthHeightRatio, 0.0001 ) )
20132025
{
2014-
if ( mapWidthHeightRatio >= imageWidthHeightRatio )
2015-
{
2016-
//increase image height
2017-
height = width * mapWidthHeightRatio;
2018-
}
2019-
else
2020-
{
2021-
//increase image width
2022-
width = height / mapWidthHeightRatio;
2023-
}
2026+
// inspired by MapServer, mapdraw.c L115
2027+
double cellsize = ( mapExtent.width() / ( double )width ) * 0.5 + ( mapExtent.height() / ( double )height ) * 0.5;
2028+
width = mapExtent.width() / cellsize;
2029+
height = mapExtent.height() / cellsize;
20242030
}
20252031
}
20262032
}

0 commit comments

Comments
 (0)