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 authored and github-actions committed Nov 3, 2021
1 parent 1b3002e commit ab0185f5eed23382b9dfa18068cccbbf8fbbf052
Showing with 7 additions and 12 deletions.
  1. +7 −12 src/core/raster/qgsrasterdataprovider.cpp
@@ -397,19 +397,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 ab0185f

Please sign in to comment.