Skip to content
Permalink
Browse files
Fix logic for clearing cached histograms when raster data provider us…
…er no data value is set

We can't assume that the cached histograms and stats lists are
always aligned. (Seen when TestQgsZonalStatistics::testNoData()
is run)
  • Loading branch information
nyalldawson committed Nov 7, 2021
1 parent 45e7993 commit b4c872432af5a06b20282fb1efd7653a99cf9316
Showing with 7 additions and 12 deletions.
  1. +7 −12 src/core/raster/qgsrasterdataprovider.cpp
@@ -400,19 +400,14 @@ void QgsRasterDataProvider::setUserNoDataValue( int bandNo, const QgsRasterRange
if ( mUserNoDataValue[bandNo - 1] != noData )
{
// Clear statistics
int i = 0;
while ( i < mStatistics.size() )
mStatistics.erase( std::remove_if( mStatistics.begin(), mStatistics.end(), [bandNo]( const QgsRasterBandStats & stats )
{
if ( mStatistics.value( i ).bandNumber == bandNo )
{
mStatistics.removeAt( i );
mHistograms.removeAt( i );
}
else
{
i++;
}
}
return stats.bandNumber == bandNo;
} ), mStatistics.end() );
mHistograms.erase( std::remove_if( mHistograms.begin(), mHistograms.end(), [bandNo]( const QgsRasterHistogram & histogram )
{
return histogram.bandNumber == bandNo;
} ), mHistograms.end() );
mUserNoDataValue[bandNo - 1] = noData;
}
}

0 comments on commit b4c8724

Please sign in to comment.