Skip to content
Permalink
Browse files

Fix raster calculator with multiband rasters

Fixes #21151
  • Loading branch information
elpaso committed Mar 7, 2019
1 parent 3919eef commit a2b4c21137cee13331a5aeebc43af9884d9a440c
Showing with 16 additions and 4 deletions.
  1. +12 −3 src/analysis/raster/qgsrastercalculator.cpp
  2. +4 −1 tests/src/analysis/testqgsrastercalculator.cpp
@@ -636,9 +636,18 @@ QVector<QgsRasterCalculatorEntry> QgsRasterCalculatorEntry::rasterEntries()
// Safety belt
if ( !( entry.raster && ref.raster ) )
continue;
// Check if a layer with the same data source was already added to the list
// Check if is another band of the same raster
if ( ref.raster->publicSource() == entry.raster->publicSource() )
return false;
{
if ( ref.bandNumber != entry.bandNumber )
{
continue;
}
else // a layer with the same data source was already added to the list
{
return false;
}
}
// If same name but different source
if ( ref.ref == entry.ref )
{
@@ -664,7 +673,7 @@ QVector<QgsRasterCalculatorEntry> QgsRasterCalculatorEntry::rasterEntries()
entry.raster = rlayer;
entry.bandNumber = i + 1;
if ( ! uniqueRasterBandIdentifier( entry ) )
continue;
break;
availableEntries.push_back( entry );
}
}
@@ -583,7 +583,10 @@ void TestQgsRasterCalculator::testRasterEntries()
}
QStringList keys( entryMap.keys() );
keys.sort();
QCOMPARE( keys.join( ',' ), QStringLiteral( "dem@1,dem_1@1,landsat@1,landsat_4326@1,slope2@1" ) );
QCOMPARE( keys.join( ',' ), QStringLiteral( "dem@1,dem_1@1,landsat@1,landsat@2,landsat@3,landsat@4,"
"landsat@5,landsat@6,landsat@7,landsat@8,landsat@9,"
"landsat_4326@1,landsat_4326@2,landsat_4326@3,landsat_4326@4,"
"landsat_4326@5,landsat_4326@6,landsat_4326@7,landsat_4326@8,landsat_4326@9,slope2@1" ) );
}

void TestQgsRasterCalculator::errors( )

0 comments on commit a2b4c21

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