Skip to content

Commit 454df31

Browse files
committedJan 3, 2017
[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 47130a6 commit 454df31

File tree

8 files changed

+17
-11
lines changed

8 files changed

+17
-11
lines changed
 

‎src/server/qgswmsserver.cpp

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

19751975
//Adapt width / height if the aspect ratio does not correspond with the BBOX.
19761976
//Required by WMS spec. 1.3.
1977-
if ( useBbox )
1977+
QString version = mParameters.value( QStringLiteral( "VERSION" ), QStringLiteral( "1.3.0" ) );
1978+
if ( useBbox && version != QLatin1String( "1.1.1" ) )
19781979
{
19791980
bool bboxOk;
19801981
QgsRectangle mapExtent = _parseBBOX( mParameters.value( "BBOX" ), bboxOk );
1982+
QString crs = mParameters.value( QStringLiteral( "CRS" ), mParameters.value( QStringLiteral( "SRS" ) ) );
1983+
if ( crs.compare( "CRS:84", Qt::CaseInsensitive ) == 0 )
1984+
{
1985+
crs = QString( "EPSG:4326" );
1986+
mapExtent.invert();
1987+
}
1988+
QgsCoordinateReferenceSystem outputCRS = QgsCoordinateReferenceSystem::fromOgcWmsCrs( crs );
1989+
if ( outputCRS.hasAxisInverted() )
1990+
{
1991+
mapExtent.invert();
1992+
}
19811993
if ( bboxOk )
19821994
{
19831995
double mapWidthHeightRatio = mapExtent.width() / mapExtent.height();
19841996
double imageWidthHeightRatio = ( double )width / ( double )height;
19851997
if ( !qgsDoubleNear( mapWidthHeightRatio, imageWidthHeightRatio, 0.0001 ) )
19861998
{
1987-
if ( mapWidthHeightRatio >= imageWidthHeightRatio )
1988-
{
1989-
//increase image height
1990-
height = width * mapWidthHeightRatio;
1991-
}
1992-
else
1993-
{
1994-
//increase image width
1995-
width = height / mapWidthHeightRatio;
1996-
}
1999+
// inspired by MapServer, mapdraw.c L115
2000+
double cellsize = ( mapExtent.width() / ( double )width ) * 0.5 + ( mapExtent.height() / ( double )height ) * 0.5;
2001+
width = mapExtent.width() / cellsize;
2002+
height = mapExtent.height() / cellsize;
19972003
}
19982004
}
19992005
}
Loading
Loading
Loading
Loading
Loading
Loading
Loading

0 commit comments

Comments
 (0)
Please sign in to comment.