All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Utils.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2008-2011 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 std::string te::stat::GetStatSummaryShortName(const int& e)
35 {
36  switch(e)
37  {
39  return TR_STATISTICS("MIN_VALUE");
40 
42  return TR_STATISTICS("MAX_VALUE");
43 
44  case te::stat::MEAN:
45  return TR_STATISTICS("MEAN");
46 
47  case te::stat::SUM:
48  return TR_STATISTICS("SUM");
49 
50  case te::stat::COUNT:
51  return TR_STATISTICS("COUNT");
52 
54  return TR_STATISTICS("VALID_COUNT");
55 
57  return TR_STATISTICS("STANDARD_DEVIATION");
58 
59  case te::stat::VARIANCE:
60  return TR_STATISTICS("VARIANCE");
61 
62  case te::stat::SKEWNESS:
63  return TR_STATISTICS("SKEWNESS");
64 
65  case te::stat::KURTOSIS:
66  return TR_STATISTICS("KURTOSIS");
67 
69  return TR_STATISTICS("AMPLITUDE");
70 
71  case te::stat::MEDIAN:
72  return TR_STATISTICS("MEDIAN");
73 
75  return TR_STATISTICS("VAR_COEFF");
76 
77  case te::stat::MODE:
78  return TR_STATISTICS("MODE");
79 
80  default:
81  return ("");
82  }
83 }
84 
85 std::string te::stat::GetStatSummaryFullName(const int& e)
86 {
87  switch(e)
88  {
90  return TR_STATISTICS("Minimum value");
91 
93  return TR_STATISTICS("Maximum value");
94 
95  case te::stat::MEAN:
96  return TR_STATISTICS("Mean");
97 
98  case te::stat::SUM:
99  return TR_STATISTICS("Sum of values");
100 
101  case te::stat::COUNT:
102  return TR_STATISTICS("Total number of values");
103 
105  return TR_STATISTICS("Total not null values");
106 
108  return TR_STATISTICS("Standard deviation");
109 
110  case te::stat::VARIANCE:
111  return TR_STATISTICS("Variance");
112 
113  case te::stat::SKEWNESS:
114  return TR_STATISTICS("Skewness");
115 
116  case te::stat::KURTOSIS:
117  return TR_STATISTICS("Kurtosis");
118 
119  case te::stat::AMPLITUDE:
120  return TR_STATISTICS("Amplitude");
121 
122  case te::stat::MEDIAN:
123  return TR_STATISTICS("Median");
124 
125  case te::stat::VAR_COEFF:
126  return TR_STATISTICS("Coefficient variation");
127 
128  case te::stat::MODE:
129  return TR_STATISTICS("Mode");
130 
131  default:
132  return ("");
133  }
134 }
135 
136 std::vector<std::string> te::stat::GetStringData(te::da::DataSet* dataSet, const std::string propName)
137 {
138  std::vector<std::string> result;
139  std::string value="";
140 
141  dataSet->moveFirst();
142 
143  do
144  {
145  if (!dataSet->isNull(propName))
146  {
147  value = dataSet->getString(propName);
148  result.push_back(value);
149  }
150  }while(dataSet->moveNext());
151 
152  return result;
153 }
154 
155 std::vector<double> te::stat::GetNumericData(te::da::DataSet* dataSet, const std::string propName)
156 {
157  std::vector<double> result;
158  double numval;
159 
160  size_t index=0;
161  for (index=0; index<dataSet->getNumProperties(); ++index)
162  if (dataSet->getPropertyName(index) == propName)
163  break;
164 
165  std::size_t type = dataSet->getPropertyDataType(index);
166  dataSet->moveFirst();
167  do
168  {
169  if (!dataSet->isNull(propName))
170  {
171  if (type == te::dt::INT16_TYPE)
172  numval = dataSet->getInt16(index);
173  else if (type == te::dt::INT32_TYPE)
174  numval = dataSet->getInt32(index);
175  else if (type == te::dt::INT64_TYPE)
176  numval = (double)dataSet->getInt64(index);
177  else if (type == te::dt::FLOAT_TYPE)
178  numval = dataSet->getFloat(index);
179  else if (type == te::dt::DOUBLE_TYPE)
180  numval = dataSet->getDouble(index);
181  result.push_back(numval);
182  }
183  }while(dataSet->moveNext());
184 
185  return result;
186 }
virtual std::string getPropertyName(std::size_t i) const =0
It returns the property name at position pos.
virtual double getDouble(std::size_t i) const =0
Method for retrieving a double attribute value.
virtual std::size_t getNumProperties() const =0
It returns the number of properties that composes an item of the dataset.
Total number of values.
Definition: Enums.h:45
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:85
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:155
virtual float getFloat(std::size_t i) const =0
Method for retrieving a float attribute value.
Standard deviation.
Definition: Enums.h:47
virtual boost::int32_t getInt32(std::size_t i) const =0
Method for retrieving a 32-bit integer attribute value (4 bytes long).
virtual std::string getString(std::size_t i) const =0
Method for retrieving a string value attribute.
Coefficient variation.
Definition: Enums.h:53
virtual bool moveNext()=0
It moves the internal pointer to the next item of the collection.
virtual bool isNull(std::size_t i) const =0
It checks if the attribute value is NULL.
Mean.
Definition: Enums.h:43
Mode.
Definition: Enums.h:54
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:136
Total not null values.
Definition: Enums.h:46
virtual boost::int16_t getInt16(std::size_t i) const =0
Method for retrieving a 16-bit integer attribute value (2 bytes long).
An exception class for the statistical module.
Amplitude.
Definition: Enums.h:51
virtual int getPropertyDataType(std::size_t i) const =0
It returns the underlying data type of the property at position pos.
Maximum value.
Definition: Enums.h:42
virtual boost::int64_t getInt64(std::size_t i) const =0
Method for retrieving a 64-bit integer attribute value (8 bytes long).
#define TR_STATISTICS(message)
It marks a string in order to get translated. This is a special mark used in the Terrralib Statistics...
Definition: Config.h:58
Median.
Definition: Enums.h:52
Skewness.
Definition: Enums.h:49
Kurtosis.
Definition: Enums.h:50
Variance.
Definition: Enums.h:48
Configuration flags for the Terrralib Statistic module.
virtual bool moveFirst()=0
It moves the internal pointer to the first item in the collection.
Utility functions for Statistics.
Sum of values.
Definition: Enums.h:44
A dataset is the unit of information manipulated by the data access module of TerraLib.
Definition: DataSet.h:111
TESTATEXPORT std::string GetStatSummaryShortName(const int &e)
Get the statistical parameter short name from its enumerator.
Definition: Utils.cpp:34
Minimum value.
Definition: Enums.h:41