All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Utils.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18 */
19 
20 /*!
21  \file terralib\statistics\core\Utils.cpp
22 
23  \brief Utility functions for Statistics.
24 */
25 
26 // TerraLib
27 #include "../../common/Translator.h"
28 #include "../../dataaccess/dataset/DataSet.h"
29 #include "Config.h"
30 #include "Enums.h"
31 #include "Exception.h"
32 #include "Utils.h"
33 
34 //Boost
35 #include <boost/lexical_cast.hpp>
36 
37 std::string te::stat::GetStatSummaryShortName(const int& e)
38 {
39  switch(e)
40  {
42  return TE_TR("MIN_VALUE");
43 
45  return TE_TR("MAX_VALUE");
46 
47  case te::stat::MEAN:
48  return TE_TR("MEAN");
49 
50  case te::stat::SUM:
51  return TE_TR("SUM");
52 
53  case te::stat::COUNT:
54  return TE_TR("COUNT");
55 
57  return TE_TR("VALID_COUNT");
58 
60  return TE_TR("STANDARD_DEVIATION");
61 
62  case te::stat::VARIANCE:
63  return TE_TR("VARIANCE");
64 
65  case te::stat::SKEWNESS:
66  return TE_TR("SKEWNESS");
67 
68  case te::stat::KURTOSIS:
69  return TE_TR("KURTOSIS");
70 
72  return TE_TR("AMPLITUDE");
73 
74  case te::stat::MEDIAN:
75  return TE_TR("MEDIAN");
76 
78  return TE_TR("VAR_COEFF");
79 
80  case te::stat::MODE:
81  return TE_TR("MODE");
82 
83  default:
84  return ("");
85  }
86 }
87 
88 std::string te::stat::GetStatSummaryFullName(const int& e)
89 {
90  switch(e)
91  {
93  return TE_TR("Minimum value");
94 
96  return TE_TR("Maximum value");
97 
98  case te::stat::MEAN:
99  return TE_TR("Mean");
100 
101  case te::stat::SUM:
102  return TE_TR("Sum of values");
103 
104  case te::stat::COUNT:
105  return TE_TR("Total number of values");
106 
108  return TE_TR("Total not null values");
109 
111  return TE_TR("Standard deviation");
112 
113  case te::stat::VARIANCE:
114  return TE_TR("Variance");
115 
116  case te::stat::SKEWNESS:
117  return TE_TR("Skewness");
118 
119  case te::stat::KURTOSIS:
120  return TE_TR("Kurtosis");
121 
122  case te::stat::AMPLITUDE:
123  return TE_TR("Amplitude");
124 
125  case te::stat::MEDIAN:
126  return TE_TR("Median");
127 
128  case te::stat::VAR_COEFF:
129  return TE_TR("Coefficient variation");
130 
131  case te::stat::MODE:
132  return TE_TR("Mode");
133 
134  default:
135  return ("");
136  }
137 }
138 
139 std::vector<std::string> te::stat::GetStringData(te::da::DataSet* dataSet, const std::string propName)
140 {
141  std::vector<std::string> result;
142  std::string value="";
143 
144  dataSet->moveFirst();
145 
146  do
147  {
148  if (!dataSet->isNull(propName))
149  {
150  value = dataSet->getString(propName);
151  result.push_back(value);
152  }
153  }while(dataSet->moveNext());
154 
155  return result;
156 }
157 
158 std::vector<double> te::stat::GetNumericData(te::da::DataSet* dataSet, const std::string propName)
159 {
160  std::vector<double> result;
161  double numval;
162 
163  size_t index=0;
164  for (index=0; index<dataSet->getNumProperties(); ++index)
165  if (dataSet->getPropertyName(index) == propName)
166  break;
167 
168  std::size_t type = dataSet->getPropertyDataType(index);
169  dataSet->moveFirst();
170  do
171  {
172  if (!dataSet->isNull(propName))
173  {
174  if (type == te::dt::INT16_TYPE)
175  numval = dataSet->getInt16(index);
176  else if (type == te::dt::INT32_TYPE)
177  numval = dataSet->getInt32(index);
178  else if (type == te::dt::INT64_TYPE)
179  numval = (double)dataSet->getInt64(index);
180  else if (type == te::dt::FLOAT_TYPE)
181  numval = dataSet->getFloat(index);
182  else if (type == te::dt::DOUBLE_TYPE)
183  numval = dataSet->getDouble(index);
184  else if(type == te::dt::NUMERIC_TYPE)
185  numval = boost::lexical_cast<double>(dataSet->getNumeric(index));
186  result.push_back(numval);
187  }
188  }while(dataSet->moveNext());
189 
190  return result;
191 }
Mean.
Definition: Enums.h:43
virtual boost::int16_t getInt16(std::size_t i) const =0
Method for retrieving a 16-bit integer attribute value (2 bytes long).
virtual boost::int32_t getInt32(std::size_t i) const =0
Method for retrieving a 32-bit integer attribute value (4 bytes long).
Skewness.
Definition: Enums.h:49
Total not null values.
Definition: Enums.h:46
Total number of values.
Definition: Enums.h:45
virtual boost::int64_t getInt64(std::size_t i) const =0
Method for retrieving a 64-bit integer attribute value (8 bytes long).
TESTATEXPORT std::string GetStatSummaryShortName(const int &e)
Get the statistical parameter short name from its enumerator.
Definition: Utils.cpp:37
Utility functions for Statistics.
virtual std::string getNumeric(std::size_t i) const =0
Method for retrieving a numeric attribute value.
#define TE_TR(message)
It marks a string in order to get translated.
Definition: Translator.h:347
virtual double getDouble(std::size_t i) const =0
Method for retrieving a double attribute value.
TESTATEXPORT std::vector< double > GetNumericData(te::da::DataSet *dataSet, const std::string propName)
Returns the values of a numeric type property in a vector of values.
Definition: Utils.cpp:158
Minimum value.
Definition: Enums.h:41
virtual bool moveNext()=0
It moves the internal pointer to the next item of the collection.
virtual float getFloat(std::size_t i) const =0
Method for retrieving a float attribute value.
Median.
Definition: Enums.h:52
virtual std::string getPropertyName(std::size_t i) const =0
It returns the property name at position pos.
TESTATEXPORT std::vector< std::string > GetStringData(te::da::DataSet *dataSet, const std::string propName)
Returns the values of a string type property in a vector of values.
Definition: Utils.cpp:139
virtual bool isNull(std::size_t i) const =0
It checks if the attribute value is NULL.
Kurtosis.
Definition: Enums.h:50
Standard deviation.
Definition: Enums.h:47
Sum of values.
Definition: Enums.h:44
Enumerations related to Vector Processing module.
TESTATEXPORT std::string GetStatSummaryFullName(const int &e)
Get the statistical parameter full name ffrom its enumerator.
Definition: Utils.cpp:88
virtual std::size_t getNumProperties() const =0
It returns the number of properties that composes an item of the dataset.
Coefficient variation.
Definition: Enums.h:53
A dataset is the unit of information manipulated by the data access module of TerraLib.
Definition: DataSet.h:112
Mode.
Definition: Enums.h:54
virtual std::string getString(std::size_t i) const =0
Method for retrieving a string value attribute.
An exception class for the statistical module.
virtual int getPropertyDataType(std::size_t i) const =0
It returns the underlying data type of the property at position pos.
Variance.
Definition: Enums.h:48
Maximum value.
Definition: Enums.h:42
virtual bool moveFirst()=0
It moves the internal pointer to the first item in the collection.
Amplitude.
Definition: Enums.h:51
Configuration flags for the Terrralib Statistic module.