Skip to content

Commit

Permalink
Fix first stop color for discrete RATs
Browse files Browse the repository at this point in the history
  • Loading branch information
elpaso authored and nyalldawson committed Nov 8, 2022
1 parent 09e71a0 commit 5ed5b06
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/core/raster/qgsrasterattributetable.cpp
Expand Up @@ -1406,15 +1406,16 @@ QgsGradientColorRamp QgsRasterAttributeTable::colorRamp( QStringList &labels, co
};

// Case 1: range classes, discrete colors
// Create stops for the lower value of each class except for the first.
// Create stops for the lower value of each class except for the first use
// the color from the previous class
if ( orderedRat.hasColor() && isRange )
{
labels.push_back( labelFromField( 0 ) );

for ( int rowIdx = 1; rowIdx < orderedRat.data().count(); ++rowIdx )
{
const double offset { ( orderedRat.value( rowIdx, minIdx ).toDouble( ) - min ) / range };
const QColor color { orderedRat.color( rowIdx ) };
const QColor color { orderedRat.color( rowIdx - 1 ) };
stops.append( QgsGradientStop( offset, color ) );
labels.push_back( labelFromField( rowIdx ) );
}
Expand Down
2 changes: 1 addition & 1 deletion tests/src/python/test_qgsrasterattributetable.py
Expand Up @@ -716,7 +716,7 @@ def testRamp(self):
self.assertEqual(func.minimumValue(), 0.0)
self.assertEqual(func.maximumValue(), 2.99999)

self.assertEqual([(int(100 * st.offset), st.color.name()) for st in func.sourceColorRamp().stops()], [(66, '#ff0000'), (86, '#00ff00')])
self.assertEqual([(int(100 * st.offset), st.color.name()) for st in func.sourceColorRamp().stops()], [(66, '#0000ff'), (86, '#ff0000')])

# Test range classes and colors
rat = QgsRasterAttributeTable()
Expand Down

0 comments on commit 5ed5b06

Please sign in to comment.