Skip to content

Commit

Permalink
LegendData analyzer: Avoid empty ranges in the class bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
dirkvdb committed Sep 4, 2024
1 parent 216708b commit 3794d14
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
13 changes: 7 additions & 6 deletions include/infra/legenddataanalyser.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<float> _sampleData; // must be sorted small to large
std::vector<int> _freqNr; // # of occurrences of the values
int _nClasses;
std::vector<float> _sampleData; // must be sorted small to large
std::vector<int> _freqNr; // # of occurrences of the values
std::vector<double> _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<double> calculate_classbounds(LegendScaleType scaleType, int numClasses, double minValue, double maxValue);
Expand Down
12 changes: 11 additions & 1 deletion legenddataanalyser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(_classBounds.size()) - 1;
}

void LegendDataAnalyser::calculate_classbounds(LegendScaleType scaleType, double minValue, double maxValue)
{
try {
Expand All @@ -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<int>(_classBounds.size() - 1);
cleanup_classbounds();
} catch (const std::exception&) {
_classBounds.clear();
}
Expand Down

0 comments on commit 3794d14

Please sign in to comment.