Skip to content
Permalink
Browse files

Clean QgsRasterLayer

  • Loading branch information
mhugent committed Jun 22, 2012
1 parent d3f8702 commit 86e9129c616ac7a83979924087d3065e6c0dd8a5
Showing with 0 additions and 195 deletions.
  1. +0 −195 src/core/raster/qgsrasterlayer.cpp
@@ -595,201 +595,6 @@ QString QgsRasterLayer::contrastEnhancementAlgorithmAsString() const
void QgsRasterLayer::setRendererForDrawingStyle( const DrawingStyle & theDrawingStyle )
{
setRenderer( QgsRasterRendererRegistry::instance()->defaultRendererForDrawingStyle( theDrawingStyle, mDataProvider ) );
#if 0
QgsRasterRenderer* renderer = 0;

switch ( theDrawingStyle )
{
case PalettedColor:
{
int grayBand = bandNumber( grayBandName() );
QgsColorRampShader* colorRampShader = dynamic_cast<QgsColorRampShader*>( rasterShader()->rasterShaderFunction() );
if ( colorRampShader )
{
QList<QgsColorRampShader::ColorRampItem> colorEntries = colorRampShader->colorRampItemList();

//go through list and take maximum value (it could be that entries don't start at 0 or indices are not contiguous)
int colorArraySize = 0;
QList<QgsColorRampShader::ColorRampItem>::const_iterator colorIt = colorEntries.constBegin();
for ( ; colorIt != colorEntries.constEnd(); ++colorIt )
{
if ( colorIt->value > colorArraySize )
{
colorArraySize = ( int )( colorIt->value );
}
}

colorArraySize += 1; //usually starts at 0
QColor* colorArray = new QColor[ colorArraySize ];
colorIt = colorEntries.constBegin();
for ( ; colorIt != colorEntries.constEnd(); ++colorIt )
{
colorArray[( int )( colorIt->value )] = colorIt->color;
}

renderer = new QgsPalettedRasterRenderer( mDataProvider,
grayBand,
colorArray,
colorArraySize );
}
else //try to get it from the color table
{
QList<QgsColorRampShader::ColorRampItem> itemList = mRasterStatsList[ grayBand - 1].colorTable;
QColor* colorArray = new QColor[itemList.size()];
QList<QgsColorRampShader::ColorRampItem>::const_iterator colorIt = itemList.constBegin();
for ( ; colorIt != itemList.constEnd(); ++colorIt )
{
colorArray[( int )colorIt->value] = colorIt->color;
}
renderer = new QgsPalettedRasterRenderer( mDataProvider,
grayBand, colorArray, itemList.size() );
}
break;
}
case MultiBandSingleBandGray:
case SingleBandGray:
{
int grayBand = bandNumber( mGrayBandName );
renderer = new QgsSingleBandGrayRenderer( mDataProvider, grayBand );
QgsContrastEnhancement* ce = new QgsContrastEnhancement(( QgsContrastEnhancement::QgsRasterDataType )(
mDataProvider->dataType( grayBand ) ) );
ce->setContrastEnhancementAlgorithm( contrastEnhancementAlgorithm() );
if ( QgsContrastEnhancement::NoEnhancement != contrastEnhancementAlgorithm() && !mUserDefinedGrayMinimumMaximum && mStandardDeviations > 0 )
{
QgsRasterBandStats myGrayBandStats = bandStatistics( grayBand );
ce->setMinimumValue( myGrayBandStats.mean - ( mStandardDeviations * myGrayBandStats.stdDev ) );
ce->setMaximumValue( myGrayBandStats.mean + ( mStandardDeviations * myGrayBandStats.stdDev ) );
}
else if ( QgsContrastEnhancement::NoEnhancement != contrastEnhancementAlgorithm() && !mUserDefinedGrayMinimumMaximum )
{
ce->setMinimumValue( mDataProvider->minimumValue( grayBand ) );
ce->setMaximumValue( mDataProvider->maximumValue( grayBand ) );
}
(( QgsSingleBandGrayRenderer* )renderer )->setContrastEnhancement( ce );
break;
}
case SingleBandPseudoColor:
{
int bandNo = bandNumber( mGrayBandName );
QgsRasterBandStats myRasterBandStats = bandStatistics( bandNo );
double myMinimumValue = 0.0;
double myMaximumValue = 0.0;
//Use standard deviations if set, otherwise, use min max of band
if ( mStandardDeviations > 0 )
{
myMinimumValue = ( myRasterBandStats.mean - ( mStandardDeviations * myRasterBandStats.stdDev ) );
myMaximumValue = ( myRasterBandStats.mean + ( mStandardDeviations * myRasterBandStats.stdDev ) );
}
else
{
myMinimumValue = myRasterBandStats.minimumValue;
myMaximumValue = myRasterBandStats.maximumValue;
}

mRasterShader->setMinimumValue( myMinimumValue );
mRasterShader->setMaximumValue( myMaximumValue );

renderer = new QgsSingleBandPseudoColorRenderer( mDataProvider, bandNo, mRasterShader );
break;
}
case MultiBandColor:
{
int red = -1;
QgsContrastEnhancement* redEnhancement = 0;
if ( mRedBandName != TRSTRING_NOT_SET )
{
red = bandNumber( mRedBandName );
if ( contrastEnhancementAlgorithm() != QgsContrastEnhancement::NoEnhancement )
{
QgsContrastEnhancement* bkRedEnhancement = contrastEnhancement( red );
if ( bkRedEnhancement )
{
redEnhancement = new QgsContrastEnhancement(( QgsContrastEnhancement::QgsRasterDataType )(
mDataProvider->dataType( red ) ) );
redEnhancement->setMinimumValue( bkRedEnhancement->minimumValue() );
redEnhancement->setMaximumValue( bkRedEnhancement->maximumValue() );
redEnhancement->setContrastEnhancementAlgorithm( contrastEnhancementAlgorithm() );
}
}
}
int green = -1;
QgsContrastEnhancement* greenEnhancement = 0;
if ( mGreenBandName != TRSTRING_NOT_SET )
{
green = bandNumber( mGreenBandName );
if ( contrastEnhancementAlgorithm() != QgsContrastEnhancement::NoEnhancement )
{
QgsContrastEnhancement* bkGreenEnhancement = contrastEnhancement( green );
if ( bkGreenEnhancement )
{
greenEnhancement = new QgsContrastEnhancement(( QgsContrastEnhancement::QgsRasterDataType )(
mDataProvider->dataType( green ) ) );
greenEnhancement->setMinimumValue( bkGreenEnhancement->minimumValue() );
greenEnhancement->setMaximumValue( bkGreenEnhancement->maximumValue() );
greenEnhancement->setContrastEnhancementAlgorithm( contrastEnhancementAlgorithm() );
}
}
}
int blue = -1;
QgsContrastEnhancement* blueEnhancement = 0;
if ( mBlueBandName != TRSTRING_NOT_SET )
{
blue = bandNumber( mBlueBandName );
if ( contrastEnhancementAlgorithm() != QgsContrastEnhancement::NoEnhancement )
{
QgsContrastEnhancement* bkBlueEnhancement = contrastEnhancement( blue );
if ( bkBlueEnhancement )
{
blueEnhancement = new QgsContrastEnhancement(( QgsContrastEnhancement::QgsRasterDataType )(
mDataProvider->dataType( blue ) ) );
blueEnhancement->setMinimumValue( bkBlueEnhancement->minimumValue() );
blueEnhancement->setMaximumValue( bkBlueEnhancement->maximumValue() );
blueEnhancement->setContrastEnhancementAlgorithm( contrastEnhancementAlgorithm() );
}
}
}
renderer = new QgsMultiBandColorRenderer( mDataProvider, red, green, blue,
redEnhancement, greenEnhancement, blueEnhancement );
break;
}
case SingleBandColorDataStyle:
{
renderer = new QgsSingleBandColorDataRenderer( mDataProvider, bandNumber( mGrayBandName ) );
break;
}
default:
break;
}

if ( !renderer )
{
return;
}

renderer->setOpacity( mTransparencyLevel / 255.0 );

QgsRasterTransparency* tr = new QgsRasterTransparency(); //renderer takes ownership
if ( mDataProvider->bandCount() == 1 )
{
tr->setTransparentSingleValuePixelList( mRasterTransparency.transparentSingleValuePixelList() );
}
else if ( mDataProvider->bandCount() == 3 )
{
tr->setTransparentThreeValuePixelList( mRasterTransparency.transparentThreeValuePixelList() );
}
renderer->setRasterTransparency( tr );

if ( mTransparencyBandName != TRSTRING_NOT_SET )
{
int tBand = bandNumber( mTransparencyBandName );
if ( tBand > 0 )
{
renderer->setAlphaBand( tBand );
}
}
renderer->setInvertColor( mInvertColor );
setRenderer( renderer );
#endif //0
}

/**

0 comments on commit 86e9129

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