@@ -347,7 +347,7 @@ void QgsSingleBandPseudoColorRendererWidget::on_mClassifyButton_clicked()
347
347
348
348
// int bandNr = mBandComboBox->itemData( bandComboIndex ).toInt();
349
349
// QgsRasterBandStats myRasterBandStats = mRasterLayer->dataProvider()->bandStatistics( bandNr );
350
- int numberOfEntries = 0 ;
350
+ int numberOfEntries;
351
351
352
352
bool discrete = mColorInterpolationComboBox ->currentText () == tr ( " Discrete" );
353
353
@@ -408,6 +408,7 @@ void QgsSingleBandPseudoColorRendererWidget::on_mClassifyButton_clicked()
408
408
else // for other classification modes interpolate colors linearly
409
409
{
410
410
numberOfEntries = mNumberOfEntriesSpinBox ->value ();
411
+ if ( numberOfEntries < 2 ) return ; // < 2 classes is not useful, shouldn't happen, but if it happens save it from crashing
411
412
412
413
if ( mClassificationModeComboBox ->itemData ( mClassificationModeComboBox ->currentIndex () ).toInt () == Quantile )
413
414
{ // Quantile
@@ -423,74 +424,51 @@ void QgsSingleBandPseudoColorRendererWidget::on_mClassifyButton_clicked()
423
424
// set min and max from histogram, used later to calculate number of decimals to display
424
425
mRasterLayer ->dataProvider ()->cumulativeCut ( bandNr, 0.0 , 1.0 , min, max, extent, sampleSize );
425
426
426
- double intervalDiff ;
427
- if ( numberOfEntries > 1 )
427
+ entryValues. reserve ( numberOfEntries ) ;
428
+ if ( discrete )
428
429
{
429
- entryValues. reserve ( numberOfEntries );
430
- if ( discrete )
430
+ double intervalDiff = 1.0 / ( numberOfEntries );
431
+ for ( int i = 1 ; i < numberOfEntries; ++i )
431
432
{
432
- intervalDiff = 1.0 / ( numberOfEntries );
433
- for ( int i = 1 ; i < numberOfEntries; ++i )
434
- {
435
- mRasterLayer ->dataProvider ()->cumulativeCut ( bandNr, 0.0 , i * intervalDiff, cut1, cut2, extent, sampleSize );
436
- entryValues.push_back ( cut2 );
437
- }
438
- entryValues.push_back ( std::numeric_limits<double >::infinity () );
439
- }
440
- else
441
- {
442
- intervalDiff = 1.0 / ( numberOfEntries - 1 );
443
- for ( int i = 0 ; i < numberOfEntries; ++i )
444
- {
445
- mRasterLayer ->dataProvider ()->cumulativeCut ( bandNr, 0.0 , i * intervalDiff, cut1, cut2, extent, sampleSize );
446
- entryValues.push_back ( cut2 );
447
- }
433
+ mRasterLayer ->dataProvider ()->cumulativeCut ( bandNr, 0.0 , i * intervalDiff, cut1, cut2, extent, sampleSize );
434
+ entryValues.push_back ( cut2 );
448
435
}
436
+ entryValues.push_back ( std::numeric_limits<double >::infinity () );
449
437
}
450
- else if ( numberOfEntries == 1 )
438
+ else
451
439
{
452
- mRasterLayer ->dataProvider ()->cumulativeCut ( bandNr, 0.0 , 0.5 , cut1, cut2, extent, sampleSize );
453
- entryValues.push_back ( cut2 );
440
+ double intervalDiff = 1.0 / ( numberOfEntries - 1 );
441
+ for ( int i = 0 ; i < numberOfEntries; ++i )
442
+ {
443
+ mRasterLayer ->dataProvider ()->cumulativeCut ( bandNr, 0.0 , i * intervalDiff, cut1, cut2, extent, sampleSize );
444
+ entryValues.push_back ( cut2 );
445
+ }
454
446
}
455
447
}
456
448
else // EqualInterval
457
449
{
458
- if ( numberOfEntries > 1 )
450
+ entryValues.reserve ( numberOfEntries );
451
+ if ( discrete )
459
452
{
460
- entryValues.reserve ( numberOfEntries );
461
- if ( discrete )
462
- {
463
- // in discrete mode the lowest value is not an entry and the highest
464
- // value is inf, there are ( numberOfEntries ) of which the first
465
- // and last are not used.
466
- double intervalDiff = ( max - min ) / ( numberOfEntries );
453
+ // in discrete mode the lowest value is not an entry and the highest
454
+ // value is inf, there are ( numberOfEntries ) of which the first
455
+ // and last are not used.
456
+ double intervalDiff = ( max - min ) / ( numberOfEntries );
467
457
468
- for ( int i = 1 ; i < numberOfEntries; ++i )
469
- {
470
- entryValues.push_back ( min + i * intervalDiff );
471
- }
472
- entryValues.push_back ( std::numeric_limits<double >::infinity () );
473
- }
474
- else
458
+ for ( int i = 1 ; i < numberOfEntries; ++i )
475
459
{
476
- // because the highest value is also an entry, there are (numberOfEntries - 1) intervals
477
- double intervalDiff = ( max - min ) / ( numberOfEntries - 1 );
478
-
479
- for ( int i = 0 ; i < numberOfEntries; ++i )
480
- {
481
- entryValues.push_back ( min + i * intervalDiff );
482
- }
460
+ entryValues.push_back ( min + i * intervalDiff );
483
461
}
462
+ entryValues.push_back ( std::numeric_limits<double >::infinity () );
484
463
}
485
- else if ( numberOfEntries == 1 )
464
+ else
486
465
{
487
- if ( discrete )
488
- {
489
- entryValues.push_back ( std::numeric_limits<double >::infinity () );
490
- }
491
- else
466
+ // because the highest value is also an entry, there are (numberOfEntries - 1) intervals
467
+ double intervalDiff = ( max - min ) / ( numberOfEntries - 1 );
468
+
469
+ for ( int i = 0 ; i < numberOfEntries; ++i )
492
470
{
493
- entryValues.push_back (( max + min ) / 2 );
471
+ entryValues.push_back ( min + i * intervalDiff );
494
472
}
495
473
}
496
474
}
0 commit comments