Skip to content

Commit

Permalink
Add Quantile based color map creation mode
Browse files Browse the repository at this point in the history
  • Loading branch information
pierstitus authored and nyalldawson committed Jun 2, 2016
1 parent 61a4c48 commit 47676d4
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 7 deletions.
6 changes: 2 additions & 4 deletions src/gui/raster/qgsrasterminmaxwidget.cpp
Expand Up @@ -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
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/gui/raster/qgsrasterminmaxwidget.h
Expand Up @@ -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(); }

Expand Down
36 changes: 34 additions & 2 deletions src/gui/raster/qgssinglebandpseudocolorrendererwidget.cpp
Expand Up @@ -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

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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 )
Expand Down
3 changes: 2 additions & 1 deletion src/gui/raster/qgssinglebandpseudocolorrendererwidget.h
Expand Up @@ -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() );
Expand Down

0 comments on commit 47676d4

Please sign in to comment.