Skip to content

Commit 47676d4

Browse files
pierstitusnyalldawson
authored andcommitted
Add Quantile based color map creation mode
1 parent 61a4c48 commit 47676d4

File tree

4 files changed

+41
-7
lines changed

4 files changed

+41
-7
lines changed

src/gui/raster/qgsrasterminmaxwidget.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,9 @@ void QgsRasterMinMaxWidget::on_mLoadPushButton_clicked()
6565
double myMin = std::numeric_limits<double>::quiet_NaN();
6666
double myMax = std::numeric_limits<double>::quiet_NaN();
6767

68-
QgsRectangle myExtent; // empty == full
68+
QgsRectangle myExtent = extent(); // empty == full
6969
if ( mCurrentExtentRadioButton->isChecked() )
7070
{
71-
myExtent = mExtent; // current
7271
origin |= QgsRasterRenderer::MinMaxSubExtent;
7372
}
7473
else
@@ -77,10 +76,9 @@ void QgsRasterMinMaxWidget::on_mLoadPushButton_clicked()
7776
}
7877
QgsDebugMsg( QString( "myExtent.isEmpty() = %1" ).arg( myExtent.isEmpty() ) );
7978

80-
int mySampleSize = 0; // 0 == exact
79+
int mySampleSize = sampleSize(); // 0 == exact
8180
if ( mEstimateRadioButton->isChecked() )
8281
{
83-
mySampleSize = 250000;
8482
origin |= QgsRasterRenderer::MinMaxEstimated;
8583
}
8684
else

src/gui/raster/qgsrasterminmaxwidget.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ class GUI_EXPORT QgsRasterMinMaxWidget: public QWidget, private Ui::QgsRasterMin
3333

3434
void setBands( const QList<int> & theBands ) { mBands = theBands; }
3535

36+
QgsRectangle extent() { QgsRectangle myExtent; return mCurrentExtentRadioButton->isChecked() ? mExtent : myExtent; }
37+
int sampleSize() { return mEstimateRadioButton->isChecked() ? 250000 : 0; }
38+
3639
// Load programmaticaly with current values
3740
void load() { on_mLoadPushButton_clicked(); }
3841

src/gui/raster/qgssinglebandpseudocolorrendererwidget.cpp

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ QgsSingleBandPseudoColorRendererWidget::QgsSingleBandPseudoColorRendererWidget(
103103
mColorInterpolationComboBox->setCurrentIndex( 1 );
104104
mClassificationModeComboBox->addItem( tr( "Continuous" ), Continuous );
105105
mClassificationModeComboBox->addItem( tr( "Equal interval" ), EqualInterval );
106-
//quantile would be nice as well
106+
mClassificationModeComboBox->addItem( tr( "Quantile" ), Quantile );
107107

108108
mNumberOfEntriesSpinBox->setValue( 5 ); // some default
109109

@@ -343,6 +343,38 @@ void QgsSingleBandPseudoColorRendererWidget::on_mClassifyButton_clicked()
343343
}
344344
}
345345
}
346+
else if ( mClassificationModeComboBox->itemData( mClassificationModeComboBox->currentIndex() ).toInt() == Quantile )
347+
{ // Quantile
348+
mMinMaxWidget->load();
349+
350+
numberOfEntries = mNumberOfEntriesSpinBox->value();
351+
352+
int bandNr = mBandComboBox->itemData( bandComboIndex ).toInt();
353+
//QgsRasterHistogram myRasterHistogram = mRasterLayer->dataProvider()->histogram( bandNr );
354+
355+
double myMin = std::numeric_limits<double>::quiet_NaN();
356+
double myMax = std::numeric_limits<double>::quiet_NaN();
357+
358+
QgsRectangle myExtent = mMinMaxWidget->extent();
359+
int mySampleSize = mMinMaxWidget->sampleSize();
360+
361+
double intervalDiff;
362+
if ( numberOfEntries > 1 )
363+
{
364+
intervalDiff = 1.0 / ( numberOfEntries - 1 );
365+
entryValues.reserve( numberOfEntries );
366+
for ( int i = 0; i < numberOfEntries; ++i )
367+
{
368+
mRasterLayer->dataProvider()->cumulativeCut( bandNr, 0.0, i * intervalDiff, myMin, myMax, myExtent, mySampleSize );
369+
entryValues.push_back( myMax );
370+
}
371+
}
372+
else if ( numberOfEntries == 1 )
373+
{
374+
mRasterLayer->dataProvider()->cumulativeCut( bandNr, 0.0, 0.5, myMin, myMax, myExtent, mySampleSize );
375+
entryValues.push_back( myMax );
376+
}
377+
}
346378
else // EqualInterval
347379
{
348380
numberOfEntries = mNumberOfEntriesSpinBox->value();
@@ -438,7 +470,7 @@ void QgsSingleBandPseudoColorRendererWidget::on_mClassifyButton_clicked()
438470

439471
void QgsSingleBandPseudoColorRendererWidget::on_mClassificationModeComboBox_currentIndexChanged( int index )
440472
{
441-
mNumberOfEntriesSpinBox->setEnabled( mClassificationModeComboBox->itemData( index ).toInt() == EqualInterval );
473+
mNumberOfEntriesSpinBox->setEnabled( mClassificationModeComboBox->itemData( index ).toInt() != Continuous );
442474
}
443475

444476
void QgsSingleBandPseudoColorRendererWidget::on_mColorRampComboBox_currentIndexChanged( int index )

src/gui/raster/qgssinglebandpseudocolorrendererwidget.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ class GUI_EXPORT QgsSingleBandPseudoColorRendererWidget: public QgsRasterRendere
3131
enum Mode
3232
{
3333
Continuous = 1, // Using breaks from color palette
34-
EqualInterval = 2
34+
EqualInterval = 2,
35+
Quantile = 3
3536
};
3637

3738
QgsSingleBandPseudoColorRendererWidget( QgsRasterLayer* layer, const QgsRectangle &extent = QgsRectangle() );

0 commit comments

Comments
 (0)