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"
36 #include "../datatype/Property.h"
37 #include "../datatype/SimpleProperty.h"
38 #include "../datatype/StringProperty.h"
40 #include "../dataaccess/query/Avg.h"
41 #include "../dataaccess/query/Count.h"
42 #include "../dataaccess/query/DataSetName.h"
43 #include "../dataaccess/query/Expression.h"
44 #include "../dataaccess/query/Field.h"
45 #include "../dataaccess/query/Fields.h"
46 #include "../dataaccess/query/From.h"
47 #include "../dataaccess/query/FromItem.h"
48 #include "../dataaccess/query/GroupBy.h"
49 #include "../dataaccess/query/GroupByItem.h"
50 #include "../dataaccess/query/Literal.h"
51 #include "../dataaccess/query/LiteralBool.h"
52 #include "../dataaccess/query/LiteralInt32.h"
53 #include "../dataaccess/query/PropertyName.h"
54 #include "../dataaccess/query/Select.h"
55 #include "../dataaccess/query/ST_Area.h"
56 #include "../dataaccess/query/ST_Centroid.h"
57 #include "../dataaccess/query/ST_ConvexHull.h"
58 #include "../dataaccess/query/ST_Envelope.h"
59 #include "../dataaccess/query/ST_Length.h"
60 #include "../dataaccess/query/ST_Perimeter.h"
61 #include "../dataaccess/query/ST_SetSRID.h"
62 #include "../dataaccess/query/ST_Union.h"
63 #include "../dataaccess/query/Variance.h"
64 #include "../dataaccess/utils/Utils.h"
66 #include "../geometry/Geometry.h"
67 #include "../geometry/GeometryCollection.h"
68 #include "../geometry/GeometryProperty.h"
69 #include "../geometry/Utils.h"
71 #include "../memory/DataSet.h"
72 #include "../memory/DataSetItem.h"
74 #include "../statistics/core/SummaryFunctions.h"
75 #include "../statistics/core/StringStatisticalSummary.h"
76 #include "../statistics/core/NumericStatisticalSummary.h"
90 #include <boost/lexical_cast.hpp>
91 #include <boost/algorithm/string.hpp>
102 std::vector<int> opGeom;
103 std::vector<int> opTab;
104 std::vector<te::da::DataSetType*> dsTypeVec;
106 for(std::size_t i = 0; i < m_operations.size(); ++i)
108 switch(m_operations[i])
130 #ifdef TERRALIB_LOGGER_ENABLED
131 te::common::Logger::logDebug(
"vp",
"Geometric Operation - The operation is not valid.");
132 #endif //TERRALIB_LOGGER_ENABLED
139 bool hasMultiGeomColumns =
false;
142 switch(m_objStrategy)
146 if(hasMultiGeomColumns)
152 if(opGeom.size() > 0)
154 for(std::size_t i = 0; i < opGeom.size(); ++i)
163 for(std::size_t dsTypePos = 0; dsTypePos < dsTypeVec.size(); ++dsTypePos)
165 m_outDsetNameVec.push_back(dsTypeVec[dsTypePos]->getName());
167 std::auto_ptr<te::da::DataSetType> outDataSetType(dsTypeVec[dsTypePos]);
168 std::auto_ptr<te::mem::DataSet> outDataSet(SetAllObjects(dsTypeVec[dsTypePos], opTab, opGeom));
170 te::vp::Save(m_outDsrc.get(), outDataSet.get(), outDataSetType.get());
180 if(hasMultiGeomColumns)
186 if(opGeom.size() > 0)
188 for(std::size_t i = 0; i < opGeom.size(); ++i)
197 for(std::size_t dsTypePos = 0; dsTypePos < dsTypeVec.size(); ++dsTypePos)
199 m_outDsetNameVec.push_back(dsTypeVec[dsTypePos]->getName());
201 std::auto_ptr<te::da::DataSetType> outDataSetType(dsTypeVec[dsTypePos]);
202 std::auto_ptr<te::mem::DataSet> outDataSet(SetAggregObj(dsTypeVec[dsTypePos], opTab, opGeom));
205 te::vp::Save(m_outDsrc.get(), outDataSet.get(), outDataSetType.get());
219 if(hasMultiGeomColumns)
225 if(opGeom.size() > 0)
227 for(std::size_t i = 0; i < opGeom.size(); ++i)
236 for(std::size_t dsTypePos = 0; dsTypePos < dsTypeVec.size(); ++dsTypePos)
238 m_outDsetNameVec.push_back(dsTypeVec[dsTypePos]->getName());
240 std::auto_ptr<te::da::DataSetType> outDataSetType(dsTypeVec[dsTypePos]);
241 std::auto_ptr<te::mem::DataSet> outDataSet(SetAggregByAttribute(dsTypeVec[dsTypePos], opTab, opGeom));
244 te::vp::Save(m_outDsrc.get(), outDataSet.get(), outDataSetType.get());
258 #ifdef TERRALIB_LOGGER_ENABLED
259 te::common::Logger::logDebug(
"vp",
"Geometric Operation - Strategy Not found!");
260 #endif //TERRALIB_LOGGER_ENABLED
278 std::vector<int> tabVec,
279 std::vector<int> geoVec)
282 std::auto_ptr<te::da::DataSet> inDset = m_inDsrc->getDataSet(m_inDsetName);
287 if(m_selectedProps.size() > 0)
289 for(std::size_t prop_pos = 0; prop_pos < m_selectedProps.size(); ++prop_pos)
292 fields->push_back(f_prop);
296 std::string name = inDset->getPropertyName(geom_pos);
298 if(tabVec.size() > 0)
300 for(std::size_t tabPos = 0; tabPos < tabVec.size(); ++tabPos)
305 switch(tabVec[tabPos])
311 fields->push_back(f);
318 fields->push_back(f);
325 fields->push_back(f);
330 #ifdef TERRALIB_LOGGER_ENABLED
331 te::common::Logger::logDebug(
"vp",
"Geometric Operation - Invalid field to add in query.");
332 #endif //TERRALIB_LOGGER_ENABLED
339 std::auto_ptr<te::da::DataSetType>dsTypeSource(m_inDsrc->getDataSetType(m_inDsetName));
344 if(geoVec.size() > 0)
346 for(std::size_t geoPos = 0; geoPos < geoVec.size(); ++geoPos)
352 switch(geoVec[geoPos])
357 if( pos < outDSet->getNumProperties() && pos > 0)
359 if (geomPropertySource->getSRID() != geomPropertyLayer->getSRID())
371 fields->push_back(f_geom);
378 if( pos < outDSet->getNumProperties() && pos > 0)
380 if (geomPropertySource->getSRID() != geomPropertyLayer->getSRID())
392 fields->push_back(f_geom);
399 if( pos < outDSet->getNumProperties() && pos > 0)
401 if (geomPropertySource->getSRID() != geomPropertyLayer->getSRID())
413 fields->push_back(f_geom);
419 #ifdef TERRALIB_LOGGER_ENABLED
420 te::common::Logger::logDebug(
"vp",
"Geometric Operation - Invalid field to add in query.");
421 #endif //TERRALIB_LOGGER_ENABLED
430 if (geomPropertySource->getSRID() != geomPropertyLayer->getSRID())
441 fields->push_back(f_prop);
446 from->push_back(fromItem);
450 std::auto_ptr<te::da::DataSet> dsQuery = m_inDsrc->query(select);
452 if (dsQuery->isEmpty())
455 SetOutputDSet(dsQuery.get(), outDSet.get());
457 return outDSet.release();
461 std::vector<int> tabVec,
462 std::vector<int> geoVec)
466 std::auto_ptr<te::da::DataSet> inDset = m_inDsrc->getDataSet(m_inDsetName);
468 std::string name = inDset->getPropertyName(geom_pos);
472 if(tabVec.size() > 0)
474 for(std::size_t tabPos = 0; tabPos < tabVec.size(); ++tabPos)
479 switch(tabVec[tabPos])
486 fields->push_back(f);
494 fields->push_back(f);
502 fields->push_back(f);
507 #ifdef TERRALIB_LOGGER_ENABLED
508 te::common::Logger::logDebug(
"vp",
"Geometric Operation - Invalid field to add in query.");
509 #endif //TERRALIB_LOGGER_ENABLED
516 std::auto_ptr<te::da::DataSetType>dsTypeSource(m_inDsrc->getDataSetType(m_inDsetName));
521 if(geoVec.size() > 0)
523 for(std::size_t geoPos = 0; geoPos < geoVec.size(); ++geoPos)
529 switch(geoVec[geoPos])
534 if( pos < outDSet->getNumProperties() && pos > 0)
536 if (geomPropertySource->getSRID() != geomPropertyLayer->getSRID())
549 fields->push_back(f_geom);
556 if( pos < outDSet->getNumProperties() && pos > 0)
558 if (geomPropertySource->getSRID() != geomPropertyLayer->getSRID())
571 fields->push_back(f_geom);
578 if( pos < outDSet->getNumProperties() && pos > 0)
580 if (geomPropertySource->getSRID() != geomPropertyLayer->getSRID())
593 fields->push_back(f_geom);
599 #ifdef TERRALIB_LOGGER_ENABLED
600 te::common::Logger::logDebug(
"vp",
"Geometric Operation - Invalid field to add in query.");
601 #endif //TERRALIB_LOGGER_ENABLED
610 if (geomPropertySource->getSRID() != geomPropertyLayer->getSRID())
621 fields->push_back(f_prop);
626 from->push_back(fromItem);
630 std::auto_ptr<te::da::DataSet> dsQuery = m_inDsrc->query(select);
632 if (dsQuery->isEmpty())
635 SetOutputDSet(dsQuery.get(), outDSet.get());
637 return outDSet.release();
641 std::vector<int> tabVec,
642 std::vector<int> geoVec)
645 std::auto_ptr<te::da::DataSet> inDset = m_inDsrc->getDataSet(m_inDsetName);
647 std::string name = inDset->getPropertyName(geom_pos);
652 fields->push_back(f_aggreg);
654 if(tabVec.size() > 0)
656 for(std::size_t tabPos = 0; tabPos < tabVec.size(); ++tabPos)
661 switch(tabVec[tabPos])
668 fields->push_back(f);
676 fields->push_back(f);
684 fields->push_back(f);
689 #ifdef TERRALIB_LOGGER_ENABLED
690 te::common::Logger::logDebug(
"vp",
"Geometric Operation - Invalid field to add in query.");
691 #endif //TERRALIB_LOGGER_ENABLED
698 std::auto_ptr<te::da::DataSetType>dsTypeSource(m_inDsrc->getDataSetType(m_inDsetName));
703 if(geoVec.size() > 0)
705 for(std::size_t geoPos = 0; geoPos < geoVec.size(); ++geoPos)
711 switch(geoVec[geoPos])
716 if( pos < outDSet->getNumProperties() && pos > 0)
718 if (geomPropertySource->getSRID() != geomPropertyLayer->getSRID())
731 fields->push_back(f_geom);
738 if( pos < outDSet->getNumProperties() && pos > 0)
740 if (geomPropertySource->getSRID() != geomPropertyLayer->getSRID())
753 fields->push_back(f_geom);
760 if( pos < outDSet->getNumProperties() && pos > 0)
762 if (geomPropertySource->getSRID() != geomPropertyLayer->getSRID())
775 fields->push_back(f_geom);
781 #ifdef TERRALIB_LOGGER_ENABLED
782 te::common::Logger::logDebug(
"vp",
"Geometric Operation - Invalid field to add in query.");
783 #endif //TERRALIB_LOGGER_ENABLED
792 if (geomPropertySource->getSRID() != geomPropertyLayer->getSRID())
803 fields->push_back(f_prop);
808 from->push_back(fromItem);
814 groupBy->push_back(e_groupBy);
818 std::auto_ptr<te::da::DataSet> dsQuery = m_inDsrc->query(select);
820 if (dsQuery->isEmpty())
823 SetOutputDSet(dsQuery.get(), outDSet.get());
825 return outDSet.release();
834 bool geomFlag =
true;
845 for(std::size_t i = 0; i < numProps; ++i)
869 if(inPropName ==
"convex_hull")
880 else if(inPropName ==
"centroid")
886 else if(inPropName ==
"mbr")
944 #ifdef TERRALIB_LOGGER_ENABLED
945 te::common::Logger::logDebug(
"vp",
"Geometric Operation - Property type not found.");
946 #endif //TERRALIB_LOGGER_ENABLED
953 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 Set SRID operator.
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.
TEDATAACCESSEXPORT te::gm::GeometryProperty * GetFirstGeomProperty(const DataSetType *dt)
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)