Skip to content
Permalink
Browse files

Fix paletted raster renderer does not respect correct band when rende…

…ring

Fixes #21505
  • Loading branch information
nyalldawson committed Mar 7, 2019
1 parent aaa5ee0 commit 12ba41750f8058a3f0a504515255cdbc180955b3
@@ -119,15 +119,15 @@ void QgsPalettedRasterRenderer::setLabel( int idx, const QString &label )
}
}

QgsRasterBlock *QgsPalettedRasterRenderer::block( int bandNo, QgsRectangle const &extent, int width, int height, QgsRasterBlockFeedback *feedback )
QgsRasterBlock *QgsPalettedRasterRenderer::block( int, QgsRectangle const &extent, int width, int height, QgsRasterBlockFeedback *feedback )
{
std::unique_ptr< QgsRasterBlock > outputBlock( new QgsRasterBlock() );
if ( !mInput || mClassData.isEmpty() )
{
return outputBlock.release();
}

std::shared_ptr< QgsRasterBlock > inputBlock( mInput->block( bandNo, extent, width, height, feedback ) );
std::shared_ptr< QgsRasterBlock > inputBlock( mInput->block( mBand, extent, width, height, feedback ) );

if ( !inputBlock || inputBlock->isEmpty() )
{
@@ -401,6 +401,47 @@ def testPaletted(self):

self.assertTrue(checker.runTest("expected_paletted_renderer"), "Paletted rendering test failed")

def testPalettedBand(self):
""" test paletted raster render band"""
path = os.path.join(unitTestDataPath(),
'landsat_4326.tif')
info = QFileInfo(path)
base_name = info.baseName()
layer = QgsRasterLayer(path, base_name)
self.assertTrue(layer.isValid(), 'Raster not loaded: {}'.format(path))

renderer = QgsPalettedRasterRenderer(layer.dataProvider(), 2,
[QgsPalettedRasterRenderer.Class(137, QColor(0, 255, 0), 'class 2'),
QgsPalettedRasterRenderer.Class(138, QColor(255, 0, 0), 'class 1'),
QgsPalettedRasterRenderer.Class(139, QColor(0, 0, 255), 'class 1')])

layer.setRenderer(renderer)
ms = QgsMapSettings()
ms.setLayers([layer])
ms.setExtent(layer.extent())

checker = QgsRenderChecker()
checker.setControlName("expected_paletted_renderer_band2")
checker.setMapSettings(ms)

self.assertTrue(checker.runTest("expected_paletted_renderer_band2"), "Paletted rendering test failed")

renderer = QgsPalettedRasterRenderer(layer.dataProvider(), 3,
[QgsPalettedRasterRenderer.Class(120, QColor(0, 255, 0), 'class 2'),
QgsPalettedRasterRenderer.Class(123, QColor(255, 0, 0), 'class 1'),
QgsPalettedRasterRenderer.Class(124, QColor(0, 0, 255), 'class 1')])

layer.setRenderer(renderer)
ms = QgsMapSettings()
ms.setLayers([layer])
ms.setExtent(layer.extent())

checker = QgsRenderChecker()
checker.setControlName("expected_paletted_renderer_band3")
checker.setMapSettings(ms)

self.assertTrue(checker.runTest("expected_paletted_renderer_band3"), "Paletted rendering test failed")

def testPalettedColorTableToClassData(self):
entries = [QgsColorRampShader.ColorRampItem(5, QColor(255, 0, 0), 'item1'),
QgsColorRampShader.ColorRampItem(3, QColor(0, 255, 0), 'item2'),
Binary file not shown.
Binary file not shown.

0 comments on commit 12ba417

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