26 #ifndef __TERRALIB_MAPTOOLS_INTERNAL_GROUPINGALGORITHMS_H 27 #define __TERRALIB_MAPTOOLS_INTERNAL_GROUPINGALGORITHMS_H 31 #include "../core/translator/Translator.h" 32 #include "../common/StringUtils.h" 33 #include "../fe/Utils.h" 34 #include "../se/Description.h" 35 #include "../se/Rule.h" 46 #define MIN(a,b) ( (a<b) ? a : b ) 50 #define MAX(a,b) ( (a>b) ? a : b ) 70 std::vector<te::se::Rule*>& rules,
int precision);
95 template<
class iterator>
96 void GroupingByEqualSteps(std::string attrName, iterator begin, iterator end,
int nSteps, std::vector<te::se::Rule*>& rules,
99 double min = std::numeric_limits<double>::max();
100 double max = -std::numeric_limits<double>::max();
111 double slice = (max - min)/
double(nSteps);
113 for(
int i = 0; i < nSteps; ++i)
118 min = min + double(i) * slice;
123 max = min + double(i + 1) * slice;
127 std::string* ruleNamePtr =
new std::string(ruleName);
128 ruleItem->
setName(ruleNamePtr);
131 rules.push_back(ruleItem);
147 template<
class iterator>
148 void GroupingByQuantil(std::string attrName, iterator begin, iterator end,
int nSteps, std::vector<te::se::Rule*>& rules,
153 int size =
static_cast<int>(end - begin);
154 double steps = (double)size / (
double)nSteps;
156 std::vector< std::pair<std::string, std::string> > pairMinMax;
163 std::string maxValue =
"";
165 int p = (
int)(steps * (
double)++n + .5);
173 std::pair<std::string, std::string> pair(minValue, maxValue);
175 pairMinMax.push_back(pair);
180 double min = (*begin);
181 double max = (*(end-1));
190 for (std::size_t t = 0; t < pairMinMax.size(); ++t)
193 std::string ruleName =
"[" + pairMinMax[t].first +
", " + pairMinMax[t].second +
"[";
194 std::string* ruleNamePtr =
new std::string(ruleName);
195 ruleItem->
setName(ruleNamePtr);
198 rules.push_back(ruleItem);
215 template<
class iterator>
216 void GroupingByStdDeviation(std::string attrName, iterator begin, iterator end,
double nDevs, std::vector<te::se::Rule*>& rules,
217 std::string& meanTitle,
int precision = 0)
220 double min = std::numeric_limits<double>::max();
221 double max = -std::numeric_limits<double>::max();
222 long double sum = 0.;
223 long double sm2 = 0.;
231 sm2 += ((*it) * (*it));
235 double count = (double)(end - begin);
236 double mean = (double)(sum / count);
237 long double var = (sm2 / count) - (mean * mean);
238 double stdDev = sqrt(var);
240 double slice = stdDev * nDevs;
242 std::vector<te::se::Rule*> aux;
247 while (val - slice > min - slice)
251 double v = val - slice;
253 std::string* ruleNamePtr =
new std::string(ruleName);
254 ruleItem->
setName(ruleNamePtr);
257 aux.push_back(ruleItem);
262 std::vector<te::se::Rule*>::reverse_iterator sit;
263 for (sit = aux.rbegin(); sit != aux.rend(); ++sit)
264 rules.push_back(*sit);
266 meanTitle =
TE_TR(
"Mean - ") + strMean;
269 std::string* ruleNamePtr =
new std::string(meanTitle);
270 ruleItemMean->
setName(ruleNamePtr);
272 rules.push_back(ruleItemMean);
275 while (val + slice < max + slice)
279 double v = val + slice;
281 std::string* ruleNamePtr =
new std::string(ruleName);
282 ruleItem->
setName(ruleNamePtr);
285 aux.push_back(ruleItem);
293 #endif //__TERRALIB_MAPTOOLS_INTERNAL_GROUPINGALGORITHMS_H TEMAPEXPORT void GroupingByUniqueValues(std::string attrName, std::vector< std::string > &inputValues, int dataType, std::vector< te::se::Rule * > &rules, int precision)
It groups the values using the unique value algorithm.
void setName(std::string *name)
TEMAPEXPORT double AdjustToPrecision(double val, int precision, bool reduce=false)
It adjusts a value to the precision specified.
#define MIN(a, b)
Macro that returns min between two values.
void GroupingByQuantil(std::string attrName, iterator begin, iterator end, int nSteps, std::vector< te::se::Rule * > &rules, int precision=0)
It groups the values defined by a range of iterators using the quantil algorithm. ...
void GroupingByEqualSteps(std::string attrName, iterator begin, iterator end, int nSteps, std::vector< te::se::Rule * > &rules, int precision=0)
It groups the values defined by a range of iterators using the equal steps algorithm.
void setFilter(te::fe::Filter *f)
#define TE_TR(message)
It marks a string in order to get translated.
#define MAX(a, b)
Macro that returns max between two values.
TEFEEXPORT te::fe::Filter * CreateFilterByStep(const std::string &attrName, const std::string &minValue, const std::string &maxValue)
A Rule is used to attach property/scale conditions to and group the individual symbols used for rende...
std::string Convert2String(boost::int16_t value)
It converts a short integer value to a string.
void GroupingByStdDeviation(std::string attrName, iterator begin, iterator end, double nDevs, std::vector< te::se::Rule * > &rules, std::string &meanTitle, int precision=0)
It groups the values defined by a range of iterators using the standard deviation algorithm...