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"
35 #include "../datatype/Property.h"
36 #include "../datatype/SimpleProperty.h"
37 #include "../datatype/StringProperty.h"
39 #include "../dataaccess/query/Avg.h"
40 #include "../dataaccess/query/Count.h"
41 #include "../dataaccess/query/DataSetName.h"
42 #include "../dataaccess/query/Expression.h"
43 #include "../dataaccess/query/Field.h"
44 #include "../dataaccess/query/Fields.h"
45 #include "../dataaccess/query/From.h"
46 #include "../dataaccess/query/FromItem.h"
47 #include "../dataaccess/query/GroupBy.h"
48 #include "../dataaccess/query/GroupByItem.h"
49 #include "../dataaccess/query/Literal.h"
50 #include "../dataaccess/query/LiteralBool.h"
51 #include "../dataaccess/query/PropertyName.h"
52 #include "../dataaccess/query/Select.h"
53 #include "../dataaccess/query/ST_Area.h"
54 #include "../dataaccess/query/ST_Centroid.h"
55 #include "../dataaccess/query/ST_ConvexHull.h"
56 #include "../dataaccess/query/ST_Envelope.h"
57 #include "../dataaccess/query/ST_Length.h"
58 #include "../dataaccess/query/ST_Perimeter.h"
59 #include "../dataaccess/query/ST_Union.h"
60 #include "../dataaccess/query/Variance.h"
61 #include "../dataaccess/utils/Utils.h"
63 #include "../geometry/Geometry.h"
64 #include "../geometry/GeometryCollection.h"
65 #include "../geometry/GeometryProperty.h"
66 #include "../geometry/Utils.h"
68 #include "../memory/DataSet.h"
69 #include "../memory/DataSetItem.h"
71 #include "../statistics/core/SummaryFunctions.h"
72 #include "../statistics/core/StringStatisticalSummary.h"
73 #include "../statistics/core/NumericStatisticalSummary.h"
87 #include <boost/lexical_cast.hpp>
88 #include <boost/algorithm/string.hpp>
99 std::vector<int> opGeom;
100 std::vector<int> opTab;
101 std::vector<te::da::DataSetType*> dsTypeVec;
103 for(std::size_t i = 0; i < m_operations.size(); ++i)
105 switch(m_operations[i])
127 #ifdef TERRALIB_LOGGER_ENABLED
128 te::common::Logger::logDebug(
"vp",
"Geometric Operation - The operation is not valid.");
129 #endif //TERRALIB_LOGGER_ENABLED
136 bool hasMultiGeomColumns =
false;
139 switch(m_objStrategy)
143 if(hasMultiGeomColumns)
149 if(opGeom.size() > 0)
151 for(std::size_t i = 0; i < opGeom.size(); ++i)
160 for(std::size_t dsTypePos = 0; dsTypePos < dsTypeVec.size(); ++dsTypePos)
162 m_outDsetNameVec.push_back(dsTypeVec[dsTypePos]->getName());
164 std::auto_ptr<te::da::DataSetType> outDataSetType(dsTypeVec[dsTypePos]);
165 std::auto_ptr<te::mem::DataSet> outDataSet(SetAllObjects(dsTypeVec[dsTypePos], opTab, opGeom));
167 te::vp::Save(m_outDsrc.get(), outDataSet.get(), outDataSetType.get());
177 if(hasMultiGeomColumns)
183 if(opGeom.size() > 0)
185 for(std::size_t i = 0; i < opGeom.size(); ++i)
194 for(std::size_t dsTypePos = 0; dsTypePos < dsTypeVec.size(); ++dsTypePos)
196 m_outDsetNameVec.push_back(dsTypeVec[dsTypePos]->getName());
198 std::auto_ptr<te::da::DataSetType> outDataSetType(dsTypeVec[dsTypePos]);
199 std::auto_ptr<te::mem::DataSet> outDataSet(SetAggregObj(dsTypeVec[dsTypePos], opTab, opGeom));
202 te::vp::Save(m_outDsrc.get(), outDataSet.get(), outDataSetType.get());
216 if(hasMultiGeomColumns)
222 if(opGeom.size() > 0)
224 for(std::size_t i = 0; i < opGeom.size(); ++i)
233 for(std::size_t dsTypePos = 0; dsTypePos < dsTypeVec.size(); ++dsTypePos)
235 m_outDsetNameVec.push_back(dsTypeVec[dsTypePos]->getName());
237 std::auto_ptr<te::da::DataSetType> outDataSetType(dsTypeVec[dsTypePos]);
238 std::auto_ptr<te::mem::DataSet> outDataSet(SetAggregByAttribute(dsTypeVec[dsTypePos], opTab, opGeom));
241 te::vp::Save(m_outDsrc.get(), outDataSet.get(), outDataSetType.get());
255 #ifdef TERRALIB_LOGGER_ENABLED
256 te::common::Logger::logDebug(
"vp",
"Geometric Operation - Strategy Not found!");
257 #endif //TERRALIB_LOGGER_ENABLED
275 std::vector<int> tabVec,
276 std::vector<int> geoVec)
279 std::auto_ptr<te::da::DataSet> inDset = m_inDsrc->getDataSet(m_inDsetName);
284 if(m_selectedProps.size() > 0)
286 for(std::size_t prop_pos = 0; prop_pos < m_selectedProps.size(); ++prop_pos)
289 fields->push_back(f_prop);
293 std::string name = inDset->getPropertyName(geom_pos);
295 if(tabVec.size() > 0)
297 for(std::size_t tabPos = 0; tabPos < tabVec.size(); ++tabPos)
302 switch(tabVec[tabPos])
308 fields->push_back(f);
315 fields->push_back(f);
322 fields->push_back(f);
327 #ifdef TERRALIB_LOGGER_ENABLED
328 te::common::Logger::logDebug(
"vp",
"Geometric Operation - Invalid field to add in query.");
329 #endif //TERRALIB_LOGGER_ENABLED
335 if(geoVec.size() > 0)
337 for(std::size_t geoPos = 0; geoPos < geoVec.size(); ++geoPos)
342 switch(geoVec[geoPos])
347 if( pos < outDSet->getNumProperties() && pos > 0)
351 fields->push_back(f_geom);
358 if( pos < outDSet->getNumProperties() && pos > 0)
362 fields->push_back(f_geom);
369 if( pos < outDSet->getNumProperties() && pos > 0)
373 fields->push_back(f_geom);
379 #ifdef TERRALIB_LOGGER_ENABLED
380 te::common::Logger::logDebug(
"vp",
"Geometric Operation - Invalid field to add in query.");
381 #endif //TERRALIB_LOGGER_ENABLED
389 fields->push_back(f_prop);
394 from->push_back(fromItem);
398 std::auto_ptr<te::da::DataSet> dsQuery = m_inDsrc->query(select);
400 if (dsQuery->isEmpty())
403 SetOutputDSet(dsQuery.get(), outDSet.get());
405 return outDSet.release();
409 std::vector<int> tabVec,
410 std::vector<int> geoVec)
414 std::auto_ptr<te::da::DataSet> inDset = m_inDsrc->getDataSet(m_inDsetName);
416 std::string name = inDset->getPropertyName(geom_pos);
420 if(tabVec.size() > 0)
422 for(std::size_t tabPos = 0; tabPos < tabVec.size(); ++tabPos)
427 switch(tabVec[tabPos])
434 fields->push_back(f);
442 fields->push_back(f);
450 fields->push_back(f);
455 #ifdef TERRALIB_LOGGER_ENABLED
456 te::common::Logger::logDebug(
"vp",
"Geometric Operation - Invalid field to add in query.");
457 #endif //TERRALIB_LOGGER_ENABLED
463 if(geoVec.size() > 0)
465 for(std::size_t geoPos = 0; geoPos < geoVec.size(); ++geoPos)
470 switch(geoVec[geoPos])
475 if( pos < outDSet->getNumProperties() && pos > 0)
480 fields->push_back(f_geom);
487 if( pos < outDSet->getNumProperties() && pos > 0)
492 fields->push_back(f_geom);
499 if( pos < outDSet->getNumProperties() && pos > 0)
504 fields->push_back(f_geom);
510 #ifdef TERRALIB_LOGGER_ENABLED
511 te::common::Logger::logDebug(
"vp",
"Geometric Operation - Invalid field to add in query.");
512 #endif //TERRALIB_LOGGER_ENABLED
521 fields->push_back(f_prop);
526 from->push_back(fromItem);
530 std::auto_ptr<te::da::DataSet> dsQuery = m_inDsrc->query(select);
532 if (dsQuery->isEmpty())
535 SetOutputDSet(dsQuery.get(), outDSet.get());
537 return outDSet.release();
541 std::vector<int> tabVec,
542 std::vector<int> geoVec)
545 std::auto_ptr<te::da::DataSet> inDset = m_inDsrc->getDataSet(m_inDsetName);
547 std::string name = inDset->getPropertyName(geom_pos);
552 fields->push_back(f_aggreg);
554 if(tabVec.size() > 0)
556 for(std::size_t tabPos = 0; tabPos < tabVec.size(); ++tabPos)
561 switch(tabVec[tabPos])
568 fields->push_back(f);
576 fields->push_back(f);
584 fields->push_back(f);
589 #ifdef TERRALIB_LOGGER_ENABLED
590 te::common::Logger::logDebug(
"vp",
"Geometric Operation - Invalid field to add in query.");
591 #endif //TERRALIB_LOGGER_ENABLED
597 if(geoVec.size() > 0)
599 for(std::size_t geoPos = 0; geoPos < geoVec.size(); ++geoPos)
604 switch(geoVec[geoPos])
609 if( pos < outDSet->getNumProperties() && pos > 0)
614 fields->push_back(f_geom);
621 if( pos < outDSet->getNumProperties() && pos > 0)
626 fields->push_back(f_geom);
633 if( pos < outDSet->getNumProperties() && pos > 0)
638 fields->push_back(f_geom);
644 #ifdef TERRALIB_LOGGER_ENABLED
645 te::common::Logger::logDebug(
"vp",
"Geometric Operation - Invalid field to add in query.");
646 #endif //TERRALIB_LOGGER_ENABLED
655 fields->push_back(f_prop);
660 from->push_back(fromItem);
666 groupBy->push_back(e_groupBy);
670 std::auto_ptr<te::da::DataSet> dsQuery = m_inDsrc->query(select);
672 if (dsQuery->isEmpty())
675 SetOutputDSet(dsQuery.get(), outDSet.get());
677 return outDSet.release();
686 bool geomFlag =
true;
697 for(std::size_t i = 0; i < numProps; ++i)
721 if(inPropName ==
"convex_hull")
732 else if(inPropName ==
"centroid")
738 else if(inPropName ==
"mbr")
796 #ifdef TERRALIB_LOGGER_ENABLED
797 te::common::Logger::logDebug(
"vp",
"Geometric Operation - Property type not found.");
798 #endif //TERRALIB_LOGGER_ENABLED
805 outDataSet->
add(dItem);
te::da::DataSetType * GetDataSetType(te::vp::GeometricOpObjStrategy, bool MultiGeomColumns, int geomOp=-1)
int getSRID() const
It returns the Spatial Reference System ID associated to this geometric object.
virtual boost::int16_t getInt16(std::size_t i) const =0
Method for retrieving a 16-bit integer attribute value (2 bytes long).
boost::ptr_vector< GroupByItem > GroupBy
A class that can be used to model a GROUP BY clause.
An exception class for the Vector processing module.
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.
A class that can be used in a GROUP BY clause.
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...
virtual boost::int32_t getInt32(std::size_t i) const =0
Method for retrieving a 32-bit integer attribute value (4 bytes long).
void setDouble(std::size_t i, double value)
It sets the value of the i-th property.
The geographic operation Line.
A class that models the name of a dataset used in a From clause.
The geographic operation Minimum Bounding Rectangle.
A class that models the name of any property of an object.
A class that models the description of a dataset.
virtual boost::int64_t getInt64(std::size_t i) const =0
Method for retrieving a 64-bit integer attribute value (8 bytes long).
void Save(te::da::DataSource *source, te::da::DataSet *result, te::da::DataSetType *outDsType)
void setInt16(std::size_t i, boost::int16_t value)
It sets the value of the i-th property.
virtual double getDouble(std::size_t i) const =0
Method for retrieving a double attribute value.
Spatial envelope operator.
This is an abstract class that models a query expression.
void add(DataSetItem *item)
It adds a new item to the dataset and takes its ownership.
Spatial perimeter operator.
void setInt32(std::size_t i, boost::int32_t value)
It sets the value of the i-th property.
virtual bool moveNext()=0
It moves the internal pointer to the next item of the collection.
Implementation of a random-access dataset class for the TerraLib In-Memory Data Access driver...
TEDATAACCESSEXPORT std::size_t GetFirstSpatialPropertyPos(const te::da::DataSet *dataset)
It returns the first dataset spatial property or NULL if none is found.
The geographic operation Area.
virtual std::string getPropertyName(std::size_t i) const =0
It returns the property name at position pos.
boost::ptr_vector< Field > Fields
Fields is just a boost::ptr_vector of Field pointers.
Aggregate objects by attribute.
void SetOutputDSet(te::da::DataSet *inDataSet, te::mem::DataSet *outDataSet)
The geographic operation Perimeter.
virtual bool isValid() const
It tells if the geometry is well formed.
GeomType getGeomTypeId() const
It returns the geometry subclass type identifier.
virtual std::size_t getNumProperties() const =0
It returns the number of properties that composes an item of the dataset.
void setGroupBy(GroupBy *g)
It sets the list of expressions used to condense the result set.
The geographic operation Centroid.
te::mem::DataSet * SetAggregByAttribute(te::da::DataSetType *dsType, std::vector< int > tabVec, std::vector< int > geoVec)
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
A Select models a query to be used when retrieving data from a DataSource.
virtual std::auto_ptr< te::gm::Geometry > getGeometry(std::size_t i) const =0
Method for retrieving a geometric attribute value.
boost::ptr_vector< FromItem > From
It models the FROM clause for a query.
Spatial centroid operator.
An implementation of the DatasetItem class for the TerraLib In-Memory Data Access driver...
A dataset is the unit of information manipulated by the data access module of TerraLib.
virtual bool moveBeforeFirst()=0
It moves the internal pointer to a position before the first item in the collection.
void setGeometryN(std::size_t i, Geometry *g)
It sets the n-th geometry in this geometry collection.
The geographic operation Convex Hull.
std::size_t getPropertyPosition(const std::string &name) const
It returns the property position based on its name.
ST_Union statistical function.
te::mem::DataSet * SetAllObjects(te::da::DataSetType *dsType, std::vector< int > tabVec, std::vector< int > geoVec)
Configuration flags for the Terrralib Vector Processing module.
virtual std::string getString(std::size_t i) const =0
Method for retrieving a string value attribute.
void setString(std::size_t i, const std::string &value)
It sets the value of the i-th property.
void setInt64(std::size_t i, boost::int64_t value)
It sets the value of the i-th property.
It is a collection of other geometric objects.
virtual int getPropertyDataType(std::size_t i) const =0
It returns the underlying data type of the property at position pos.
All objects individually.
te::mem::DataSet * SetAggregObj(te::da::DataSetType *dsType, std::vector< int > tabVec, std::vector< int > geoVec)