Skip to content

Commit 9885341

Browse files
committed
fixed gdal stats approx for large rasters
1 parent eac8bc8 commit 9885341

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/providers/gdal/qgsgdalprovider.cpp

+7-3
Original file line numberDiff line numberDiff line change
@@ -1356,12 +1356,16 @@ QgsRasterHistogram QgsGdalProvider::histogram( int theBandNo,
13561356
int bApproxOK = false;
13571357
if ( theSampleSize > 0 )
13581358
{
1359-
if (( xSize() * ySize() / theSampleSize ) > 2 ) // not perfect
1359+
// cast to double, integer could overflow
1360+
if ((( double )xSize() * ( double )ySize() / theSampleSize ) > 2 ) // not perfect
13601361
{
1362+
QgsDebugMsg( "Approx" );
13611363
bApproxOK = true;
13621364
}
13631365
}
13641366

1367+
QgsDebugMsg( QString( "xSize() = %1 ySize() = %2 theSampleSize = %3 bApproxOK = %4" ).arg( xSize() ).arg( ySize() ).arg( theSampleSize ).arg( bApproxOK ) );
1368+
13651369
QgsGdalProgress myProg;
13661370
myProg.type = ProgressHistogram;
13671371
myProg.provider = this;
@@ -2042,7 +2046,7 @@ bool QgsGdalProvider::hasStatistics( int theBandNo,
20422046
int bApproxOK = false;
20432047
if ( theSampleSize > 0 )
20442048
{
2045-
if (( xSize() * ySize() / theSampleSize ) > 2 ) // not perfect
2049+
if ((( double )xSize() * ( double )ySize() / theSampleSize ) > 2 ) // not perfect
20462050
{
20472051
bApproxOK = true;
20482052
}
@@ -2119,7 +2123,7 @@ QgsRasterBandStats QgsGdalProvider::bandStatistics( int theBandNo, int theStats,
21192123
int bApproxOK = false;
21202124
if ( theSampleSize > 0 )
21212125
{
2122-
if (( xSize() * ySize() / theSampleSize ) > 2 ) // not perfect
2126+
if ((( double )xSize() * ( double )ySize() / theSampleSize ) > 2 ) // not perfect
21232127
{
21242128
bApproxOK = true;
21252129
}

0 commit comments

Comments
 (0)