Add Quantile based color map creation mode

This commit is contained in:
Piers Titus van der Torren 2016-04-06 15:28:12 +02:00 committed by Nyall Dawson
parent 61a4c48b82
commit 47676d4bc5
4 changed files with 41 additions and 7 deletions

View File

@ -65,10 +65,9 @@ void QgsRasterMinMaxWidget::on_mLoadPushButton_clicked()
double myMin = std::numeric_limits<double>::quiet_NaN();
double myMax = std::numeric_limits<double>::quiet_NaN();
QgsRectangle myExtent; // empty == full
QgsRectangle myExtent = extent(); // empty == full
if ( mCurrentExtentRadioButton->isChecked() )
{
myExtent = mExtent; // current
origin |= QgsRasterRenderer::MinMaxSubExtent;
}
else
@ -77,10 +76,9 @@ void QgsRasterMinMaxWidget::on_mLoadPushButton_clicked()
}
QgsDebugMsg( QString( "myExtent.isEmpty() = %1" ).arg( myExtent.isEmpty() ) );
int mySampleSize = 0; // 0 == exact
int mySampleSize = sampleSize(); // 0 == exact
if ( mEstimateRadioButton->isChecked() )
{
mySampleSize = 250000;
origin |= QgsRasterRenderer::MinMaxEstimated;
}
else

View File

@ -33,6 +33,9 @@ class GUI_EXPORT QgsRasterMinMaxWidget: public QWidget, private Ui::QgsRasterMin
void setBands( const QList<int> & theBands ) { mBands = theBands; }
QgsRectangle extent() { QgsRectangle myExtent; return mCurrentExtentRadioButton->isChecked() ? mExtent : myExtent; }
int sampleSize() { return mEstimateRadioButton->isChecked() ? 250000 : 0; }
// Load programmaticaly with current values
void load() { on_mLoadPushButton_clicked(); }

View File

@ -103,7 +103,7 @@ QgsSingleBandPseudoColorRendererWidget::QgsSingleBandPseudoColorRendererWidget(
mColorInterpolationComboBox->setCurrentIndex( 1 );
mClassificationModeComboBox->addItem( tr( "Continuous" ), Continuous );
mClassificationModeComboBox->addItem( tr( "Equal interval" ), EqualInterval );
//quantile would be nice as well
mClassificationModeComboBox->addItem( tr( "Quantile" ), Quantile );
mNumberOfEntriesSpinBox->setValue( 5 ); // some default
@ -343,6 +343,38 @@ void QgsSingleBandPseudoColorRendererWidget::on_mClassifyButton_clicked()
}
}
}
else if ( mClassificationModeComboBox->itemData( mClassificationModeComboBox->currentIndex() ).toInt() == Quantile )
{ // Quantile
mMinMaxWidget->load();
numberOfEntries = mNumberOfEntriesSpinBox->value();
int bandNr = mBandComboBox->itemData( bandComboIndex ).toInt();
//QgsRasterHistogram myRasterHistogram = mRasterLayer->dataProvider()->histogram( bandNr );
double myMin = std::numeric_limits<double>::quiet_NaN();
double myMax = std::numeric_limits<double>::quiet_NaN();
QgsRectangle myExtent = mMinMaxWidget->extent();
int mySampleSize = mMinMaxWidget->sampleSize();
double intervalDiff;
if ( numberOfEntries > 1 )
{
intervalDiff = 1.0 / ( numberOfEntries - 1 );
entryValues.reserve( numberOfEntries );
for ( int i = 0; i < numberOfEntries; ++i )
{
mRasterLayer->dataProvider()->cumulativeCut( bandNr, 0.0, i * intervalDiff, myMin, myMax, myExtent, mySampleSize );
entryValues.push_back( myMax );
}
}
else if ( numberOfEntries == 1 )
{
mRasterLayer->dataProvider()->cumulativeCut( bandNr, 0.0, 0.5, myMin, myMax, myExtent, mySampleSize );
entryValues.push_back( myMax );
}
}
else // EqualInterval
{
numberOfEntries = mNumberOfEntriesSpinBox->value();
@ -438,7 +470,7 @@ void QgsSingleBandPseudoColorRendererWidget::on_mClassifyButton_clicked()
void QgsSingleBandPseudoColorRendererWidget::on_mClassificationModeComboBox_currentIndexChanged( int index )
{
mNumberOfEntriesSpinBox->setEnabled( mClassificationModeComboBox->itemData( index ).toInt() == EqualInterval );
mNumberOfEntriesSpinBox->setEnabled( mClassificationModeComboBox->itemData( index ).toInt() != Continuous );
}
void QgsSingleBandPseudoColorRendererWidget::on_mColorRampComboBox_currentIndexChanged( int index )

View File

@ -31,7 +31,8 @@ class GUI_EXPORT QgsSingleBandPseudoColorRendererWidget: public QgsRasterRendere
enum Mode
{
Continuous = 1, // Using breaks from color palette
EqualInterval = 2
EqualInterval = 2,
Quantile = 3
};
QgsSingleBandPseudoColorRendererWidget( QgsRasterLayer* layer, const QgsRectangle &extent = QgsRectangle() );