Navigation Menu

Skip to content

Commit

Permalink
Merge pull request #9422 from elpaso/bugfix-21511-rastercalc-multiband
Browse files Browse the repository at this point in the history
Fix raster calculator with multiband rasters
  • Loading branch information
elpaso committed Mar 8, 2019
2 parents ec0ff4a + c5ef988 commit c732dfd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
15 changes: 12 additions & 3 deletions src/analysis/raster/qgsrastercalculator.cpp
Expand Up @@ -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 )
{
Expand All @@ -664,7 +673,7 @@ QVector<QgsRasterCalculatorEntry> QgsRasterCalculatorEntry::rasterEntries()
entry.raster = rlayer;
entry.bandNumber = i + 1;
if ( ! uniqueRasterBandIdentifier( entry ) )
continue;
break;
availableEntries.push_back( entry );
}
}
Expand Down
5 changes: 4 additions & 1 deletion tests/src/analysis/testqgsrastercalculator.cpp
Expand Up @@ -599,7 +599,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( )
Expand Down

0 comments on commit c732dfd

Please sign in to comment.