@@ -383,123 +383,129 @@ void QgsSingleBandPseudoColorRendererWidget::on_mClassifyButton_clicked()
383
383
entryValues.push_back ( min + value * ( max - min ) );
384
384
}
385
385
}
386
+ // for continuous mode take original color map colors
387
+ for ( int i = 0 ; i < numberOfEntries; ++i )
388
+ {
389
+ entryColors.push_back ( colorRamp->color ( colorRamp->value ( i ) ) );
390
+ }
386
391
}
387
392
}
388
- else if ( mClassificationModeComboBox -> itemData ( mClassificationModeComboBox -> currentIndex () ). toInt () == Quantile )
389
- { // Quantile
393
+ else // for other classification modes interpolate colors linearly
394
+ {
390
395
numberOfEntries = mNumberOfEntriesSpinBox ->value ();
391
396
392
- int bandNr = mBandComboBox ->itemData ( bandComboIndex ).toInt ();
393
- // QgsRasterHistogram rasterHistogram = mRasterLayer->dataProvider()->histogram( bandNr );
397
+ if ( mClassificationModeComboBox ->itemData ( mClassificationModeComboBox ->currentIndex () ).toInt () == Quantile )
398
+ { // Quantile
399
+ int bandNr = mBandComboBox ->itemData ( bandComboIndex ).toInt ();
400
+ // QgsRasterHistogram rasterHistogram = mRasterLayer->dataProvider()->histogram( bandNr );
394
401
395
- double cut1 = std::numeric_limits<double >::quiet_NaN ();
396
- double cut2 = std::numeric_limits<double >::quiet_NaN ();
402
+ double cut1 = std::numeric_limits<double >::quiet_NaN ();
403
+ double cut2 = std::numeric_limits<double >::quiet_NaN ();
397
404
398
- QgsRectangle extent = mMinMaxWidget ->extent ();
399
- int sampleSize = mMinMaxWidget ->sampleSize ();
405
+ QgsRectangle extent = mMinMaxWidget ->extent ();
406
+ int sampleSize = mMinMaxWidget ->sampleSize ();
400
407
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 );
408
+ // set min and max from histogram, used later to calculate number of decimals to display
409
+ mRasterLayer ->dataProvider ()->cumulativeCut ( bandNr, 0.0 , 1.0 , min, max, extent, sampleSize );
403
410
404
- double intervalDiff;
405
- if ( numberOfEntries > 1 )
406
- {
407
- entryValues.reserve ( numberOfEntries );
408
- if ( discrete )
411
+ double intervalDiff;
412
+ if ( numberOfEntries > 1 )
409
413
{
410
- intervalDiff = 1.0 / ( numberOfEntries );
411
- for ( int i = 1 ; i < numberOfEntries; ++i )
414
+ entryValues. reserve ( numberOfEntries );
415
+ if ( discrete )
412
416
{
413
- mRasterLayer ->dataProvider ()->cumulativeCut ( bandNr, 0.0 , i * intervalDiff, cut1, cut2, extent, sampleSize );
414
- entryValues.push_back ( cut2 );
417
+ intervalDiff = 1.0 / ( numberOfEntries );
418
+ for ( int i = 1 ; i < numberOfEntries; ++i )
419
+ {
420
+ mRasterLayer ->dataProvider ()->cumulativeCut ( bandNr, 0.0 , i * intervalDiff, cut1, cut2, extent, sampleSize );
421
+ entryValues.push_back ( cut2 );
422
+ }
423
+ entryValues.push_back ( std::numeric_limits<double >::infinity () );
415
424
}
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 )
425
+ else
422
426
{
423
- mRasterLayer ->dataProvider ()->cumulativeCut ( bandNr, 0.0 , i * intervalDiff, cut1, cut2, extent, sampleSize );
424
- entryValues.push_back ( cut2 );
427
+ intervalDiff = 1.0 / ( numberOfEntries - 1 );
428
+ for ( int i = 0 ; i < numberOfEntries; ++i )
429
+ {
430
+ mRasterLayer ->dataProvider ()->cumulativeCut ( bandNr, 0.0 , i * intervalDiff, cut1, cut2, extent, sampleSize );
431
+ entryValues.push_back ( cut2 );
432
+ }
425
433
}
426
434
}
435
+ else if ( numberOfEntries == 1 )
436
+ {
437
+ mRasterLayer ->dataProvider ()->cumulativeCut ( bandNr, 0.0 , 0.5 , cut1, cut2, extent, sampleSize );
438
+ entryValues.push_back ( cut2 );
439
+ }
427
440
}
428
- else if ( numberOfEntries == 1 )
441
+ else // EqualInterval
429
442
{
430
- mRasterLayer ->dataProvider ()->cumulativeCut ( bandNr, 0.0 , 0.5 , cut1, cut2, extent, sampleSize );
431
- entryValues.push_back ( cut2 );
432
- }
433
- }
434
- else // EqualInterval
435
- {
436
- numberOfEntries = mNumberOfEntriesSpinBox ->value ();
437
-
438
- if ( numberOfEntries > 1 )
439
- {
440
- entryValues.reserve ( numberOfEntries );
441
- if ( discrete )
443
+ if ( numberOfEntries > 1 )
442
444
{
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 );
445
+ entryValues.reserve ( numberOfEntries );
446
+ if ( discrete )
447
+ {
448
+ // in discrete mode the lowest value is not an entry and the highest
449
+ // value is inf, there are ( numberOfEntries ) of which the first
450
+ // and last are not used.
451
+ double intervalDiff = ( max - min ) / ( numberOfEntries );
447
452
448
- for ( int i = 1 ; i < numberOfEntries; ++i )
453
+ for ( int i = 1 ; i < numberOfEntries; ++i )
454
+ {
455
+ entryValues.push_back ( min + i * intervalDiff );
456
+ }
457
+ entryValues.push_back ( std::numeric_limits<double >::infinity () );
458
+ }
459
+ else
449
460
{
450
- entryValues.push_back ( min + i * intervalDiff );
461
+ // because the highest value is also an entry, there are (numberOfEntries - 1) intervals
462
+ double intervalDiff = ( max - min ) / ( numberOfEntries - 1 );
463
+
464
+ for ( int i = 0 ; i < numberOfEntries; ++i )
465
+ {
466
+ entryValues.push_back ( min + i * intervalDiff );
467
+ }
451
468
}
452
- entryValues.push_back ( std::numeric_limits<double >::infinity () );
453
469
}
454
- else
470
+ else if ( numberOfEntries == 1 )
455
471
{
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 )
472
+ if ( discrete )
473
+ {
474
+ entryValues.push_back ( std::numeric_limits<double >::infinity () );
475
+ }
476
+ else
460
477
{
461
- entryValues.push_back ( min + i * intervalDiff );
478
+ entryValues.push_back (( max + min ) / 2 );
462
479
}
463
480
}
464
481
}
465
- else if ( numberOfEntries == 1 )
482
+
483
+ if ( ! colorRamp )
466
484
{
467
- if ( discrete )
485
+ // hard code color range from blue -> red (previous default)
486
+ int colorDiff = 0 ;
487
+ if ( numberOfEntries != 0 )
468
488
{
469
- entryValues. push_back ( std::numeric_limits< double >:: infinity () );
489
+ colorDiff = ( int )( 255 / numberOfEntries );
470
490
}
471
- else
491
+
492
+ entryColors.reserve ( numberOfEntries );
493
+ for ( int i = 0 ; i < numberOfEntries; ++i )
472
494
{
473
- entryValues.push_back (( max + min ) / 2 );
495
+ QColor currentColor;
496
+ int idx = mInvertCheckBox ->isChecked () ? numberOfEntries - i - 1 : i;
497
+ currentColor.setRgb ( colorDiff*idx, 0 , 255 - colorDiff * idx );
498
+ entryColors.push_back ( currentColor );
474
499
}
475
500
}
476
- }
477
-
478
- if ( ! colorRamp )
479
- {
480
- // hard code color range from blue -> red (previous default)
481
- int colorDiff = 0 ;
482
- if ( numberOfEntries != 0 )
483
- {
484
- colorDiff = ( int )( 255 / numberOfEntries );
485
- }
486
-
487
- entryColors.reserve ( numberOfEntries );
488
- for ( int i = 0 ; i < numberOfEntries; ++i )
489
- {
490
- QColor currentColor;
491
- int idx = mInvertCheckBox ->isChecked () ? numberOfEntries - i - 1 : i;
492
- currentColor.setRgb ( colorDiff*idx, 0 , 255 - colorDiff * idx );
493
- entryColors.push_back ( currentColor );
494
- }
495
- }
496
- else
497
- {
498
- entryColors.reserve ( numberOfEntries );
499
- for ( int i = 0 ; i < numberOfEntries; ++i )
501
+ else
500
502
{
501
- int idx = mInvertCheckBox ->isChecked () ? numberOfEntries - i - 1 : i;
502
- entryColors.push_back ( colorRamp->color ((( double ) idx ) / ( numberOfEntries - 1 ) ) );
503
+ entryColors.reserve ( numberOfEntries );
504
+ for ( int i = 0 ; i < numberOfEntries; ++i )
505
+ {
506
+ int idx = mInvertCheckBox ->isChecked () ? numberOfEntries - i - 1 : i;
507
+ entryColors.push_back ( colorRamp->color ((( double ) idx ) / ( numberOfEntries - 1 ) ) );
508
+ }
503
509
}
504
510
}
505
511
0 commit comments