Skip to content

Commit 08bd084

Browse files
committedSep 5, 2012
GRASS raster rendered by default as pseudo color, color table loaded from GRASS
1 parent 7b05793 commit 08bd084

File tree

4 files changed

+29
-8
lines changed

4 files changed

+29
-8
lines changed
 

‎src/core/qgsrasterdataprovider.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class CORE_EXPORT QgsRasterDataProvider : public QgsDataProvider, public QgsRast
7676
{
7777
UndefinedColorInterpretation = 0,
7878
/*! Greyscale */ GrayIndex = 1,
79-
/*! Paletted (see associated color table) */ PaletteIndex = 2,
79+
/*! Paletted (see associated color table) */ PaletteIndex = 2, // indexed color table
8080
/*! Red band of RGBA image */ RedBand = 3,
8181
/*! Green band of RGBA image */ GreenBand = 4,
8282
/*! Blue band of RGBA image */ BlueBand = 5,
@@ -91,7 +91,8 @@ class CORE_EXPORT QgsRasterDataProvider : public QgsDataProvider, public QgsRast
9191
/*! Y Luminance */ YCbCr_YBand = 14,
9292
/*! Cb Chroma */ YCbCr_CbBand = 15,
9393
/*! Cr Chroma */ YCbCr_CrBand = 16,
94-
/*! Max current value */ ColorInterpretationMax = 16
94+
/*! Continuous palette, QGIS addition, GRASS */ ContinuousPalette = 17,
95+
/*! Max current value */ ColorInterpretationMax = 17
9596
};
9697

9798
// Progress types

‎src/core/raster/qgsrasterlayer.cpp

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1800,6 +1800,10 @@ void QgsRasterLayer::setDataProvider( QString const & provider )
18001800
{
18011801
mRasterType = Palette;
18021802
}
1803+
else if ( mDataProvider->colorInterpretation( 1 ) == QgsRasterDataProvider::ContinuousPalette )
1804+
{
1805+
mRasterType = Palette;
1806+
}
18031807
else
18041808
{
18051809
mRasterType = GrayOrUndefined;
@@ -1811,11 +1815,27 @@ void QgsRasterLayer::setDataProvider( QString const & provider )
18111815
QgsDebugMsg( "Setting mDrawingStyle to SingleBandColorDataStyle " + QString::number( SingleBandColorDataStyle ) );
18121816
setDrawingStyle( SingleBandColorDataStyle );
18131817
}
1814-
else if ( mRasterType == Palette )
1818+
else if ( mRasterType == Palette && mDataProvider->colorInterpretation( 1 ) == QgsRasterDataProvider::PaletteIndex )
18151819
{
1816-
18171820
setDrawingStyle( PalettedColor ); //sensible default
18181821
}
1822+
else if ( mRasterType == Palette && mDataProvider->colorInterpretation( 1 ) == QgsRasterDataProvider::ContinuousPalette )
1823+
{
1824+
setDrawingStyle( SingleBandPseudoColor );
1825+
// Load color table
1826+
QList<QgsColorRampShader::ColorRampItem> colorTable = mDataProvider->colorTable( 1 );
1827+
QgsSingleBandPseudoColorRenderer* r = dynamic_cast<QgsSingleBandPseudoColorRenderer*>( renderer() );
1828+
if ( r )
1829+
{
1830+
// TODO: this should go somewhere else
1831+
QgsRasterShader* shader = new QgsRasterShader();
1832+
QgsColorRampShader* colorRampShader = new QgsColorRampShader();
1833+
colorRampShader->setColorRampType( QgsColorRampShader::INTERPOLATED );
1834+
colorRampShader->setColorRampItemList( colorTable );
1835+
shader->setRasterShaderFunction( colorRampShader );
1836+
r->setShader( shader );
1837+
}
1838+
}
18191839
else if ( mRasterType == Multiband )
18201840
{
18211841
setDrawingStyle( MultiBandColor ); //sensible default

‎src/providers/grass/qgis.g.info.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,8 @@ int main( int argc, char **argv )
147147
G_fatal_error(( "Unable to read range file" ) );
148148
}
149149
G_get_fp_range_min_max( &range, &zmin, &zmax );
150-
fprintf( stdout, "MIN_VALUE:%f\n", zmin );
151-
fprintf( stdout, "MAX_VALUE:%f\n", zmax );
150+
fprintf( stdout, "MIN_VALUE:%.17e\n", zmin );
151+
fprintf( stdout, "MAX_VALUE:%.17e\n", zmax );
152152
}
153153
else if ( strcmp( "colors", info_opt->answer ) == 0 )
154154
{
@@ -168,7 +168,7 @@ int main( int argc, char **argv )
168168
unsigned char r1, g1, b1, r2, g2, b2;
169169

170170
G_get_f_color_rule( &val1, &r1, &g1, &b1, &val2, &r2, &g2, &b2, &colors, i );
171-
fprintf( stdout, "%e %e %d %d %d %d %d %d\n", val1, val2, r1, g1, b1, r2, g2, b2 );
171+
fprintf( stdout, "%.17e %.17e %d %d %d %d %d %d\n", val1, val2, r1, g1, b1, r2, g2, b2 );
172172
}
173173
}
174174
}

‎src/providers/grass/qgsgrassrasterprovider.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ int QgsGrassRasterProvider::colorInterpretation( int bandNo ) const
493493
QList<QgsColorRampShader::ColorRampItem> ct = colorTable( bandNo );
494494
if ( ct.size() > 0 )
495495
{
496-
return QgsRasterDataProvider::PaletteIndex;
496+
return QgsRasterDataProvider::ContinuousPalette;
497497
}
498498
return QgsRasterDataProvider::GrayIndex;
499499
}

0 commit comments

Comments
 (0)
Please sign in to comment.