28 #include "terralib_config.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/utils/Utils.h" 
   35 #include "../datatype/Property.h" 
   36 #include "../datatype/SimpleProperty.h" 
   37 #include "../datatype/StringProperty.h" 
   39 #include "../geometry/Geometry.h" 
   40 #include "../geometry/GeometryProperty.h" 
   41 #include "../geometry/Utils.h" 
   43 #include "../memory/DataSet.h" 
   44 #include "../memory/DataSetItem.h" 
   46 #include "../statistics/core/SummaryFunctions.h" 
   47 #include "../statistics/core/StringStatisticalSummary.h" 
   48 #include "../statistics/core/NumericStatisticalSummary.h" 
   49 #include "../statistics/core/Utils.h" 
   63 #include <boost/lexical_cast.hpp> 
   64 #include <boost/algorithm/string.hpp> 
   74   std::map<std::string, std::string> result;
 
   76   std::map<te::dt::Property*, std::vector<te::stat::StatisticalSummary> >::const_iterator it = m_statSum.begin();
 
   77   while(it != m_statSum.end())
 
   81       size_t propPos = m_inDsetType->getPropertyPosition(it->first->getName());
 
   82       std::vector<std::string> values;
 
   83       for(std::size_t i = 0; i < items.size(); ++i)
 
   85         if (!items[i]->isNull(propPos))
 
   86           values.push_back(items[i]->getString(propPos));
 
   92       result.insert( std::map<std::string, std::string>::value_type(it->first->getName() + 
"_MIN_VALUE", ss.
m_minVal ));
 
   93       result.insert( std::map<std::string, std::string>::value_type(it->first->getName() + 
"_MAX_VALUE", ss.
m_maxVal ));
 
   94       result.insert( std::map<std::string, std::string>::value_type(it->first->getName() + 
"_COUNT", boost::lexical_cast<std::string>(items.size())));
 
   95       result.insert( std::map<std::string, std::string>::value_type(it->first->getName()+ 
"_VALID_COUNT", boost::lexical_cast<std::string>(values.size())));
 
  104   std::map<std::string, double> result;
 
  106   std::map<te::dt::Property*, std::vector<te::stat::StatisticalSummary> >::const_iterator it = m_statSum.begin();
 
  107   while(it != m_statSum.end())
 
  111       size_t propPos = m_inDsetType->getPropertyPosition(it->first->getName());
 
  112       int propType = it->first->getType();
 
  114       std::vector<double> values;
 
  115       for(std::size_t i = 0; i < items.size(); ++i)
 
  117         if (!items[i]->isNull(propPos))
 
  121             numval = items[i]->getInt16(propPos);
 
  123             numval = items[i]->getInt32(propPos);
 
  125             numval = (double)items[i]->getInt64(propPos);
 
  127             numval = items[i]->getFloat(propPos);
 
  129             numval = items[i]->getDouble(propPos);
 
  133           values.push_back(numval);
 
  137       std::string propName = it->first->getName();
 
  142       result.insert( std::map<std::string, double>::value_type(propName + 
"_MIN_VALUE", ss.
m_minVal));
 
  143       result.insert( std::map<std::string, double>::value_type(propName + 
"_MAX_VALUE", ss.
m_maxVal));
 
  144       result.insert( std::map<std::string, double>::value_type(propName + 
"_COUNT", items.size()));
 
  145       result.insert( std::map<std::string, double>::value_type(propName + 
"_VALID_COUNT", values.size()));
 
  146       result.insert( std::map<std::string, double>::value_type(propName + 
"_MEAN", ss.
m_mean));
 
  147       result.insert( std::map<std::string, double>::value_type(propName + 
"_SUM", ss.
m_sum));
 
  148       result.insert( std::map<std::string, double>::value_type(propName + 
"_STANDARD_DEVIATION", ss.
m_stdDeviation));
 
  149       result.insert( std::map<std::string, double>::value_type(propName + 
"_VARIANCE", ss.
m_variance));
 
  150       result.insert( std::map<std::string, double>::value_type(propName + 
"_SKEWNESS", ss.
m_skewness));
 
  151       result.insert( std::map<std::string, double>::value_type(propName + 
"_KURTOSIS", ss.
m_kurtosis));
 
  152       result.insert( std::map<std::string, double>::value_type(propName + 
"_AMPLITUDE", ss.
m_amplitude));
 
  153       result.insert( std::map<std::string, double>::value_type(propName + 
"_MEDIAN", ss.
m_median));
 
  154       result.insert( std::map<std::string, double>::value_type(propName + 
"_VAR_COEFF", ss.
m_varCoeff));
 
  158         modeProp = boost::lexical_cast<std::string>(ss.
m_mode[0]);
 
  159         for(std::size_t i=1; i<ss.
m_mode.size(); ++i)
 
  162           modeProp += boost::lexical_cast<std::string>(ss.
m_mode[i]);
 
  164         modeName = propName + 
