28 #include "../BuildConfig.h"
29 #include "../common/progress/TaskProgress.h"
30 #include "../common/Logger.h"
31 #include "../common/Translator.h"
33 #include "../dataaccess/dataset/DataSet.h"
34 #include "../dataaccess/dataset/DataSetAdapter.h"
35 #include "../dataaccess/utils/Utils.h"
36 #include "../datatype/Property.h"
37 #include "../datatype/SimpleProperty.h"
38 #include "../datatype/StringProperty.h"
40 #include "../geometry/Geometry.h"
41 #include "../geometry/GeometryProperty.h"
42 #include "../geometry/Utils.h"
44 #include "../memory/DataSet.h"
45 #include "../memory/DataSetItem.h"
47 #include "../statistics/core/SummaryFunctions.h"
48 #include "../statistics/core/StringStatisticalSummary.h"
49 #include "../statistics/core/NumericStatisticalSummary.h"
50 #include "../statistics/core/Utils.h"
64 #include <boost/lexical_cast.hpp>
65 #include <boost/algorithm/string.hpp>
75 std::map<std::string, std::string> result;
77 std::map<te::dt::Property*, std::vector<te::stat::StatisticalSummary> >::const_iterator it = m_statSum.begin();
78 while(it != m_statSum.end())
82 size_t propPos = m_converter->getResult()->getPropertyPosition(it->first->getName());
83 std::vector<std::string> values;
84 for(std::size_t i = 0; i < items.size(); ++i)
86 if (!items[i]->isNull(propPos))
87 values.push_back(items[i]->getString(propPos));
93 result.insert( std::map<std::string, std::string>::value_type(it->first->getName() +
"_MIN_VALUE", ss.
m_minVal ));
94 result.insert( std::map<std::string, std::string>::value_type(it->first->getName() +
"_MAX_VALUE", ss.
m_maxVal ));
95 result.insert( std::map<std::string, std::string>::value_type(it->first->getName() +
"_COUNT", boost::lexical_cast<std::string>(items.size())));
96 result.insert( std::map<std::string, std::string>::value_type(it->first->getName()+
"_VALID_COUNT", boost::lexical_cast<std::string>(values.size())));
105 std::map<std::string, double> result;
107 std::map<te::dt::Property*, std::vector<te::stat::StatisticalSummary> >::const_iterator it = m_statSum.begin();
108 while(it != m_statSum.end())
112 size_t propPos = m_converter->getResult()->getPropertyPosition(it->first->getName());
113 int propType = it->first->getType();
115 std::vector<double> values;
116 for(std::size_t i = 0; i < items.size(); ++i)
118 if (!items[i]->isNull(propPos))
122 numval = items[i]->getInt16(propPos);
124 numval = items[i]->getInt32(propPos);
126 numval = (double)items[i]->getInt64(propPos);
128 numval = items[i]->getFloat(propPos);
130 numval = items[i]->getDouble(propPos);
134 values.push_back(numval);
138 std::string propName = it->first->getName();
143 result.insert( std::map<std::string, double>::value_type(propName +
"_MIN_VALUE", ss.
m_minVal));
144 result.insert( std::map<std::string, double>::value_type(propName +
"_MAX_VALUE", ss.
m_maxVal));
145 result.insert( std::map<std::string, double>::value_type(propName +
"_COUNT", items.size()));
146 result.insert( std::map<std::string, double>::value_type(propName +
"_VALID_COUNT", values.size()));
147 result.insert( std::map<std::string, double>::value_type(propName +
"_MEAN", ss.
m_mean));
148 result.insert( std::map<std::string, double>::value_type(propName +
"_SUM", ss.
m_sum));
149 result.insert( std::map<std::string, double>::value_type(propName +
"_STANDARD_DEVIATION", ss.
m_stdDeviation));
150 result.insert( std::map<std::string, double>::value_type(propName +
"_VARIANCE", ss.
m_variance));
151 result.insert( std::map<std::string, double>::value_type(propName +
"_SKEWNESS", ss.
m_skewness));
152 result.insert( std::map<std::string, double>::value_type(propName +
"_KURTOSIS", ss.
m_kurtosis));
153 result.insert( std::map<std::string, double>::value_type(propName +
"_AMPLITUDE", ss.
m_amplitude));
154 result.insert( std::map<std::string, double>::value_type(propName +
"_MEDIAN", ss.
m_median));
155 result.insert( std::map<std::string, double>::value_type(propName +
"_VAR_COEFF", ss.
m_varCoeff));
159 modeProp = boost::lexical_cast<std::string>(ss.
m_mode[0]);
160 for(std::size_t i=1; i<ss.
m_mode.size(); ++i)
163 modeProp += boost::lexical_cast<std::string>(ss.
m_mode[i]);
165 modeName = propName +
"_MODE";
185 dataSetType->add(stringProperty);
189 dataSetType->add(aggregationProperty);
192 std::string functionResult;
193 std::vector<te::stat::StatisticalSummary> vectorResult;
194 std::map<te::dt::Property*, std::vector<te::stat::StatisticalSummary> >::const_iterator it = m_statSum.begin();
195 std::string propResult =
"";
196 std::string funcResult =
"";
197 while(it != m_statSum.end())
199 propResult = it->first->getName();
202 vectorResult = it->second;
204 for(std::size_t i = 0; i < vectorResult.size(); ++i)
206 funcResult = propResult;
212 dataSetType->add(funcProp);
217 dataSetType->add(funcProp);
230 dataSetType->add(geometry);
239 std::string geomName = geom->
getName();
240 std::size_t geomIdx = boost::lexical_cast<std::size_t>(m_converter->getResult()->getPropertyPosition(geomName));
245 std::vector<size_t> groupPropIdxs;
246 for(std::size_t i=0; i<m_groupProps.size(); ++i)
249 std::map<std::string, std::vector<te::mem::DataSetItem*> > groups;
250 std::map<std::string, std::vector<te::mem::DataSetItem*> >::iterator itg;
252 std::auto_ptr<te::da::DataSet> inDsetSrc;
255 inDsetSrc = m_inDsrc->getDataSet(m_inDsetName);
257 inDsetSrc = m_inDsrc->getDataSet(m_inDsetName, m_oidSet);
259 std::auto_ptr<te::da::DataSetAdapter> inDset(
te::da::CreateAdapter(inDsetSrc.get(), m_converter.get()));
261 size_t nprops = inDset->getNumProperties();
263 inDset->moveBeforeFirst();
264 while(inDset->moveNext())
267 std::string key = inDset->getAsString(groupPropIdxs[0]);
268 for(std::size_t i=1; i<groupPropIdxs.size(); ++i)
269 key +=
"_" + inDset->getAsString(groupPropIdxs[i]);
273 for(std::size_t j=0; j<nprops; ++j)
275 if (!inDset->isNull(j))
277 std::auto_ptr<te::dt::AbstractData> val = inDset->
getValue(j);
278 dataSetItem->
setValue(j,val.release());
282 itg = groups.find(key);
283 if (itg==groups.end())
285 std::vector<te::mem::DataSetItem*> dataSetItemVector;
286 dataSetItemVector.push_back(dataSetItem);
287 groups.insert(std::pair<std::string, std::vector<te::mem::DataSetItem*> >(key,dataSetItemVector));
290 itg->second.push_back(dataSetItem);
295 std::auto_ptr<te::da::DataSetType> outDsType = this->buildOutDataSetType();
298 std::auto_ptr<te::mem::DataSet> outDataset(
new te::mem::DataSet(outDsType.get()));
305 itg = groups.begin();
306 while(itg != groups.end())
309 std::string value = itg->first;
313 for (
size_t i = 0; i < itg->second.size(); ++i)
315 if (!itg->second[i]->getGeometry(geomIdx)->isValid())
317 #ifdef TERRALIB_LOGGER_ENABLED
318 te::common::Logger::logDebug(
"vp",
"Aggregation - The input layer has invalid geometry.");
319 #endif // TERRALIB_LOGGER_ENABLED
329 std::map<std::string, std::string> resultString = calculateStringStats(itg->second);
332 std::string smodeprop, smodeval;
333 std::map<std::string, double> resultNumeric = calculateNumStats(itg->second,smodeval,smodeprop);
338 outDSetItem->
setInt32(1, (
int)itg->second.size());
341 std::map<std::string, std::string>::iterator itString = resultString.begin();
342 while(itString != resultString.end())
346 outDSetItem->
setString(itString->first, itString->second);
351 if (!smodeval.empty())
352 outDSetItem->
setString(smodeprop, smodeval);
354 std::map<std::string, double>::iterator itNumeric = resultNumeric.begin();
355 while(itNumeric != resultNumeric.end())
358 outDSetItem->
setDouble(itNumeric->first, itNumeric->second);
362 outDataset->add(outDSetItem);
366 #ifdef TERRALIB_LOGGER_ENABLED
367 te::common::Logger::logDebug(
"vp",
"Aggregation - The operation generated invalid geometry.");
368 #endif // TERRALIB_LOGGER_ENABLED
373 throw te::vp::Exception(
TE_TR(
"Operation canceled!"));
378 te::vp::Save(m_outDsrc.get(), outDataset.get(), outDsType.get());
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.
void Save(te::da::DataSource *source, te::da::DataSet *result, te::da::DataSetType *outDsType)
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...
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)
TEDATAACCESSEXPORT DataSetAdapter * CreateAdapter(DataSet *ds, DataSetTypeConverter *converter, bool isOwner=false)
const std::string & getName() const
It returns the property name.