Skip to content
Permalink
Browse files

fix NoData handling in getCellValuesFromBlockStack()

  • Loading branch information
root676 authored and nyalldawson committed Jul 2, 2020
1 parent 4181149 commit 2d2ad2c5f8a790b79503162d93d525dc129c858e
@@ -249,11 +249,11 @@ QVariantMap QgsCellStatisticsAlgorithm::processAlgorithm( const QVariantMap &par
for ( int col = 0; col < iterCols; col++ )
{
double result = 0;
bool hasNoData = false;
std::vector<double> cellValues = QgsRasterAnalysisUtils::getCellValuesFromBlockStack( inputBlocks, row, col, hasNoData );
bool noDataInStack = false;
std::vector<double> cellValues = QgsRasterAnalysisUtils::getCellValuesFromBlockStack( inputBlocks, row, col, noDataInStack );
int cellValueStackSize = cellValues.size();

if ( hasNoData && !mIgnoreNoData )
if ( noDataInStack && !mIgnoreNoData )
{
//output cell will always be NoData if NoData occurs in cellValueStack and NoData is not ignored
//this saves unnecessary iterations on the cellValueStack
@@ -264,7 +264,7 @@ QVariantMap QgsCellStatisticsAlgorithm::processAlgorithm( const QVariantMap &par
outputBlock->setValue( row, col, mNoDataValue );
}
}
else if ( !hasNoData || (hasNoData && mIgnoreNoData) )
else if ( !noDataInStack || (noDataInStack && mIgnoreNoData) )
{
switch ( statisticMethodIdx )
{
@@ -287,26 +287,33 @@ void QgsRasterAnalysisUtils::applyRasterLogicOperator( const std::vector< QgsRas
destinationRaster->setEditable( false );
}

std::vector<double> QgsRasterAnalysisUtils::getCellValuesFromBlockStack( const std::vector< std::unique_ptr< QgsRasterBlock > > &inputBlocks, int &row, int &col, bool &hasNoData )
std::vector<double> QgsRasterAnalysisUtils::getCellValuesFromBlockStack( const std::vector< std::unique_ptr< QgsRasterBlock > > &inputBlocks, int &row, int &col, bool &noDataInStack )
{
//get all values from inputBlocks
std::vector<double> cellValues;
bool hasNoData = false;
cellValues.reserve( inputBlocks.size() );

for ( auto &block : inputBlocks )
{
double value = 0;
if ( !block || !block->isValid() )
{
hasNoData = true;
noDataInStack = true;
break;
}
else
{
value = block->valueAndNoData( row, col, hasNoData );
if ( hasNoData )
break;
cellValues.push_back( value );
{
noDataInStack = true;
continue; //NoData is not included in the cell value vector
}
else
{
cellValues.push_back( value );
}
}
}
return cellValues;
@@ -94,7 +94,7 @@ namespace QgsRasterAnalysisUtils
/**
* Returns a vector of double values obtained from a stack of input QgsRasterBlocks
*/
std::vector<double> getCellValuesFromBlockStack( const std::vector< std::unique_ptr< QgsRasterBlock > > &inputBlocks, int &row, int &col, bool &hasNoData );
std::vector<double> getCellValuesFromBlockStack( const std::vector< std::unique_ptr< QgsRasterBlock > > &inputBlocks, int &row, int &col, bool &noDataInStack );

/**
* Returns the arithmetic mean from a vector of cell values

0 comments on commit 2d2ad2c

Please sign in to comment.
You can’t perform that action at this time.