Skip to content

Commit

Permalink
fixed gdal stats approx for large rasters
Browse files Browse the repository at this point in the history
  • Loading branch information
blazek committed Jul 29, 2012
1 parent eac8bc8 commit 9885341
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/providers/gdal/qgsgdalprovider.cpp
Expand Up @@ -1356,12 +1356,16 @@ QgsRasterHistogram QgsGdalProvider::histogram( int theBandNo,
int bApproxOK = false;
if ( theSampleSize > 0 )
{
if (( xSize() * ySize() / theSampleSize ) > 2 ) // not perfect
// cast to double, integer could overflow
if ((( double )xSize() * ( double )ySize() / theSampleSize ) > 2 ) // not perfect
{
QgsDebugMsg( "Approx" );
bApproxOK = true;
}
}

QgsDebugMsg( QString( "xSize() = %1 ySize() = %2 theSampleSize = %3 bApproxOK = %4" ).arg( xSize() ).arg( ySize() ).arg( theSampleSize ).arg( bApproxOK ) );

QgsGdalProgress myProg;
myProg.type = ProgressHistogram;
myProg.provider = this;
Expand Down Expand Up @@ -2042,7 +2046,7 @@ bool QgsGdalProvider::hasStatistics( int theBandNo,
int bApproxOK = false;
if ( theSampleSize > 0 )
{
if (( xSize() * ySize() / theSampleSize ) > 2 ) // not perfect
if ((( double )xSize() * ( double )ySize() / theSampleSize ) > 2 ) // not perfect
{
bApproxOK = true;
}
Expand Down Expand Up @@ -2119,7 +2123,7 @@ QgsRasterBandStats QgsGdalProvider::bandStatistics( int theBandNo, int theStats,
int bApproxOK = false;
if ( theSampleSize > 0 )
{
if (( xSize() * ySize() / theSampleSize ) > 2 ) // not perfect
if ((( double )xSize() * ( double )ySize() / theSampleSize ) > 2 ) // not perfect
{
bApproxOK = true;
}
Expand Down

0 comments on commit 9885341

Please sign in to comment.