Skip to content
Permalink
Browse files

optimize data extraction from QgsRasterBlocks

  • Loading branch information
root676 authored and nyalldawson committed Jul 28, 2020
1 parent b956981 commit b83bb8bbec3c780d563a9ed0ffc9bd5796f1f2a9
Showing with 15 additions and 7 deletions.
  1. +15 −7 src/analysis/processing/qgsalgorithmrasterfrequencybycomparisonoperator.cpp
@@ -173,13 +173,10 @@ QVariantMap QgsRasterFrequencyByComparisonOperatorBase::processAlgorithm( const

for ( int col = 0; col < iterCols; col++ )
{
bool noDataInStack = false;
std::vector<double> cellValues = QgsRasterAnalysisUtils::getCellValuesFromBlockStack( inputBlocks, row, col, noDataInStack );

bool valueRasterCellIsNoData = false;
double value = inputBlock->valueAndNoData( row, col, valueRasterCellIsNoData );

if ( ( valueRasterCellIsNoData || noDataInStack ) && !mIgnoreNoData )
if ( valueRasterCellIsNoData && !mIgnoreNoData )
{
//output cell will always be NoData if NoData occurs in valueRaster or cellValueStack and NoData is not ignored
//this saves unnecessary iterations on the cellValueStack
@@ -188,9 +185,20 @@ QVariantMap QgsRasterFrequencyByComparisonOperatorBase::processAlgorithm( const
}
else
{
int frequency = applyComparisonOperator( value, cellValues );
outputBlock->setValue( row, col, frequency );
occurrenceCount += frequency;
bool noDataInStack = false;
std::vector<double> cellValues = QgsRasterAnalysisUtils::getCellValuesFromBlockStack( inputBlocks, row, col, noDataInStack );

if( noDataInStack && !mIgnoreNoData )
{
outputBlock->setValue( row, col, mNoDataValue );
noDataLocationsCount++;
}
else
{
int frequency = applyComparisonOperator( value, cellValues );
outputBlock->setValue( row, col, frequency );
occurrenceCount += frequency;
}
}
}
}

0 comments on commit b83bb8b

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