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 authored and github-actions[bot] committed Nov 3, 2021
1 parent ec467dd commit b717f01
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions src/core/raster/qgsrasterdataprovider.cpp
Expand Up @@ -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;
}
}
Expand Down

0 comments on commit b717f01

Please sign in to comment.