27 #include "../../dataaccess/query_h.h"
28 #include "../../dataaccess/dataset/DataSet.h"
29 #include "../../dataaccess/dataset/DataSetType.h"
30 #include "../../dataaccess/datasource/DataSource.h"
31 #include "../../dataaccess/datasource/DataSourceCapabilities.h"
32 #include "../../dataaccess/datasource/DataSourceTransactor.h"
33 #include "../../dataaccess/utils/Utils.h"
34 #include "../../dataaccess/query_h.h"
35 #include "../../datatype/Property.h"
36 #include "../../maptools/AbstractLayer.h"
37 #include "../../maptools/DataSetLayer.h"
44 #include <boost/lexical_cast.hpp>
58 std::vector<std::string> validValues;
59 for (
size_t i=0; i<values.size(); ++i)
61 if (values[i] != nulValue)
62 validValues.push_back(values[i]);
74 std::sort(values.begin(), values.end());
77 ss.
m_maxVal = values[values.size() - 1];
81 for(std::size_t i = 0; i < values.size(); ++i)
83 if(!values[i].empty())
97 std::vector<double> validValues;
98 for (
size_t i=0; i<values.size(); ++i)
100 if (values[i] != nulValue)
101 validValues.push_back(values[i]);
113 std::sort(values.begin(), values.end());
116 ss.
m_maxVal = values[values.size() - 1];
120 for(std::size_t i = 0; i < values.size(); ++i)
122 ss.
m_sum += values[i];
127 for(
int i = 0; i < ss.
m_count; ++i)
158 bool fullIntersection)
163 std::map<double, double> percentMap;
165 std::sort(values.begin(), values.end());
167 double key = values[0];
170 if (fullIntersection)
172 for (std::size_t i = 1; i < values.size(); ++i)
174 if (values[i] == key)
180 double percent = (count * 100) / (
double)values.size();
181 percentMap.insert(std::pair<double, double>(key, percent));
187 double percent = (count * 100) / (
double)values.size();
188 percentMap.insert(std::pair<double, double>(key, percent));
192 for (std::size_t i = 1; i < values.size(); ++i)
194 if (values[i] == key)
200 double areaIntersection = count*(resolutionX*resolutionY);
201 double percentInter = (areaIntersection / area) * 100;
202 percentMap.insert(std::pair<double, double>(key, percentInter));
208 double areaIntersection = count*(resolutionX*resolutionY);
209 double percentInter = (areaIntersection / area) * 100;
210 percentMap.insert(std::pair<double, double>(key, percentInter));
218 std::vector<double> mode;
223 std::map<double, int> mapMode;
225 for(std::size_t i = 0; i < values.size(); ++i)
231 std::map<double, int>::iterator itMode = mapMode.begin();
233 while(itMode != mapMode.end())
235 if(itMode->first == values[i])
245 mapMode.insert( std::map<double, int>::value_type( values[i] , 1 ) );
249 mapMode.insert( std::map<double, int>::value_type( values[i] , 1 ) );
252 std::map<double, int>::iterator itMode = mapMode.begin();
255 while(itMode != mapMode.end())
257 if(itMode->second > 1)
259 if(repeat < itMode->second)
261 repeat = itMode->second;
263 mode.push_back(itMode->first);
265 else if(repeat == itMode->second)
267 mode.push_back(itMode->first);
283 std::string mode =
"";
284 std::map<std::string, int> mapMode;
286 for(std::size_t i = 0; i < values.size(); ++i)
292 std::map<std::string, int>::iterator itMode = mapMode.begin();
294 while(itMode != mapMode.end())
296 if(itMode->first == values[i])
306 mapMode.insert( std::map<std::string, int>::value_type( values[i] , 1 ) );
310 mapMode.insert( std::map<std::string, int>::value_type( values[i] , 1 ) );
313 std::map<std::string, int>::iterator itMode = mapMode.begin();
316 while(itMode != mapMode.end())
318 if(repeat < itMode->second)
320 repeat = itMode->second;
321 mode = itMode->first;
332 const std::string& propName,
335 assert(inDatasource);
344 std::auto_ptr<te::da::DataSet> ds = inDatasource->
getDataSet(inDataset);
368 fields->push_back(f_min);
369 fields->push_back(f_max);
370 fields->push_back(f_count);
371 fields->push_back(f_validcount);
375 from->push_back(fromItem);
379 std::auto_ptr<te::da::DataSet> dsQuery = inDatasource->
query(select);
384 dsQuery->moveFirst();
386 ss.
m_minVal = dsQuery->getAsString(1);
387 ss.
m_maxVal = dsQuery->getAsString(2);
388 ss.
m_count = dsQuery->getInt16(3);
397 const std::string& propName,
400 assert(inDatasource);
409 std::auto_ptr<te::da::DataSet> ds = inDatasource->
getDataSet(inDataset);
445 fields->push_back(f_min);
446 fields->push_back(f_max);
447 fields->push_back(f_count);
448 fields->push_back(f_sum);
449 fields->push_back(f_mean);
450 fields->push_back(f_stddev);
451 fields->push_back(f_variance);
452 fields->push_back(f_amplitude);
456 from->push_back(fromItem);
460 std::auto_ptr<te::da::DataSet> dsQuery = inDatasource->
query(select);
465 dsQuery->moveFirst();
467 ss.
m_minVal = boost::lexical_cast<
double>(dsQuery->getAsString(0));
468 ss.
m_maxVal = boost::lexical_cast<
double>(dsQuery->getAsString(1));
469 ss.
m_count = boost::lexical_cast<
int>(dsQuery->getAsString(2));
470 ss.
m_sum = boost::lexical_cast<
double>(dsQuery->getAsString(3));
471 ss.
m_mean = boost::lexical_cast<
double>(dsQuery->getAsString(4));
472 ss.
m_stdDeviation = boost::lexical_cast<
double>(dsQuery->getAsString(5));
473 ss.
m_variance = boost::lexical_cast<
double>(dsQuery->getAsString(6));
474 ss.
m_amplitude = boost::lexical_cast<
double>(dsQuery->getAsString(7));
TESTATEXPORT void GetNumericStatisticalSummary(std::vector< double > &values, te::stat::NumericStatisticalSummary &ss, double nullVal)
const std::string & getName() const
It returns the property name.
TESTATEXPORT void GetNumericStatisticalSummaryQuery(const std::string &inDataset, te::da::DataSource *inDatasource, const std::string &propName, te::stat::NumericStatisticalSummary &ss)
A structure to hold the set of statistics from a set of numerical values.
Utility functions for the data access module.
An abstract class that models a source of data in a query.
The Field class can be used to model an expression that takes part of the output items of a SELECT...
A class that models the name of a dataset used in a From clause.
TESTATEXPORT void GetStringStatisticalSummaryQuery(const std::string &inDataset, te::da::DataSource *inDatasource, const std::string &propName, te::stat::StringStatisticalSummary &ss)
TESTATEXPORT std::vector< double > Mode(const std::vector< double > &values)
virtual std::auto_ptr< DataSet > query(const Select &q, te::common::TraverseType travType=te::common::FORWARDONLY, const te::common::AccessPolicy accessPolicy=te::common::RAccess)
It executes a query that may return some data using a generic query. This method always returns a dis...
A class that models the name of any property of an object.
Count statistical function.
std::vector< double > m_mode
A class that represents the known capabilities of a specific data source, i.e. this class informs all...
An abstract class for data providers like a DBMS, Web Services or a regular file. ...
Avg statistical function.
Min statistical function.
std::map< double, double > m_percentEachClass
This is an abstract class that models a query expression.
StdDev statistical function.
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.
A set of functions to calculate the statistic summary from a set of values.
TESAEXPORT double Sum(te::sa::GeneralizedProximityMatrix *gpm, int attrIdx)
Function used to calculate sum of a specific attribute from a gpm.
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.
virtual std::auto_ptr< DataSet > getDataSet(const std::string &name, te::common::TraverseType travType=te::common::FORWARDONLY, const te::common::AccessPolicy accessPolicy=te::common::RAccess)
It gets the dataset identified by the given name. This method always returns a disconnected dataset...
boost::ptr_vector< Field > Fields
Fields is just a boost::ptr_vector of Field pointers.
virtual const DataSourceCapabilities & getCapabilities() const =0
It returns the known capabilities of the data source.
TESTATEXPORT void GetStringStatisticalSummary(std::vector< std::string > &values, te::stat::StringStatisticalSummary &ss)
A Select models a query to be used when retrieving data from a DataSource.
boost::ptr_vector< FromItem > From
It models the FROM clause for a query.
virtual bool dataSetExists(const std::string &name)
It checks if a dataset with the given name exists in the data source.
The subtraction operator.
A structure to hold the set of statistics from a set of categorical (sample) values.
Variance statistical function.
bool supportsPreparedQueryAPI() const
An exception class for the statistical module.
Max statistical function.
TESTATEXPORT void GetPercentOfEachClassByArea(std::vector< double > &values, double &resolutionX, double &resolutionY, double &area, te::stat::NumericStatisticalSummary &ss, bool fullIntersection=true)
Configuration flags for the Terrralib Statistic module.