Skip to content

Commit 086b262

Browse files
committedOct 16, 2014
avoid creating a histogram without range (fixes #11217)
1 parent d05b039 commit 086b262

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed
 

‎src/core/raster/qgsrasterinterface.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -517,17 +517,20 @@ void QgsRasterInterface::cumulativeCut( int theBandNo,
517517

518518
int mySrcDataType = srcDataType( theBandNo );
519519

520+
// Init to NaN is better than histogram min/max to catch errors
521+
theLowerValue = std::numeric_limits<double>::quiet_NaN();
522+
theUpperValue = std::numeric_limits<double>::quiet_NaN();
523+
520524
//get band stats to specify real histogram min/max (fix #9793 Byte bands)
521525
QgsRasterBandStats stats = bandStatistics( theBandNo, QgsRasterBandStats::Min, theExtent, theSampleSize );
526+
if( stats.maximumValue < stats.minimumValue )
527+
return;
528+
522529
// for byte bands make sure bin count == actual range
523530
int myBinCount = ( mySrcDataType == QGis::Byte ) ? int( ceil( stats.maximumValue - stats.minimumValue + 1 ) ) : 0;
524531
QgsRasterHistogram myHistogram = histogram( theBandNo, myBinCount, stats.minimumValue, stats.maximumValue, theExtent, theSampleSize );
525532
//QgsRasterHistogram myHistogram = histogram( theBandNo, 0, std::numeric_limits<double>::quiet_NaN(), std::numeric_limits<double>::quiet_NaN(), theExtent, theSampleSize );
526533

527-
// Init to NaN is better than histogram min/max to catch errors
528-
theLowerValue = std::numeric_limits<double>::quiet_NaN();
529-
theUpperValue = std::numeric_limits<double>::quiet_NaN();
530-
531534
double myBinXStep = ( myHistogram.maximum - myHistogram.minimum ) / myHistogram.binCount;
532535
int myCount = 0;
533536
int myMinCount = ( int ) qRound( theLowerCount * myHistogram.nonNullCount );

0 commit comments

Comments
 (0)
Please sign in to comment.