Skip to content
Permalink
Browse files

Merge pull request #39955 from qgis-bot/backport-39946-to-release-3_16

[Backport release-3_16] Raster calc nodata value
  • Loading branch information
elpaso committed Nov 11, 2020
2 parents bca43af + e0bf763 commit 981fe3af645f9c8c9b849c7905cacfe4bdcb2eb4
Showing with 13 additions and 2 deletions.
  1. +13 −2 src/analysis/raster/qgsrastercalculator.cpp
@@ -477,16 +477,27 @@ QgsRasterCalculator::Result QgsRasterCalculator::processCalculationGPU( std::uni
{
// Get the index of the current element
const int i = get_global_id(0);
// Check for nodata in input
if ( ##INPUT_NODATA_CHECK## )
resultLine[i] = -FLT_MAX;
// Expression
resultLine[i] = ##EXPRESSION##;
else
resultLine[i] = ##EXPRESSION##;
}
)CL" );

QStringList inputDesc;
QStringList inputNoDataCheck;
for ( const auto &ref : inputRefs )
{
inputDesc.append( QStringLiteral( " // %1 = %2" ).arg( ref.varName ).arg( ref.name ) );
if ( ref.layer->dataProvider()->sourceHasNoDataValue( ref.band ) )
{
inputNoDataCheck.append( QStringLiteral( "(float) %1[i] == (float) %2" ).arg( ref.varName ).arg( ref.layer->dataProvider()->sourceNoDataValue( ref.band ) ) );
}
}

programTemplate = programTemplate.replace( QLatin1String( "##INPUT_NODATA_CHECK##" ), inputNoDataCheck.isEmpty() ? QStringLiteral( "false" ) : inputNoDataCheck.join( QStringLiteral( " || " ) ) );
programTemplate = programTemplate.replace( QLatin1String( "##INPUT_DESC##" ), inputDesc.join( '\n' ) );
programTemplate = programTemplate.replace( QLatin1String( "##INPUT##" ), !inputArgs.isEmpty() ? ( inputArgs.join( ',' ).append( ',' ) ) : QChar( ' ' ) );
programTemplate = programTemplate.replace( QLatin1String( "##EXPRESSION##" ), cExpression );
@@ -536,7 +547,7 @@ QgsRasterCalculator::Result QgsRasterCalculator::processCalculationGPU( std::uni
if ( !outputRasterBand )
return BandError;

float outputNodataValue = -FLT_MAX;
const float outputNodataValue = -FLT_MAX;
GDALSetRasterNoDataValue( outputRasterBand, outputNodataValue );

// Input block (buffer)

0 comments on commit 981fe3a

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