Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
avoid creating a histogram without range (fixes #11217)
  • Loading branch information
jef-n committed Oct 16, 2014
1 parent d05b039 commit 086b262
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/core/raster/qgsrasterinterface.cpp
Expand Up @@ -517,17 +517,20 @@ void QgsRasterInterface::cumulativeCut( int theBandNo,

int mySrcDataType = srcDataType( theBandNo );

// Init to NaN is better than histogram min/max to catch errors
theLowerValue = std::numeric_limits<double>::quiet_NaN();
theUpperValue = std::numeric_limits<double>::quiet_NaN();

//get band stats to specify real histogram min/max (fix #9793 Byte bands)
QgsRasterBandStats stats = bandStatistics( theBandNo, QgsRasterBandStats::Min, theExtent, theSampleSize );
if( stats.maximumValue < stats.minimumValue )
return;

// for byte bands make sure bin count == actual range
int myBinCount = ( mySrcDataType == QGis::Byte ) ? int( ceil( stats.maximumValue - stats.minimumValue + 1 ) ) : 0;
QgsRasterHistogram myHistogram = histogram( theBandNo, myBinCount, stats.minimumValue, stats.maximumValue, theExtent, theSampleSize );
//QgsRasterHistogram myHistogram = histogram( theBandNo, 0, std::numeric_limits<double>::quiet_NaN(), std::numeric_limits<double>::quiet_NaN(), theExtent, theSampleSize );

// Init to NaN is better than histogram min/max to catch errors
theLowerValue = std::numeric_limits<double>::quiet_NaN();
theUpperValue = std::numeric_limits<double>::quiet_NaN();

double myBinXStep = ( myHistogram.maximum - myHistogram.minimum ) / myHistogram.binCount;
int myCount = 0;
int myMinCount = ( int ) qRound( theLowerCount * myHistogram.nonNullCount );
Expand Down

0 comments on commit 086b262

Please sign in to comment.