Skip to content
Permalink
Browse files
Improvements to single band gray renderer widget
  • Loading branch information
mhugent committed Mar 13, 2012
1 parent c7d284d commit 267c1e274e5aec04c8226943c74b83f71dd1eaf9
@@ -646,20 +646,21 @@ void QgsRasterLayer::setRendererForDrawingStyle( const DrawingStyle & theDrawin
{
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 )
{
mGrayMinimumMaximumEstimated = false;
QgsRasterBandStats myGrayBandStats = bandStatistics( grayBand );
setMaximumValue( grayBand, myGrayBandStats.mean + ( mStandardDeviations * myGrayBandStats.stdDev ) );
setMinimumValue( grayBand, myGrayBandStats.mean - ( mStandardDeviations * myGrayBandStats.stdDev ) );
ce->setMinimumValue( myGrayBandStats.mean - ( mStandardDeviations * myGrayBandStats.stdDev ) );
ce->setMaximumValue( myGrayBandStats.mean + ( mStandardDeviations * myGrayBandStats.stdDev ) );
}
else if ( QgsContrastEnhancement::NoEnhancement != contrastEnhancementAlgorithm() && !mUserDefinedGrayMinimumMaximum )
{
mGrayMinimumMaximumEstimated = true;
setMaximumValue( grayBand, mDataProvider->maximumValue( grayBand ) );
setMinimumValue( grayBand, mDataProvider->minimumValue( grayBand ) );
ce->setMinimumValue( mDataProvider->minimumValue( grayBand ) );
ce->setMaximumValue( mDataProvider->maximumValue( grayBand ) );
}
(( QgsSingleBandGrayRenderer* )renderer )->setContrastEnhancement( contrastEnhancement( grayBand ) );
(( QgsSingleBandGrayRenderer* )renderer )->setContrastEnhancement( ce );
break;
}
case SingleBandPseudoColor:
@@ -79,8 +79,8 @@ QgsRasterRenderer* QgsSingleBandGrayRendererWidget::renderer()

QgsContrastEnhancement* e = new QgsContrastEnhancement(( QgsContrastEnhancement::QgsRasterDataType )(
provider->dataType( band ) ) );
e->setMinimumValue( mMinLineEdit->text().toInt() );
e->setMaximumValue( mMaxLineEdit->text().toInt() );
e->setMinimumValue( mMinLineEdit->text().toDouble() );
e->setMaximumValue( mMaxLineEdit->text().toDouble() );
e->setContrastEnhancementAlgorithm(( QgsContrastEnhancement::ContrastEnhancementAlgorithm )( mContrastEnhancementComboBox->itemData(
mContrastEnhancementComboBox->currentIndex() ).toInt() ) );

@@ -89,3 +89,45 @@ QgsRasterRenderer* QgsSingleBandGrayRendererWidget::renderer()
renderer->setContrastEnhancement( e );
return renderer;
}

void QgsSingleBandGrayRendererWidget::on_mLoadPushButton_clicked()
{
if ( !mRasterLayer )
{
return;
}
QgsRasterDataProvider* provider = mRasterLayer->dataProvider();
if ( !provider )
{
return;
}

int band = mGrayBandComboBox->itemData( mGrayBandComboBox->currentIndex() ).toInt();
double minVal = 0;
double maxVal = 0;
if ( mEstimateRadioButton->isChecked() )
{
minVal = provider->minimumValue( band );
maxVal = provider->maximumValue( band );
}
else if ( mActualRadioButton->isChecked() )
{
QgsRasterBandStats rasterBandStats = mRasterLayer->bandStatistics( band );
minVal = rasterBandStats.minimumValue;
maxVal = rasterBandStats.maximumValue;
}
else if ( mCurrentExtentRadioButton->isChecked() )
{
double minMax[2];
mRasterLayer->computeMinimumMaximumFromLastExtent( band, minMax );
minVal = minMax[0];
maxVal = minMax[1];
}
else
{
return;
}

mMinLineEdit->setText( QString::number( minVal ) );
mMaxLineEdit->setText( QString::number( maxVal ) );
}
@@ -31,6 +31,9 @@ class QgsSingleBandGrayRendererWidget: public QgsRasterRendererWidget, private U
static QgsRasterRendererWidget* create( QgsRasterLayer* layer ) { return new QgsSingleBandGrayRendererWidget( layer ); }

QgsRasterRenderer* renderer();

private slots:
void on_mLoadPushButton_clicked();
};

#endif // QGSSINGLEBANDGRAYRENDERERWIDGET_H
@@ -73,6 +73,9 @@
<property name="text">
<string>Estimate (faster)</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="1" colspan="2">

0 comments on commit 267c1e2

Please sign in to comment.