Skip to content
Permalink
Browse files

GRASS raster rendered by default as pseudo color, color table loaded …

…from GRASS
  • Loading branch information
blazek committed Sep 5, 2012
1 parent 7b05793 commit 08bd084aa8ca5613fa69a29bd50d5984c99f4321
@@ -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,
@@ -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
@@ -1800,6 +1800,10 @@ void QgsRasterLayer::setDataProvider( QString const & provider )
{
mRasterType = Palette;
}
else if ( mDataProvider->colorInterpretation( 1 ) == QgsRasterDataProvider::ContinuousPalette )
{
mRasterType = Palette;
}
else
{
mRasterType = GrayOrUndefined;
@@ -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
@@ -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 )
{
@@ -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 );
}
}
}
@@ -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;
}

0 comments on commit 08bd084

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