Skip to content

Commit a693521

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 b6b0902 commit a693521

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

src/server/qgswmsserver.cpp

+17-11
Original file line numberDiff line numberDiff line change
@@ -1994,26 +1994,32 @@ QImage* QgsWMSServer::createImage( int width, int height, bool useBbox ) const
19941994

19951995
//Adapt width / height if the aspect ratio does not correspond with the BBOX.
19961996
//Required by WMS spec. 1.3.
1997-
if ( useBbox )
1997+
QString version = mParameters.value( QStringLiteral( "VERSION" ), QStringLiteral( "1.3.0" ) );
1998+
if ( useBbox && version != QLatin1String( "1.1.1" ) )
19981999
{
19992000
bool bboxOk;
20002001
QgsRectangle mapExtent = _parseBBOX( mParameters.value( "BBOX" ), bboxOk );
2002+
QString crs = mParameters.value( QStringLiteral( "CRS" ), mParameters.value( QStringLiteral( "SRS" ) ) );
2003+
if ( crs.compare( "CRS:84", Qt::CaseInsensitive ) == 0 )
2004+
{
2005+
crs = QString( "EPSG:4326" );
2006+
mapExtent.invert();
2007+
}
2008+
QgsCoordinateReferenceSystem outputCRS = QgsCoordinateReferenceSystem::fromOgcWmsCrs( crs );
2009+
if ( outputCRS.hasAxisInverted() )
2010+
{
2011+
mapExtent.invert();
2012+
}
20012013
if ( bboxOk )
20022014
{
20032015
double mapWidthHeightRatio = mapExtent.width() / mapExtent.height();
20042016
double imageWidthHeightRatio = ( double )width / ( double )height;
20052017
if ( !qgsDoubleNear( mapWidthHeightRatio, imageWidthHeightRatio, 0.0001 ) )
20062018
{
2007-
if ( mapWidthHeightRatio >= imageWidthHeightRatio )
2008-
{
2009-
//increase image height
2010-
height = width * mapWidthHeightRatio;
2011-
}
2012-
else
2013-
{
2014-
//increase image width
2015-
width = height / mapWidthHeightRatio;
2016-
}
2019+
// inspired by MapServer, mapdraw.c L115
2020+
double cellsize = ( mapExtent.width() / ( double )width ) * 0.5 + ( mapExtent.height() / ( double )height ) * 0.5;
2021+
width = mapExtent.width() / cellsize;
2022+
height = mapExtent.height() / cellsize;
20172023
}
20182024
}
20192025
}

0 commit comments

Comments
 (0)