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 
84  return TE_TR("PERCENT_EACH_CLASS_BY_AREA");
85 
87  return TE_TR("PERCENT_TOTAL_AREA");
88 
89  default:
90  return ("");
91  }
92 }
93 
94 std::string te::stat::GetStatSummaryFullName(const int& e)
95 {
96  switch(e)
97  {
99  return TE_TR("Minimum value");
100 
101  case te::stat::MAX_VALUE:
102  return TE_TR("Maximum value");
103 
104  case te::stat::MEAN:
105  return TE_TR("Mean");
106 
107  case te::stat::SUM:
108  return TE_TR("Sum of values");
109 
110  case te::stat::COUNT:
111  return TE_TR("Total number of values");
112 
114  return TE_TR("Total not null values");
115 
117  return TE_TR("Standard deviation");
118 
119  case te::stat::VARIANCE:
120  return TE_TR("Variance");
121 
122  case te::stat::SKEWNESS:
123  return TE_TR("Skewness");
124 
125  case te::stat::KURTOSIS:
126  return TE_TR("Kurtosis");
127 
128  case te::stat::AMPLITUDE:
129  return TE_TR("Amplitude");
130 
131  case te::stat::MEDIAN:
132  return TE_TR("Median");
133 
134  case te::stat::VAR_COEFF:
135  return TE_TR("Coefficient variation");
136 
137  case te::stat::MODE:
138  return TE_TR("Mode");
139 
141  return TE_TR("Percente of each class by area");
142 
144  return TE_TR("Percente of total area.");
145 
146  default:
147  return ("");
148  }
149 }
150 
151 std::vector<std::string> te::stat::GetStringData(te::da::DataSet* dataSet, const std::string propName)
152 {
153  std::vector<std::string> result;
154  std::string value="";
155 
156  dataSet->moveFirst();
157 
158  do
159  {
160  if (!dataSet->isNull(propName))
161  {
162  value = dataSet->getString(propName);
163  result.push_back(value);
164  }
165  }while(dataSet->moveNext());
166 
167  return result;
168 }
169 
170 std::vector<double> te::stat::GetNumericData(te::da::DataSet* dataSet, const std::string propName)
171 {
172  std::vector<double> result;
173  double numval;
174 
175  size_t index=0;
176  for (index=0; index<dataSet->getNumProperties(); ++index)
177  if (dataSet->getPropertyName(index) == propName)
178  break;
179 
180  std::size_t type = dataSet->getPropertyDataType(index);
181  dataSet->moveFirst();
182  do
183  {
184  if (!dataSet->isNull(propName))
185  {
186  if (type == te::dt::INT16_TYPE)
187  numval = dataSet->getInt16(index);
188  else if (type == te::dt::INT32_TYPE)
189  numval = dataSet->getInt32(index);
190  else if (type == te::dt::INT64_TYPE)
191  numval = (double)dataSet->getInt64(index);
192  else if (type == te::dt::FLOAT_TYPE)
193  numval = dataSet->getFloat(index);
194  else if (type == te::dt::DOUBLE_TYPE)
195  numval = dataSet->getDouble(index);
196  else if(type == te::dt::NUMERIC_TYPE)
197  numval = boost::lexical_cast<double>(dataSet->getNumeric(index));
198  result.push_back(numval);
199  }
200  }while(dataSet->moveNext());
201 
202  return result;
203 }
Percente of total area.
Definition: Enums.h:56
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:346
Percente of each class by area.
Definition: Enums.h:55
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:170
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:151
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:94
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.