diff --git a/include/infra/legenddataanalyser.h b/include/infra/legenddataanalyser.h index 592eae31..934148fd 100644 --- a/include/infra/legenddataanalyser.h +++ b/include/infra/legenddataanalyser.h @@ -24,17 +24,18 @@ class LegendDataAnalyser float effectiveness() const; // returns an estimate for the effectiveness of the class bounds private: + void cleanup_classbounds(); double convert_value(LegendScaleType scaleType, const double& value, const double& minValue) const; - std::vector _sampleData; // must be sorted small to large - std::vector _freqNr; // # of occurrences of the values - int _nClasses; + std::vector _sampleData; // must be sorted small to large + std::vector _freqNr; // # of occurrences of the values std::vector _classBounds; // size: _nClasses + 1 + int _nClasses = 0; // statistics - double _msw; // mean of squared deviations within classes - double _msb; // mean of squared deviations between classes - double _varByClass; // proportion of variance accounted for by classification + double _msw = 0.0; // mean of squared deviations within classes + double _msb = 0.0; // mean of squared deviations between classes + double _varByClass = 0.0; // proportion of variance accounted for by classification }; std::vector calculate_classbounds(LegendScaleType scaleType, int numClasses, double minValue, double maxValue); diff --git a/legenddataanalyser.cpp b/legenddataanalyser.cpp index f964e827..2a080fdf 100644 --- a/legenddataanalyser.cpp +++ b/legenddataanalyser.cpp @@ -24,6 +24,16 @@ void LegendDataAnalyser::set_number_of_classes(int n) _nClasses = std::max(0, n); } +void LegendDataAnalyser::cleanup_classbounds() +{ + _classBounds.erase(std::unique(_classBounds.begin(), _classBounds.end()), _classBounds.end()); + if (_classBounds.size() == 1) { + _classBounds.push_back(_classBounds[0]); + } + + _nClasses = truncate(_classBounds.size()) - 1; +} + void LegendDataAnalyser::calculate_classbounds(LegendScaleType scaleType, double minValue, double maxValue) { try { @@ -32,7 +42,7 @@ void LegendDataAnalyser::calculate_classbounds(LegendScaleType scaleType, double maxValue = _sampleData[_sampleData.size() - 1]; } _classBounds = inf::calculate_classbounds(scaleType, _nClasses, minValue, maxValue, _sampleData); - _nClasses = truncate(_classBounds.size() - 1); + cleanup_classbounds(); } catch (const std::exception&) { _classBounds.clear(); }