Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
consider user no data values in GDAL raster statistics and histogram,…
… fixes partialy #3840
  • Loading branch information
blazek committed Apr 3, 2013
1 parent bb9f1f0 commit 8e7ffd7
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions src/providers/gdal/qgsgdalprovider.cpp
Expand Up @@ -1133,6 +1133,13 @@ bool QgsGdalProvider::hasHistogram( int theBandNo,
return false;
}

if (( srcHasNoDataValue( theBandNo ) && !useSrcNoDataValue( theBandNo ) ) ||
userNoDataValue( theBandNo ).size() > 0 )
{
QgsDebugMsg( "Custom no data values -> GDAL histogram not sufficient." );
return false;
}

QgsDebugMsg( "Looking for GDAL histogram" );

GDALRasterBandH myGdalBand = GDALGetRasterBand( mGdalDataset, theBandNo );
Expand Down Expand Up @@ -1208,9 +1215,16 @@ QgsRasterHistogram QgsGdalProvider::histogram( int theBandNo,
}
}

if (( srcHasNoDataValue( theBandNo ) && !useSrcNoDataValue( theBandNo ) ) ||
userNoDataValue( theBandNo ).size() > 0 )
{
QgsDebugMsg( "Custom no data values, using generic histogram." );
return QgsRasterDataProvider::histogram( theBandNo, theBinCount, theMinimum, theMaximum, theExtent, theSampleSize, theIncludeOutOfRange );
}

if ( myHistogram.extent != extent() )
{
QgsDebugMsg( "Using generic histogram." );
QgsDebugMsg( "Not full extent, using generic histogram." );
return QgsRasterDataProvider::histogram( theBandNo, theBinCount, theMinimum, theMaximum, theExtent, theSampleSize, theIncludeOutOfRange );
}

Expand Down Expand Up @@ -2035,6 +2049,13 @@ bool QgsGdalProvider::hasStatistics( int theBandNo,
QgsRasterBandStats myRasterBandStats;
initStatistics( myRasterBandStats, theBandNo, theStats, theExtent, theSampleSize );

if (( srcHasNoDataValue( theBandNo ) && !useSrcNoDataValue( theBandNo ) ) ||
userNoDataValue( theBandNo ).size() > 0 )
{
QgsDebugMsg( "Custom no data values -> GDAL statistics not sufficient." );
return false;
}

// If not cached, check if supported by GDAL
int supportedStats = QgsRasterBandStats::Min | QgsRasterBandStats::Max
| QgsRasterBandStats::Range | QgsRasterBandStats::Mean
Expand Down Expand Up @@ -2120,6 +2141,15 @@ QgsRasterBandStats QgsGdalProvider::bandStatistics( int theBandNo, int theStats,
}
}

// We cannot use GDAL stats if user disabled src no data value or set
// custom no data values
if (( srcHasNoDataValue( theBandNo ) && !useSrcNoDataValue( theBandNo ) ) ||
userNoDataValue( theBandNo ).size() > 0 )
{
QgsDebugMsg( "Custom no data values, using generic statistics." );
return QgsRasterDataProvider::bandStatistics( theBandNo, theStats, theExtent, theSampleSize );
}

int supportedStats = QgsRasterBandStats::Min | QgsRasterBandStats::Max
| QgsRasterBandStats::Range | QgsRasterBandStats::Mean
| QgsRasterBandStats::StdDev;
Expand All @@ -2129,7 +2159,7 @@ QgsRasterBandStats QgsGdalProvider::bandStatistics( int theBandNo, int theStats,
if ( myRasterBandStats.extent != extent() ||
( theStats & ( ~supportedStats ) ) )
{
QgsDebugMsg( "Using generic statistics." );
QgsDebugMsg( "Statistics not supported by provider, using generic statistics." );
return QgsRasterDataProvider::bandStatistics( theBandNo, theStats, theExtent, theSampleSize );
}

Expand Down

0 comments on commit 8e7ffd7

Please sign in to comment.