28 #include "../common/progress/TaskProgress.h"
29 #include "../common/Logger.h"
30 #include "../common/Translator.h"
32 #include "../dataaccess/dataset/DataSet.h"
33 #include "../dataaccess/utils/Utils.h"
34 #include "../datatype/Property.h"
35 #include "../datatype/SimpleProperty.h"
36 #include "../datatype/StringProperty.h"
38 #include "../geometry/Geometry.h"
39 #include "../geometry/GeometryProperty.h"
40 #include "../geometry/Utils.h"
42 #include "../memory/DataSet.h"
43 #include "../memory/DataSetItem.h"
45 #include "../statistics/core/SummaryFunctions.h"
46 #include "../statistics/core/StringStatisticalSummary.h"
47 #include "../statistics/core/NumericStatisticalSummary.h"
48 #include "../statistics/core/Utils.h"
62 #include <boost/lexical_cast.hpp>
63 #include <boost/algorithm/string.hpp>
73 std::map<std::string, std::string> result;
75 std::map<te::dt::Property*, std::vector<te::stat::StatisticalSummary> >::const_iterator it = m_statSum.begin();
76 while(it != m_statSum.end())
80 size_t propPos = m_inDsetType->getPropertyPosition(it->first->getName());
81 std::vector<std::string> values;
82 for(std::size_t i = 0; i < items.size(); ++i)
84 if (!items[i]->isNull(propPos))
85 values.push_back(items[i]->getString(propPos));
91 result.insert( std::map<std::string, std::string>::value_type(it->first->getName() +
"_MIN_VALUE", ss.
m_minVal ));
92 result.insert( std::map<std::string, std::string>::value_type(it->first->getName() +
"_MAX_VALUE", ss.
m_maxVal ));
93 result.insert( std::map<std::string, std::string>::value_type(it->first->getName() +
"_COUNT", boost::lexical_cast<std::string>(items.size())));
94 result.insert( std::map<std::string, std::string>::value_type(it->first->getName()+
"_VALID_COUNT", boost::lexical_cast<std::string>(values.size())));
103 std::map<std::string, double> result;
105 std::map<te::dt::Property*, std::vector<te::stat::StatisticalSummary> >::const_iterator it = m_statSum.begin();
106 while(it != m_statSum.end())
110 size_t propPos = m_inDsetType->getPropertyPosition(it->first->getName());
111 int propType = it->first->getType();
113 std::vector<double> values;
114 for(std::size_t i = 0; i < items.size(); ++i)
116 if (!items[i]->isNull(propPos))
120 numval = items[i]->getInt16(propPos);
122 numval = items[i]->getInt32(propPos);
124 numval = (double)items[i]->getInt64(propPos);
126 numval = items[i]->getFloat(propPos);
128 numval = items[i]->getDouble(propPos);
132 values.push_back(numval);
136 std::string propName = it->first->getName();
141 result.insert( std::map<std::string, double>::value_type(propName +
"_MIN_VALUE", ss.
m_minVal));
142 result.insert( std::map<std::string, double>::value_type(propName +
"_MAX_VALUE", ss.
m_maxVal));
143 result.insert( std::map<std::string, double>::value_type(propName +
"_COUNT", items.size()));
144 result.insert( std::map<std::string, double>::value_type(propName +
"_VALID_COUNT", values.size()));
145 result.insert( std::map<std::string, double>::value_type(propName +
"_MEAN", ss.
m_mean));
146 result.insert( std::map<std::string, double>::value_type(propName +
"_SUM", ss.
m_sum));
147 result.insert( std::map<std::string, double>::value_type(propName +
"_STANDARD_DEVIATION", ss.
m_stdDeviation));
148 result.insert( std::map<std::string, double>::value_type(propName +
"_VARIANCE", ss.
m_variance));
149 result.insert( std::map<std::string, double>::value_type(propName +
"_SKEWNESS", ss.
m_skewness));
150 result.insert( std::map<std::string, double>::value_type(propName +
"_KURTOSIS", ss.
m_kurtosis));
151 result.insert( std::map<std::string, double>::value_type(propName +
"_AMPLITUDE", ss.
m_amplitude));
152 result.insert( std::map<std::string, double>::value_type(propName +
"_MEDIAN", ss.
m_median));
153 result.insert( std::map<std::string, double>::value_type(propName +
"_VAR_COEFF", ss.
m_varCoeff));
157 modeProp = boost::lexical_cast<std::string>(ss.
m_mode[0]);
158 for(std::size_t i=1; i<ss.
m_mode.size(); ++i)
161 modeProp += boost::lexical_cast<std::string>(ss.
m_mode[i]);
163 modeName = propName +
"_MODE";
183 dataSetType->add(stringProperty);
187 dataSetType->add(aggregationProperty);
190 std::string functionResult;
191 std::vector<te::stat::StatisticalSummary> vectorResult;
192 std::map<te::dt::Property*, std::vector<te::stat::StatisticalSummary> >::const_iterator it = m_statSum.begin();
193 std::string propResult, funcResult;
194 while(it != m_statSum.end())
197 propResult = it->first->getName();
200 vectorResult = it->second;
202 for(std::size_t i = 0; i < vectorResult.size(); ++i)
204 funcResult = propResult;
210 dataSetType->add(funcProp);
215 dataSetType->add(funcProp);
228 dataSetType->add(geometry);
237 std::string geomName = geom->
getName();
238 std::size_t geomIdx = boost::lexical_cast<std::size_t>(m_inDsetType->getPropertyPosition(geomName));
243 std::vector<size_t> groupPropIdxs;
244 for(std::size_t i=0; i<m_groupProps.size(); ++i)
247 std::map<std::string, std::vector<te::mem::DataSetItem*> > groups;
248 std::map<std::string, std::vector<te::mem::DataSetItem*> >::iterator itg;
250 std::auto_ptr<te::da::DataSet> inDset;
253 inDset = m_inDsrc->getDataSet(m_inDsetName);
255 inDset = m_inDsrc->getDataSet(m_inDsetName, m_oidSet);
257 size_t nprops = inDset->getNumProperties();
259 inDset->moveBeforeFirst();
260 while(inDset->moveNext())
263 std::string key = inDset->getAsString(groupPropIdxs[0]);
264 for(std::size_t i=1; i<groupPropIdxs.size(); ++i)
265 key +=
"_" + inDset->getAsString(groupPropIdxs[i]);
269 for(std::size_t j=0; j<nprops; ++j)
271 if (!inDset->isNull(j))
273 std::auto_ptr<te::dt::AbstractData> val = inDset->
getValue(j);
274 dataSetItem->
setValue(j,val.release());
278 itg = groups.find(key);
279 if (itg==groups.end())
281 std::vector<te::mem::DataSetItem*> dataSetItemVector;
282 dataSetItemVector.push_back(dataSetItem);
283 groups.insert(std::pair<std::string, std::vector<te::mem::DataSetItem*> >(key,dataSetItemVector));
286 itg->second.push_back(dataSetItem);
294 std::auto_ptr<te::da::DataSetType> outDsType = this->buildOutDataSetType();
297 std::auto_ptr<te::mem::DataSet> outDataset(
new te::mem::DataSet(outDsType.get()));
304 itg = groups.begin();
305 while(itg != groups.end())
308 std::string value = itg->first;
316 std::map<std::string, std::string> resultString = calculateStringStats(itg->second);
319 std::string smodeprop, smodeval;
320 std::map<std::string, double> resultNumeric = calculateNumStats(itg->second,smodeval,smodeprop);
325 outDSetItem->
setInt32(1, itg->second.size());
328 std::map<std::string, std::string>::iterator itString = resultString.begin();
329 while(itString != resultString.end())
333 outDSetItem->
setString(itString->first, itString->second);
338 if (!smodeval.empty())
339 outDSetItem->
setString(smodeprop, smodeval);
341 std::map<std::string, double>::iterator itNumeric = resultNumeric.begin();
342 while(itNumeric != resultNumeric.end())
345 outDSetItem->
setDouble(itNumeric->first, itNumeric->second);
349 outDataset->add(outDSetItem);
354 throw te::vp::Exception(
TE_TR(
"Operation canceled!"));
360 return save(outDataset,outDsType);
TESTATEXPORT void GetNumericStatisticalSummary(std::vector< double > &values, te::stat::NumericStatisticalSummary &ss, double nullVal)
A structure to hold the set of statistics from a set of numerical values.
An exception class for the Vector processing module.
GeomType
Each enumerated type is compatible with a Well-known Binary (WKB) type code.
void setGeometry(std::size_t i, te::gm::Geometry *value)
It sets the value of the i-th property.
Utility functions for the data access module.
void setSRID(int srid)
It sets the spatial reference system identifier associated to this property.
void setGeometryType(GeomType t)
It sets the geometry subtype.
void setDouble(std::size_t i, double value)
It sets the value of the i-th property.
An atomic property like an integer or double.
A class that models the description of a dataset.
void useTimer(bool flag)
Used to define if task use progress timer information.
std::auto_ptr< te::dt::AbstractData > getValue(std::size_t i) const
It returns the value of the i-th property.
TESTATEXPORT std::string GetStatSummaryShortName(const int &e)
Get the statistical parameter short name from its enumerator.
te::gm::Geometry * GetGeometryUnion(const std::vector< te::mem::DataSetItem * > &items, size_t geomIdx, te::gm::GeomType outGeoType)
It returns the union of a geometry vector.
This class can be used to inform the progress of a task.
TEDATAACCESSEXPORT std::size_t GetPropertyPos(const DataSet *dataset, const std::string &name)
void setValue(std::size_t i, te::dt::AbstractData *value)
It sets the value of the i-th property.
std::vector< double > m_mode
#define TE_TR(message)
It marks a string in order to get translated.
bool isActive() const
Verify if the task is active.
Aggregation Vector Processing functions.
std::map< std::string, double > calculateNumStats(const std::vector< te::mem::DataSetItem * > &items, std::string &modeProp, std::string &modeName)
void setTotalSteps(int value)
Set the task total stepes.
void setInt32(std::size_t i, boost::int32_t value)
It sets the value of the i-th property.
Implementation of a random-access dataset class for the TerraLib In-Memory Data Access driver...
int getSRID() const
It returns the spatial reference system identifier associated to this property.
GeomType getGeometryType() const
It returns the geometry subtype allowed for the property.
void pulse()
Calls setCurrentStep() function using getCurrentStep() + 1.
The type for string types: FIXED_STRING, VAR_STRING or STRING.
TESTATEXPORT void GetStringStatisticalSummary(std::vector< std::string > &values, te::stat::StringStatisticalSummary &ss)
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
An implementation of the DatasetItem class for the TerraLib In-Memory Data Access driver...
te::gm::GeomType GeomOpResultType(te::gm::GeomType firstGeom, te::gm::GeomType secondGeom)
A structure to hold the set of statistics from a set of categorical (sample) values.
Configuration flags for the Terrralib Vector Processing module.
void setString(std::size_t i, const std::string &value)
It sets the value of the i-th property.
std::auto_ptr< te::da::DataSetType > buildOutDataSetType()
TEDATAACCESSEXPORT te::gm::GeometryProperty * GetFirstGeomProperty(const DataSetType *dt)
std::map< std::string, std::string > calculateStringStats(const std::vector< te::mem::DataSetItem * > &items)
const std::string & getName() const
It returns the property name.