"_MODE";
 
  184   dataSetType->add(stringProperty);
 
  188   dataSetType->add(aggregationProperty);
 
  191   std::string functionResult;
 
  192   std::vector<te::stat::StatisticalSummary> vectorResult;
 
  193   std::map<te::dt::Property*, std::vector<te::stat::StatisticalSummary> >::const_iterator it = m_statSum.begin();
 
  194   std::string propResult, funcResult;
 
  195   while(it != m_statSum.end())
 
  198     propResult = it->first->getName();
 
  201     vectorResult = it->second;
 
  203     for(std::size_t i = 0; i < vectorResult.size(); ++i)
 
  205       funcResult = propResult;
 
  211         dataSetType->add(funcProp);
 
  216         dataSetType->add(funcProp);
 
  229   dataSetType->add(geometry);
 
  238   std::string geomName = geom->
getName();
 
  239   std::size_t geomIdx = boost::lexical_cast<std::size_t>(m_inDsetType->getPropertyPosition(geomName));
 
  244   std::vector<size_t> groupPropIdxs;
 
  245   for(std::size_t i=0; i<m_groupProps.size(); ++i)
 
  248   std::map<std::string, std::vector<te::mem::DataSetItem*> > groups;
 
  249   std::map<std::string, std::vector<te::mem::DataSetItem*> >::iterator itg;
 
  251   std::auto_ptr<te::da::DataSet> inDset;
 
  254     inDset = m_inDsrc->getDataSet(m_inDsetName);
 
  256     inDset = m_inDsrc->getDataSet(m_inDsetName, m_oidSet);
 
  258   size_t nprops = inDset->getNumProperties();
 
  260   inDset->moveBeforeFirst();
 
  261   while(inDset->moveNext())
 
  264     std::string key = inDset->getAsString(groupPropIdxs[0]);
 
  265     for(std::size_t i=1; i<groupPropIdxs.size(); ++i)
 
  266       key += 
"_" + inDset->getAsString(groupPropIdxs[i]);
 
  270     for(std::size_t j=0; j<nprops; ++j)
 
  272       if (!inDset->isNull(j))
 
  274         std::auto_ptr<te::dt::AbstractData> val = inDset->
getValue(j);
 
  275         dataSetItem->
setValue(j,val.release());
 
  279     itg = groups.find(key);
 
  280     if (itg==groups.end())
 
  282       std::vector<te::mem::DataSetItem*> dataSetItemVector;
 
  283       dataSetItemVector.push_back(dataSetItem);
 
  284       groups.insert(std::pair<std::string, std::vector<te::mem::DataSetItem*> >(key,dataSetItemVector));
 
  287       itg->second.push_back(dataSetItem);
 
  292   std::auto_ptr<te::da::DataSetType> outDsType = this->buildOutDataSetType();
 
  295   std::auto_ptr<te::mem::DataSet> outDataset(
new te::mem::DataSet(outDsType.get()));
 
  302   itg = groups.begin();
 
  303   while(itg != groups.end())
 
  306     std::string value = itg->first;
 
  310     for (
size_t i = 0; i < itg->second.size(); ++i)
 
  312       if (!itg->second[i]->getGeometry(geomIdx)->isValid())
 
  314 #ifdef TERRALIB_LOGGER_ENABLED 
  315         te::common::Logger::logDebug(
"vp", 
"Aggregation - The input layer has invalid geometry.");
 
  316 #endif // TERRALIB_LOGGER_ENABLED 
  326       std::map<std::string, std::string> resultString = calculateStringStats(itg->second);
 
  329       std::string smodeprop, smodeval;  
 
  330       std::map<std::string, double> resultNumeric = calculateNumStats(itg->second,smodeval,smodeprop);
 
  335       outDSetItem->
setInt32(1, itg->second.size()); 
 
  338       std::map<std::string, std::string>::iterator itString = resultString.begin();
 
  339       while(itString != resultString.end())
 
  343             outDSetItem->
setString(itString->first, itString->second);
 
  348       if (!smodeval.empty())
 
  349         outDSetItem->
setString(smodeprop, smodeval);
 
  351       std::map<std::string, double>::iterator itNumeric = resultNumeric.begin();
 
  352       while(itNumeric != resultNumeric.end())
 
  355           outDSetItem->
setDouble(itNumeric->first, itNumeric->second);
 
  359       outDataset->add(outDSetItem);
 
  363 #ifdef TERRALIB_LOGGER_ENABLED 
  364         te::common::Logger::logDebug(
"vp", 
"Aggregation - The operation generated invalid geometry.");
 
  365 #endif // TERRALIB_LOGGER_ENABLED 
  370       throw te::vp::Exception(
TE_TR(
"Operation canceled!"));
 
  375   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...
 
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.