Navigation Menu

Skip to content

Commit

Permalink
Fix paletted raster renderer does not respect correct band when rende…
Browse files Browse the repository at this point in the history
…ring

Fixes #21505
  • Loading branch information
nyalldawson committed Mar 7, 2019
1 parent fb19acf commit 76482cf
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/core/raster/qgspalettedrasterrenderer.cpp
Expand Up @@ -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() )
{
Expand Down
41 changes: 41 additions & 0 deletions tests/src/python/test_qgsrasterlayer.py
Expand Up @@ -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'),
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 76482cf

Please sign in to comment.