Skip to content

Commit

Permalink
GRASS raster rendered by default as pseudo color, color table loaded …
Browse files Browse the repository at this point in the history
…from GRASS
  • Loading branch information
blazek committed Sep 5, 2012
1 parent 7b05793 commit 08bd084
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 8 deletions.
5 changes: 3 additions & 2 deletions src/core/qgsrasterdataprovider.h
Expand Up @@ -76,7 +76,7 @@ class CORE_EXPORT QgsRasterDataProvider : public QgsDataProvider, public QgsRast
{
UndefinedColorInterpretation = 0,
/*! Greyscale */ GrayIndex = 1,
/*! Paletted (see associated color table) */ PaletteIndex = 2,
/*! Paletted (see associated color table) */ PaletteIndex = 2, // indexed color table
/*! Red band of RGBA image */ RedBand = 3,
/*! Green band of RGBA image */ GreenBand = 4,
/*! Blue band of RGBA image */ BlueBand = 5,
Expand All @@ -91,7 +91,8 @@ class CORE_EXPORT QgsRasterDataProvider : public QgsDataProvider, public QgsRast
/*! Y Luminance */ YCbCr_YBand = 14,
/*! Cb Chroma */ YCbCr_CbBand = 15,
/*! Cr Chroma */ YCbCr_CrBand = 16,
/*! Max current value */ ColorInterpretationMax = 16
/*! Continuous palette, QGIS addition, GRASS */ ContinuousPalette = 17,
/*! Max current value */ ColorInterpretationMax = 17
};

// Progress types
Expand Down
24 changes: 22 additions & 2 deletions src/core/raster/qgsrasterlayer.cpp
Expand Up @@ -1800,6 +1800,10 @@ void QgsRasterLayer::setDataProvider( QString const & provider )
{
mRasterType = Palette;
}
else if ( mDataProvider->colorInterpretation( 1 ) == QgsRasterDataProvider::ContinuousPalette )
{
mRasterType = Palette;
}
else
{
mRasterType = GrayOrUndefined;
Expand All @@ -1811,11 +1815,27 @@ void QgsRasterLayer::setDataProvider( QString const & provider )
QgsDebugMsg( "Setting mDrawingStyle to SingleBandColorDataStyle " + QString::number( SingleBandColorDataStyle ) );
setDrawingStyle( SingleBandColorDataStyle );
}
else if ( mRasterType == Palette )
else if ( mRasterType == Palette && mDataProvider->colorInterpretation( 1 ) == QgsRasterDataProvider::PaletteIndex )
{

setDrawingStyle( PalettedColor ); //sensible default
}
else if ( mRasterType == Palette && mDataProvider->colorInterpretation( 1 ) == QgsRasterDataProvider::ContinuousPalette )
{
setDrawingStyle( SingleBandPseudoColor );
// Load color table
QList<QgsColorRampShader::ColorRampItem> colorTable = mDataProvider->colorTable( 1 );
QgsSingleBandPseudoColorRenderer* r = dynamic_cast<QgsSingleBandPseudoColorRenderer*>( renderer() );
if ( r )
{
// TODO: this should go somewhere else
QgsRasterShader* shader = new QgsRasterShader();
QgsColorRampShader* colorRampShader = new QgsColorRampShader();
colorRampShader->setColorRampType( QgsColorRampShader::INTERPOLATED );
colorRampShader->setColorRampItemList( colorTable );
shader->setRasterShaderFunction( colorRampShader );
r->setShader( shader );
}
}
else if ( mRasterType == Multiband )
{
setDrawingStyle( MultiBandColor ); //sensible default
Expand Down
6 changes: 3 additions & 3 deletions src/providers/grass/qgis.g.info.c
Expand Up @@ -147,8 +147,8 @@ int main( int argc, char **argv )
G_fatal_error(( "Unable to read range file" ) );
}
G_get_fp_range_min_max( &range, &zmin, &zmax );
fprintf( stdout, "MIN_VALUE:%f\n", zmin );
fprintf( stdout, "MAX_VALUE:%f\n", zmax );
fprintf( stdout, "MIN_VALUE:%.17e\n", zmin );
fprintf( stdout, "MAX_VALUE:%.17e\n", zmax );
}
else if ( strcmp( "colors", info_opt->answer ) == 0 )
{
Expand All @@ -168,7 +168,7 @@ int main( int argc, char **argv )
unsigned char r1, g1, b1, r2, g2, b2;

G_get_f_color_rule( &val1, &r1, &g1, &b1, &val2, &r2, &g2, &b2, &colors, i );
fprintf( stdout, "%e %e %d %d %d %d %d %d\n", val1, val2, r1, g1, b1, r2, g2, b2 );
fprintf( stdout, "%.17e %.17e %d %d %d %d %d %d\n", val1, val2, r1, g1, b1, r2, g2, b2 );
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/providers/grass/qgsgrassrasterprovider.cpp
Expand Up @@ -493,7 +493,7 @@ int QgsGrassRasterProvider::colorInterpretation( int bandNo ) const
QList<QgsColorRampShader::ColorRampItem> ct = colorTable( bandNo );
if ( ct.size() > 0 )
{
return QgsRasterDataProvider::PaletteIndex;
return QgsRasterDataProvider::ContinuousPalette;
}
return QgsRasterDataProvider::GrayIndex;
}
Expand Down

0 comments on commit 08bd084

Please sign in to comment.