Skip to content
Permalink
Browse files
WMS 1.3. compliance: distort image if width/height ratio of bbox is d…
…ifferent to WIDTH/HEIGHT of requested image
  • Loading branch information
mhugent committed Nov 29, 2016
1 parent 1bc6ee3 commit 120c8d38b89555a209496ad785fd35c6f3b8ee45
Showing with 45 additions and 2 deletions.
  1. +45 −2 src/server/qgswmsserver.cpp
@@ -1464,6 +1464,17 @@ QImage* QgsWmsServer::getMap( HitTest* hitTest )
// theImage->save( QDir::tempPath() + QDir::separator() + "lastrender.png" );
//#endif

thePainter.end();

//test if width / height ratio of image is the same as the ratio of WIDTH / HEIGHT parameters. If not, the image has to be scaled (required by WMS spec)
int widthParam = mParameters.value( "WIDTH", "0" ).toInt();
int heightParam = mParameters.value( "HEIGHT", "0" ).toInt();
if ( widthParam != theImage->width() || heightParam != theImage->height() )
{
//scale image
*theImage = theImage->scaled( widthParam, heightParam, Qt::IgnoreAspectRatio, Qt::SmoothTransformation );
}

return theImage;
}

@@ -1585,7 +1596,6 @@ int QgsWmsServer::getFeatureInfo( QDomDocument& result, const QString& version )
QgsRectangle mapExtent = mMapRenderer->extent();
double scaleDenominator = scaleCalc.calculate( mapExtent, outputImage->width() );
mConfigParser->setScaleDenominator( scaleDenominator );
delete outputImage; //no longer needed for feature info

//read FEATURE_COUNT
int featureCount = 1;
@@ -1625,6 +1635,16 @@ int QgsWmsServer::getFeatureInfo( QDomDocument& result, const QString& version )
j = -1;
}

//In case the output image is distorted (WIDTH/HEIGHT ratio not equal to BBOX width/height), I and J need to be adapted as well
int widthParam = mParameters.value( "WIDTH", "-1" ).toInt();
int heightParam = mParameters.value( "HEIGHT", "-1" ).toInt();
if (( i != -1 && j != -1 && widthParam != -1 && heightParam != -1 ) && ( widthParam != outputImage->width() || heightParam != outputImage->height() ) )
{
i *= ( outputImage->width() / ( double )widthParam );
j *= ( outputImage->height() / ( double )heightParam );
}
delete outputImage; //no longer needed for feature info

//Normally, I/J or X/Y are mandatory parameters.
//However, in order to make attribute only queries via the FILTER parameter, it is allowed to skip them if the FILTER parameter is there

@@ -1966,6 +1986,29 @@ QImage* QgsWmsServer::createImage( int width, int height ) const
}
}

//Adapt width / height if the aspect ratio does not correspond with the BBOX.
//Required by WMS spec. 1.3.
bool bboxOk;
QgsRectangle mapExtent = _parseBBOX( mParameters.value( "BBOX" ), bboxOk );
if ( bboxOk )
{
double mapWidthHeightRatio = mapExtent.width() / mapExtent.height();
double imageWidthHeightRatio = ( double )width / ( double )height;
if ( !qgsDoubleNear( mapWidthHeightRatio, imageWidthHeightRatio, 0.0001 ) )
{
if ( mapWidthHeightRatio >= imageWidthHeightRatio )
{
//decrease image height
height = width / mapWidthHeightRatio;
}
else
{
//decrease image width
width = height * mapWidthHeightRatio;
}
}
}

if ( width < 0 || height < 0 )
{
return nullptr;
@@ -2048,7 +2091,7 @@ int QgsWmsServer::configureMapRender( const QPaintDevice* paintDevice ) const
throw QgsMapServiceException( QStringLiteral( "InvalidParameterValue" ), QStringLiteral( "Invalid BBOX parameter" ) );
}

if ( mapExtent.isEmpty() )
if ( mParameters.contains( "BBOX" ) && mapExtent.isEmpty() )
{
throw QgsMapServiceException( "InvalidParameterValue", "BBOX is empty" );
}

1 comment on commit 120c8d3

@rldhont

This comment has been minimized.

Copy link
Contributor

@rldhont rldhont commented on 120c8d3 Dec 13, 2016

We found an issue with this commit, the distortion is not made the right way. We have to invert it.

Please sign in to comment.