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 5d66725 commit aae76f8631f5ceba30b607c76e1911e945c4ca82
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 aae76f8

Please sign in to comment.