Skip to content

Commit

Permalink
Fix logic for clearing cached histograms when raster data provider us…
Browse files Browse the repository at this point in the history
…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 3, 2021
1 parent 4327b00 commit 6e1cde4
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions src/core/raster/qgsrasterdataprovider.cpp
Expand Up @@ -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;
}
}
Expand Down

0 comments on commit 6e1cde4

Please sign in to comment.