@@ -227,6 +227,10 @@ void QgsSingleBandPseudoColorRendererWidget::autoLabel()
227
227
{
228
228
label = " <= " + currentItem->text ( ValueColumn ) + unit;
229
229
}
230
+ else if ( currentItem->text ( ValueColumn ).toDouble () == std::numeric_limits<double >::infinity () )
231
+ {
232
+ label = " > " + mColormapTreeWidget ->topLevelItem ( i - 1 )->text ( ValueColumn );
233
+ }
230
234
else
231
235
{
232
236
label = mColormapTreeWidget ->topLevelItem ( i - 1 )->text ( ValueColumn ) + " - " + currentItem->text ( ValueColumn ) + unit;
@@ -345,6 +349,8 @@ void QgsSingleBandPseudoColorRendererWidget::on_mClassifyButton_clicked()
345
349
// QgsRasterBandStats myRasterBandStats = mRasterLayer->dataProvider()->bandStatistics( bandNr );
346
350
int numberOfEntries = 0 ;
347
351
352
+ bool discrete = mColorInterpolationComboBox ->currentText () == tr ( " Discrete" );
353
+
348
354
QList<double > entryValues;
349
355
QVector<QColor> entryColors;
350
356
@@ -358,18 +364,29 @@ void QgsSingleBandPseudoColorRendererWidget::on_mClassifyButton_clicked()
358
364
if ( colorRamp )
359
365
{
360
366
numberOfEntries = colorRamp->count ();
361
- entryValues.reserve ( colorRamp-> count () );
362
- for ( int i = 0 ; i < colorRamp-> count (); ++i )
367
+ entryValues.reserve ( numberOfEntries );
368
+ if ( discrete )
363
369
{
364
- double value = colorRamp->value ( i );
365
- entryValues.push_back ( min + value * ( max - min ) );
370
+ double intervalDiff = ( max - min ) * ( numberOfEntries - 1 ) / numberOfEntries;
371
+ for ( int i = 1 ; i < numberOfEntries; ++i )
372
+ {
373
+ double value = colorRamp->value ( i );
374
+ entryValues.push_back ( min + value * intervalDiff );
375
+ }
376
+ entryValues.push_back ( std::numeric_limits<double >::infinity () );
377
+ }
378
+ else
379
+ {
380
+ for ( int i = 0 ; i < numberOfEntries; ++i )
381
+ {
382
+ double value = colorRamp->value ( i );
383
+ entryValues.push_back ( min + value * ( max - min ) );
384
+ }
366
385
}
367
386
}
368
387
}
369
388
else if ( mClassificationModeComboBox ->itemData ( mClassificationModeComboBox ->currentIndex () ).toInt () == Quantile )
370
389
{ // Quantile
371
- mMinMaxWidget ->load ();
372
-
373
390
numberOfEntries = mNumberOfEntriesSpinBox ->value ();
374
391
375
392
int bandNr = mBandComboBox ->itemData ( bandComboIndex ).toInt ();
@@ -381,15 +398,31 @@ void QgsSingleBandPseudoColorRendererWidget::on_mClassifyButton_clicked()
381
398
QgsRectangle extent = mMinMaxWidget ->extent ();
382
399
int sampleSize = mMinMaxWidget ->sampleSize ();
383
400
401
+ // set min and max from histogram, used later to calculate number of decimals to display
402
+ mRasterLayer ->dataProvider ()->cumulativeCut ( bandNr, 0.0 , 1.0 , min, max, extent, sampleSize );
403
+
384
404
double intervalDiff;
385
405
if ( numberOfEntries > 1 )
386
406
{
387
- intervalDiff = 1.0 / ( numberOfEntries - 1 );
388
407
entryValues.reserve ( numberOfEntries );
389
- for ( int i = 0 ; i < numberOfEntries; ++i )
408
+ if ( discrete )
390
409
{
391
- mRasterLayer ->dataProvider ()->cumulativeCut ( bandNr, 0.0 , i * intervalDiff, cut1, cut2, extent, sampleSize );
392
- entryValues.push_back ( cut2 );
410
+ intervalDiff = 1.0 / ( numberOfEntries );
411
+ for ( int i = 1 ; i < numberOfEntries; ++i )
412
+ {
413
+ mRasterLayer ->dataProvider ()->cumulativeCut ( bandNr, 0.0 , i * intervalDiff, cut1, cut2, extent, sampleSize );
414
+ entryValues.push_back ( cut2 );
415
+ }
416
+ entryValues.push_back ( std::numeric_limits<double >::infinity () );
417
+ }
418
+ else
419
+ {
420
+ intervalDiff = 1.0 / ( numberOfEntries - 1 );
421
+ for ( int i = 0 ; i < numberOfEntries; ++i )
422
+ {
423
+ mRasterLayer ->dataProvider ()->cumulativeCut ( bandNr, 0.0 , i * intervalDiff, cut1, cut2, extent, sampleSize );
424
+ entryValues.push_back ( cut2 );
425
+ }
393
426
}
394
427
}
395
428
else if ( numberOfEntries == 1 )
@@ -401,45 +434,47 @@ void QgsSingleBandPseudoColorRendererWidget::on_mClassifyButton_clicked()
401
434
else // EqualInterval
402
435
{
403
436
numberOfEntries = mNumberOfEntriesSpinBox ->value ();
404
- // double currentValue = myRasterBandStats.minimumValue;
405
- double currentValue = min;
406
- double intervalDiff;
437
+
407
438
if ( numberOfEntries > 1 )
408
439
{
409
- // because the highest value is also an entry, there are (numberOfEntries - 1)
410
- // intervals
411
- // intervalDiff = ( myRasterBandStats.maximumValue - myRasterBandStats.minimumValue ) /
412
- intervalDiff = ( max - min ) / ( numberOfEntries - 1 );
413
- }
414
- else
415
- {
416
- // intervalDiff = myRasterBandStats.maximumValue - myRasterBandStats.minimumValue;
417
- intervalDiff = max - min;
418
- }
440
+ entryValues.reserve ( numberOfEntries );
441
+ if ( discrete )
442
+ {
443
+ // in discrete mode the lowest value is not an entry and the highest
444
+ // value is inf, there are ( numberOfEntries ) of which the first
445
+ // and last are not used.
446
+ double intervalDiff = ( max - min ) / ( numberOfEntries );
419
447
420
- entryValues.reserve ( numberOfEntries );
421
- for ( int i = 0 ; i < numberOfEntries; ++i )
448
+ for ( int i = 1 ; i < numberOfEntries; ++i )
449
+ {
450
+ entryValues.push_back ( min + i * intervalDiff );
451
+ }
452
+ entryValues.push_back ( std::numeric_limits<double >::infinity () );
453
+ }
454
+ else
455
+ {
456
+ // because the highest value is also an entry, there are (numberOfEntries - 1) intervals
457
+ double intervalDiff = ( max - min ) / ( numberOfEntries - 1 );
458
+
459
+ for ( int i = 0 ; i < numberOfEntries; ++i )
460
+ {
461
+ entryValues.push_back ( min + i * intervalDiff );
462
+ }
463
+ }
464
+ }
465
+ else if ( numberOfEntries == 1 )
422
466
{
423
- entryValues.push_back ( currentValue );
424
- currentValue += intervalDiff;
467
+ if ( discrete )
468
+ {
469
+ entryValues.push_back ( std::numeric_limits<double >::infinity () );
470
+ }
471
+ else
472
+ {
473
+ entryValues.push_back (( max + min ) / 2 );
474
+ }
425
475
}
426
476
}
427
477
428
- #if 0
429
- //hard code color range from blue -> red for now. Allow choice of ramps in future
430
- int colorDiff = 0;
431
- if ( numberOfEntries != 0 )
432
- {
433
- colorDiff = ( int )( 255 / numberOfEntries );
434
- }
435
- for ( int i = 0; i < numberOfEntries; ++i )
436
- {
437
- QColor currentColor;
438
- currentColor.setRgb( colorDiff*i, 0, 255 - colorDiff * i );
439
- entryColors.push_back( currentColor );
440
- }
441
- #endif
442
-
443
478
if ( ! colorRamp )
444
479
{
445
480
// hard code color range from blue -> red (previous default)
@@ -494,6 +529,8 @@ void QgsSingleBandPseudoColorRendererWidget::on_mClassifyButton_clicked()
494
529
void QgsSingleBandPseudoColorRendererWidget::on_mClassificationModeComboBox_currentIndexChanged ( int index )
495
530
{
496
531
mNumberOfEntriesSpinBox ->setEnabled ( mClassificationModeComboBox ->itemData ( index ).toInt () != Continuous );
532
+ mMinLineEdit ->setEnabled ( mClassificationModeComboBox ->itemData ( index ).toInt () != Quantile );
533
+ mMaxLineEdit ->setEnabled ( mClassificationModeComboBox ->itemData ( index ).toInt () != Quantile );
497
534
}
498
535
499
536
void QgsSingleBandPseudoColorRendererWidget::on_mColorRampComboBox_currentIndexChanged ( int index )
0 commit comments