Skip to content

Commit

Permalink
[WMS provider] Avoid excessive number of decimals in BBOX parameter
Browse files Browse the repository at this point in the history
Fix #14928
  • Loading branch information
rouault committed Jun 13, 2016
1 parent 2ce4eb5 commit dfe4553
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/providers/wms/qgswmsprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3636,14 +3636,24 @@ void QgsWmsTiledImageDownloadHandler::repeatTileRequest( QNetworkRequest const &
connect( reply, SIGNAL( finished() ), this, SLOT( tileReplyFinished() ) );
}

// Some servers like http://glogow.geoportal2.pl/map/wms/wms.php? do not BBOX
// to be formatted with excessive precision. As a double is exactly represented
// with 19 decimal figures, do not attempt to output more
static QString formatDouble( double x )
{
if ( x == 0.0 )
return "0";
const int numberOfDecimals = qMax( 0, 19 - static_cast<int>( ceil( log10( fabs( x ) ) ) ) );
return qgsDoubleToString( x, numberOfDecimals );
}

QString QgsWmsProvider::toParamValue( const QgsRectangle& rect, bool changeXY )
{
// Warning: does not work with scientific notation
return QString( changeXY ? "%2,%1,%4,%3" : "%1,%2,%3,%4" )
.arg( qgsDoubleToString( rect.xMinimum() ),
qgsDoubleToString( rect.yMinimum() ),
qgsDoubleToString( rect.xMaximum() ),
qgsDoubleToString( rect.yMaximum() ) );
.arg( formatDouble( rect.xMinimum() ),
formatDouble( rect.yMinimum() ),
formatDouble( rect.xMaximum() ),
formatDouble( rect.yMaximum() ) );
}

void QgsWmsProvider::setSRSQueryItem( QUrl& url )
Expand Down

0 comments on commit dfe4553

Please sign in to comment.