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/GeometryCollection.h"
41 #include "../geometry/LineString.h"
42 #include "../geometry/MultiLineString.h"
43 #include "../geometry/MultiPolygon.h"
44 #include "../geometry/Point.h"
45 #include "../geometry/Polygon.h"
46 #include "../geometry/Utils.h"
48 #include "../memory/DataSet.h"
49 #include "../memory/DataSetItem.h"
63 #include <boost/lexical_cast.hpp>
64 #include <boost/algorithm/string.hpp>
76 std::vector<int> opGeom;
77 std::vector<int> opTab;
78 std::vector<te::da::DataSetType*> dsTypeVec;
80 for(std::size_t i = 0; i < m_operations.size(); ++i)
82 switch(m_operations[i])
103 te::common::Logger::logDebug(
"vp",
"Geometric Operation - The operation is not valid.");
109 bool hasMultiGeomColumns =
false;
112 switch(m_objStrategy)
116 if(hasMultiGeomColumns)
122 if(opGeom.size() > 0)
124 for(std::size_t i = 0; i < opGeom.size(); ++i)
133 for(std::size_t dsTypePos = 0; dsTypePos < dsTypeVec.size(); ++dsTypePos)
135 m_outDsetNameVec.push_back(dsTypeVec[dsTypePos]->getName());
137 std::auto_ptr<te::da::DataSetType> outDataSetType(dsTypeVec[dsTypePos]);
138 std::auto_ptr<te::mem::DataSet> outDataSet(SetAllObjects(dsTypeVec[dsTypePos], opTab, opGeom));
139 result = save(outDataSet, outDataSetType);
149 if(hasMultiGeomColumns)
155 if(opGeom.size() > 0)
157 for(std::size_t i = 0; i < opGeom.size(); ++i)
166 for(std::size_t dsTypePos = 0; dsTypePos < dsTypeVec.size(); ++dsTypePos)
168 m_outDsetNameVec.push_back(dsTypeVec[dsTypePos]->getName());
170 std::auto_ptr<te::da::DataSetType> outDataSetType(dsTypeVec[dsTypePos]);
171 std::auto_ptr<te::mem::DataSet> outDataSet(SetAggregObj(dsTypeVec[dsTypePos], opTab, opGeom));
172 result = save(outDataSet, outDataSetType);
182 if(hasMultiGeomColumns)
188 if(opGeom.size() > 0)
190 for(std::size_t i = 0; i < opGeom.size(); ++i)
199 for(std::size_t dsTypePos = 0; dsTypePos < dsTypeVec.size(); ++dsTypePos)
201 m_outDsetNameVec.push_back(dsTypeVec[dsTypePos]->getName());
203 std::auto_ptr<te::da::DataSetType> outDataSetType(dsTypeVec[dsTypePos]);
204 std::auto_ptr<te::mem::DataSet> outDataSet(SetAggregByAttribute(dsTypeVec[dsTypePos], opTab, opGeom));
205 result = save(outDataSet, outDataSetType);
213 te::common::Logger::logDebug(
"vp",
"Geometric Operation - Strategy Not found!");
228 std::vector<int> tabVec,
229 std::vector<int> geoVec)
234 std::auto_ptr<te::da::DataSet> inDset = m_inDsrc->getDataSet(m_inDsetName);
235 inDset->moveBeforeFirst();
239 while(inDset->moveNext())
246 if(m_selectedProps.size() > 0)
248 for(std::size_t prop_pos = 0; prop_pos < m_selectedProps.size(); ++prop_pos)
250 item->
setValue(m_selectedProps[prop_pos], inDset->getValue(m_selectedProps[prop_pos]).release());
254 std::auto_ptr<te::gm::Geometry> in_geom = inDset->getGeometry(geom_pos);
256 if(tabVec.size() > 0)
258 for(std::size_t tabPos = 0; tabPos < tabVec.size(); ++tabPos)
260 switch(tabVec[tabPos])
265 area = CalculateTabularOp(tabVec[tabPos], in_geom.get());
272 line = CalculateTabularOp(tabVec[tabPos], in_geom.get());
278 double perimeter = 0;
279 perimeter = CalculateTabularOp(tabVec[tabPos], in_geom.get());
284 te::common::Logger::logDebug(
"vp",
"Geometric Operation - Could not insert the tabular value.");
289 if(geoVec.size() > 0)
291 for(std::size_t geoPos = 0; geoPos < geoVec.size(); ++geoPos)
293 switch(geoVec[geoPos])
298 if(pos < dsType->size())
300 std::auto_ptr<te::gm::Geometry> convexHull(in_geom->convexHull());
301 convexHull->setSRID(in_geom->getSRID());
305 item->
setGeometry(
"convex_hull", convexHull.release());
316 if(pos < dsType->size())
328 if(pos < dsType->size())
330 std::auto_ptr<te::gm::Geometry> mbr(in_geom->getEnvelope());
331 mbr->setSRID(in_geom->getSRID());
340 te::common::Logger::logDebug(
"vp",
"Geometric Operation - Could not insert the geometric value.");
346 std::auto_ptr<te::gm::Geometry> g(in_geom.release());
349 switch(g->getGeomTypeId())
354 teGeomColl->add(g.release());
360 teGeomColl->add(g.release());
366 teGeomColl->add(g.release());
370 te::common::Logger::logDebug(
"vp",
"Geometric Operation - Could not insert the geometry in collection.");
372 if(teGeomColl->getNumGeometries() != 0)
385 return outDSet.release();
390 std::vector<int> tabVec,
391 std::vector<int> geoVec)
396 std::auto_ptr<te::da::DataSet> inDset = m_inDsrc->getDataSet(m_inDsetName);
404 std::auto_ptr<te::gm::Geometry> seedGeom = inDset->getGeometry(geom_pos);
405 int srid = seedGeom->getSRID();
408 if(inDset->size() > 1)
410 while(inDset->moveNext())
412 std::auto_ptr<te::gm::Geometry> c_geom = inDset->getGeometry(geom_pos);
413 if(c_geom->isValid())
414 teGeomColl->
add(c_geom.release());
420 seedGeom.reset(seedGeom->Union(teGeomColl));
421 seedGeom->setSRID(srid);
424 if(tabVec.size() > 0)
426 for(std::size_t tabPos = 0; tabPos < tabVec.size(); ++tabPos)
428 switch(tabVec[tabPos])
433 area = CalculateTabularOp(tabVec[tabPos], seedGeom.get());
440 line = CalculateTabularOp(tabVec[tabPos], seedGeom.get());
446 double perimeter = 0;
447 perimeter = CalculateTabularOp(tabVec[tabPos], seedGeom.get());
452 te::common::Logger::logDebug(
"vp",
"Geometric Operation - Could not insert the tabular value.");
457 if(geoVec.size() > 0)
459 for(std::size_t geoPos = 0; geoPos < geoVec.size(); ++geoPos)
461 switch(geoVec[geoPos])
466 if(pos < dsType->size())
468 std::auto_ptr<te::gm::Geometry> convexHull(seedGeom->convexHull());
469 convexHull->setSRID(seedGeom->getSRID());
470 item->
setGeometry(
"convex_hull", convexHull.release());
477 if(pos < dsType->size())
489 if(pos < dsType->size())
491 std::auto_ptr<te::gm::Geometry> mbr(seedGeom->getEnvelope());
492 mbr->setSRID(seedGeom->getSRID());
498 te::common::Logger::logDebug(
"vp",
"Geometric Operation - Could not insert the geometry in collection.");
504 std::auto_ptr<te::gm::Geometry> g(seedGeom.release());
507 switch(g->getGeomTypeId())
512 teGeomColl->add(g.release());
518 teGeomColl->add(g.release());
524 teGeomColl->add(g.release());
528 te::common::Logger::logDebug(
"vp",
"Geometric Operation - Could not insert the geometry in collection.");
530 if(teGeomColl->getNumGeometries() != 0)
538 return outDSet.release();
542 std::vector<int> tabVec,
543 std::vector<int> geoVec)
545 std::map<std::string, te::gm::Geometry*> geometries;
547 std::auto_ptr<te::da::DataSet> inDset = m_inDsrc->getDataSet(m_inDsetName);
554 std::auto_ptr<te::gm::Geometry> seedGeom = inDset->getGeometry(geom_pos);
555 int srid = seedGeom->getSRID();
557 if(inDset->size() > 1)
559 std::map<std::string, std::vector<te::mem::DataSetItem*> > groups;
560 std::map<std::string, std::vector<te::mem::DataSetItem*> >::iterator itg;
561 size_t nprops = inDset->getNumProperties();
564 inDset->moveBeforeFirst();
565 while(inDset->moveNext())
567 std::string key = inDset->getAsString(m_attribute);
569 for(std::size_t j=0; j<nprops; ++j)
571 if (!inDset->isNull(j))
573 std::auto_ptr<te::dt::AbstractData> val = inDset->
getValue(j);
578 itg = groups.find(key);
579 if (itg==groups.end())
581 std::vector<te::mem::DataSetItem*> dataSetItemVector;
582 dataSetItemVector.push_back(item);
583 groups.insert(std::pair<std::string, std::vector<te::mem::DataSetItem*> >(key,dataSetItemVector));
586 itg->second.push_back(item);
589 itg = groups.begin();
590 while(itg != groups.end())
596 geometries.insert(std::pair<std::string, te::gm::Geometry*>(itg->first,geometry));
604 geometries.insert(std::pair<std::string, te::gm::Geometry*>(inDset->getAsString(m_attribute), seedGeom.release()));
609 std::map<std::string, te::gm::Geometry*>::iterator itGeom;
612 itGeom = geometries.begin();
613 while(itGeom != geometries.end())
627 outItem->
setInt16(1, boost::lexical_cast<int>(itGeom->first));
630 outItem->
setInt32(1, boost::lexical_cast<int>(itGeom->first));
633 outItem->
setInt64(1, boost::lexical_cast<int>(itGeom->first));
636 outItem->
setDouble(1, boost::lexical_cast<double>(itGeom->first));
639 te::common::Logger::logDebug(
"vp",
"Geometric Operation - Could not insert the aggregated value.");
643 if(tabVec.size() > 0)
645 for(std::size_t tabPos = 0; tabPos < tabVec.size(); ++tabPos)
647 switch(tabVec[tabPos])
652 area = CalculateTabularOp(tabVec[tabPos], itGeom->second);
659 line = CalculateTabularOp(tabVec[tabPos], itGeom->second);
665 double perimeter = 0;
666 perimeter = CalculateTabularOp(tabVec[tabPos], itGeom->second);
667 outItem->
setDouble(
"perimeter", perimeter);
671 te::common::Logger::logDebug(
"vp",
"Geometric Operation - Could not insert the tabular value.");
676 if(geoVec.size() > 0)
678 for(std::size_t geoPos = 0; geoPos < geoVec.size(); ++geoPos)
680 switch(geoVec[geoPos])
685 if(pos < dsType->size())
687 std::auto_ptr<te::gm::Geometry> convexHull(itGeom->second->convexHull());
688 convexHull->setSRID(seedGeom->getSRID());
689 outItem->
setGeometry(
"convex_hull", convexHull.release());
696 if(pos < dsType->size())
708 if(pos < dsType->size())
710 std::auto_ptr<te::gm::Geometry> mbr(itGeom->second->getEnvelope());
711 mbr->setSRID(seedGeom->getSRID());
717 te::common::Logger::logDebug(
"vp",
"Geometric Operation - Could not insert the geometric value.");
725 switch(itGeom->second->getGeomTypeId())
729 if(itGeom->second->isValid())
730 teGeomColl->
add(itGeom->second);
735 if(itGeom->second->isValid())
736 teGeomColl->
add(itGeom->second);
741 if(itGeom->second->isValid())
742 teGeomColl->
add(itGeom->second);
746 te::common::Logger::logDebug(
"vp",
"Geometric Operation - Could not insert the geometry in collection.");
754 outDSet->add(outItem);
759 return outDSet.release();
783 if(type ==
"GeometryCollection")
789 std::vector<te::gm::Geometry*> geomVec = m_geoColl->
getGeometries();
790 for(std::size_t i = 0; i < geomVec.size(); ++i)
847 if(type ==
"GeometryCollection")
853 std::vector<te::gm::Geometry*> geomVec = m_geoColl->
getGeometries();
854 for(std::size_t i = 0; i < geomVec.size(); ++i)
883 te::common::Logger::logDebug(
"vp",
"Geometric Operation - Could not calculate the operation.");
std::size_t getNumGeometries() const
It returns the number of geometries in this GeometryCollection.
te::da::DataSetType * GetDataSetType(te::vp::GeometricOpObjStrategy, bool MultiGeomColumns, int geomOp=-1)
MultiPolygon is a MultiSurface whose elements are Polygons.
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 setDouble(std::size_t i, double value)
It sets the value of the i-th property.
The geographic operation Line.
double CalculateTabularOp(int tabOperation, te::gm::Geometry *geom)
The geographic operation Minimum Bounding Rectangle.
A class that models the description of a dataset.
virtual double getLength() const
The length of this curve in the unit associated to its spatial reference system.
std::auto_ptr< te::dt::AbstractData > getValue(std::size_t i) const
It returns the value of the i-th property.
double getPerimeter() const
It returns the length of the boundary for the surface.
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.
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.
te::mem::DataSet * SetAggregObj(te::da::DataSetType *dsType, std::vector< int > tabVec, std::vector< int > geoVec)
An utility struct for representing 2D coordinates.
void setInt16(std::size_t i, boost::int16_t value)
It sets the value of the i-th property.
double getPerimeter() const
It returns the length of the boundary for the surface.
It models a property definition.
void setInt32(std::size_t i, boost::int32_t value)
It sets the value of the i-th property.
Coord2D getCenter() const
It returns the rectangle's center coordinate.
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.
LineString is a curve with linear interpolation between points.
A point with x and y coordinate values.
An Envelope defines a 2D rectangular region.
te::mem::DataSet * SetAggregByAttribute(te::da::DataSetType *dsType, std::vector< int > tabVec, std::vector< int > geoVec)
te::mem::DataSet * SetAllObjects(te::da::DataSetType *dsType, std::vector< int > tabVec, std::vector< int > geoVec)
GeomType getGeometryType() const
It returns the geometry subtype allowed for the property.
virtual const std::string & getGeometryType() const =0
It returns the name of the geometry subclass.
Aggregate objects by attribute.
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.
The geographic operation Centroid.
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
double getArea() const
It returns the area of this surface, as measured in the spatial reference system of this surface...
int getType() const
It returns the property data type.
MultiLineString is a MultiCurve whose elements are LineStrings.
An implementation of the DatasetItem class for the TerraLib In-Memory Data Access driver...
Polygon is a subclass of CurvePolygon whose rings are defined by linear rings.
double getArea() const
It returns the area of this MultiSurface, as measured in the spatial reference system of this multisu...
void add(Geometry *g)
It adds the geometry into the collection.
const std::vector< Geometry * > & getGeometries() const
It returns a reference to the internal list of geometries.
The geographic operation Convex Hull.
double getLength() const
It returns the Length of this MultiCurve which is equal to the sum of the lengths of the element Curv...
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.
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.
All objects individually.