27 #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/GeometryCollection.h"
43 #include "../geometry/LineString.h"
44 #include "../geometry/MultiLineString.h"
45 #include "../geometry/MultiPolygon.h"
46 #include "../geometry/Point.h"
47 #include "../geometry/Polygon.h"
48 #include "../geometry/Utils.h"
50 #include "../memory/DataSet.h"
51 #include "../memory/DataSetItem.h"
65 #include <boost/lexical_cast.hpp>
66 #include <boost/algorithm/string.hpp>
78 std::vector<int> opGeom;
79 std::vector<int> opTab;
80 std::vector<te::da::DataSetType*> dsTypeVec;
82 for(std::size_t i = 0; i < m_operations.size(); ++i)
84 switch (m_operations[i])
106 #ifdef TERRALIB_LOGGER_ENABLED
107 te::common::Logger::logDebug(
"vp",
"Geometric Operation - The operation is not valid.");
108 #endif //TERRALIB_LOGGER_ENABLED
115 bool hasMultiGeomColumns =
false;
118 switch(m_objStrategy)
122 if(hasMultiGeomColumns)
128 if(opGeom.size() > 0)
130 for(std::size_t i = 0; i < opGeom.size(); ++i)
139 for(std::size_t dsTypePos = 0; dsTypePos < dsTypeVec.size(); ++dsTypePos)
141 m_outDsetNameVec.push_back(dsTypeVec[dsTypePos]->getName());
143 std::auto_ptr<te::da::DataSetType> outDataSetType(dsTypeVec[dsTypePos]);
144 std::auto_ptr<te::mem::DataSet> outDataSet(SetAllObjects(dsTypeVec[dsTypePos], opTab, opGeom));
148 te::vp::Save(m_outDsrc.get(), outDataSet.get(), outDataSetType.get());
164 if(hasMultiGeomColumns)
170 if(opGeom.size() > 0)
172 for(std::size_t i = 0; i < opGeom.size(); ++i)
181 for(std::size_t dsTypePos = 0; dsTypePos < dsTypeVec.size(); ++dsTypePos)
183 m_outDsetNameVec.push_back(dsTypeVec[dsTypePos]->getName());
185 std::auto_ptr<te::da::DataSetType> outDataSetType(dsTypeVec[dsTypePos]);
186 std::auto_ptr<te::mem::DataSet> outDataSet(SetAggregObj(dsTypeVec[dsTypePos], opTab, opGeom));
188 te::vp::Save(m_outDsrc.get(), outDataSet.get(), outDataSetType.get());
199 if(hasMultiGeomColumns)
205 if(opGeom.size() > 0)
207 for(std::size_t i = 0; i < opGeom.size(); ++i)
216 for(std::size_t dsTypePos = 0; dsTypePos < dsTypeVec.size(); ++dsTypePos)
218 m_outDsetNameVec.push_back(dsTypeVec[dsTypePos]->getName());
220 std::auto_ptr<te::da::DataSetType> outDataSetType(dsTypeVec[dsTypePos]);
221 std::auto_ptr<te::mem::DataSet> outDataSet(SetAggregByAttribute(dsTypeVec[dsTypePos], opTab, opGeom));
224 te::vp::Save(m_outDsrc.get(), outDataSet.get(), outDataSetType.get());
239 #ifdef TERRALIB_LOGGER_ENABLED
240 te::common::Logger::logDebug(
"vp",
"Geometric Operation - Strategy Not found!");
241 #endif //TERRALIB_LOGGER_ENABLED
257 std::vector<int> tabVec,
258 std::vector<int> geoVec)
264 std::auto_ptr<te::da::DataSet> inDsetSrc = m_inDsrc->getDataSet(m_inDsetName);
265 std::auto_ptr<te::da::DataSetAdapter> inDset(
te::da::CreateAdapter(inDsetSrc.get(), m_converter.get()));
267 inDset->moveBeforeFirst();
271 while(inDset->moveNext())
278 if(m_selectedProps.size() > 0)
280 for(std::size_t prop_pos = 0; prop_pos < m_selectedProps.size(); ++prop_pos)
282 item->
setValue(m_selectedProps[prop_pos], inDset->getValue(m_selectedProps[prop_pos]).release());
286 std::auto_ptr<te::gm::Geometry> in_geom = inDset->getGeometry(geom_pos);
288 if(tabVec.size() > 0)
290 for(std::size_t tabPos = 0; tabPos < tabVec.size(); ++tabPos)
292 switch(tabVec[tabPos])
297 area = CalculateTabularOp(tabVec[tabPos], in_geom.get());
304 line = CalculateTabularOp(tabVec[tabPos], in_geom.get());
310 double perimeter = 0;
311 perimeter = CalculateTabularOp(tabVec[tabPos], in_geom.get());
317 #ifdef TERRALIB_LOGGER_ENABLED
318 te::common::Logger::logDebug(
"vp",
"Geometric Operation - Could not insert the tabular value.");
319 #endif //TERRALIB_LOGGER_ENABLED
325 if(geoVec.size() > 0)
327 for(std::size_t geoPos = 0; geoPos < geoVec.size(); ++geoPos)
329 switch(geoVec[geoPos])
334 if(pos < dsType->size())
336 std::auto_ptr<te::gm::Geometry> convexHull(in_geom->convexHull());
337 convexHull->setSRID(in_geom->getSRID());
341 item->
setGeometry(
"convex_hull", convexHull.release());
352 if(pos < dsType->size())
364 if(pos < dsType->size())
366 std::auto_ptr<te::gm::Geometry> mbr(in_geom->getEnvelope());
367 mbr->setSRID(in_geom->getSRID());
377 #ifdef TERRALIB_LOGGER_ENABLED
378 te::common::Logger::logDebug(
"vp",
"Geometric Operation - Could not insert the geometric value.");
379 #endif //TERRALIB_LOGGER_ENABLED
386 std::auto_ptr<te::gm::Geometry> g(in_geom.release());
389 switch(g->getGeomTypeId())
394 teGeomColl->add(g.release());
400 teGeomColl->add(g.release());
406 teGeomColl->add(g.release());
411 #ifdef TERRALIB_LOGGER_ENABLED
412 te::common::Logger::logDebug(
"vp",
"Geometric Operation - Could not insert the geometry in collection.");
413 #endif //TERRALIB_LOGGER_ENABLED
416 if(teGeomColl->getNumGeometries() != 0)
429 return outDSet.release();
434 std::vector<int> tabVec,
435 std::vector<int> geoVec)
441 std::auto_ptr<te::da::DataSet> inDsetSrc = m_inDsrc->getDataSet(m_inDsetName);
442 std::auto_ptr<te::da::DataSetAdapter> inDset(
te::da::CreateAdapter(inDsetSrc.get(), m_converter.get()));
451 std::auto_ptr<te::gm::Geometry> seedGeom = inDset->getGeometry(geom_pos);
452 int srid = seedGeom->getSRID();
455 if(inDset->size() > 1)
457 while(inDset->moveNext())
459 std::auto_ptr<te::gm::Geometry> c_geom = inDset->getGeometry(geom_pos);
460 if(c_geom->isValid())
461 teGeomColl->
add(c_geom.release());
467 seedGeom.reset(seedGeom->Union(teGeomColl));
468 seedGeom->setSRID(srid);
471 if(tabVec.size() > 0)
473 for(std::size_t tabPos = 0; tabPos < tabVec.size(); ++tabPos)
475 switch(tabVec[tabPos])
480 area = CalculateTabularOp(tabVec[tabPos], seedGeom.get());
487 line = CalculateTabularOp(tabVec[tabPos], seedGeom.get());
493 double perimeter = 0;
494 perimeter = CalculateTabularOp(tabVec[tabPos], seedGeom.get());
500 #ifdef TERRALIB_LOGGER_ENABLED
501 te::common::Logger::logDebug(
"vp",
"Geometric Operation - Could not insert the tabular value.");
502 #endif //TERRALIB_LOGGER_ENABLED
508 if(geoVec.size() > 0)
510 for(std::size_t geoPos = 0; geoPos < geoVec.size(); ++geoPos)
512 switch(geoVec[geoPos])
517 if(pos < dsType->size())
519 std::auto_ptr<te::gm::Geometry> convexHull(seedGeom->convexHull());
520 convexHull->setSRID(seedGeom->getSRID());
521 item->
setGeometry(
"convex_hull", convexHull.release());
528 if(pos < dsType->size())
540 if(pos < dsType->size())
542 std::auto_ptr<te::gm::Geometry> mbr(seedGeom->getEnvelope());
543 mbr->setSRID(seedGeom->getSRID());
550 #ifdef TERRALIB_LOGGER_ENABLED
551 te::common::Logger::logDebug(
"vp",
"Geometric Operation - Could not insert the geometry in collection.");
552 #endif //TERRALIB_LOGGER_ENABLED
559 std::auto_ptr<te::gm::Geometry> g(seedGeom.release());
562 switch(g->getGeomTypeId())
567 teGeomColl->add(g.release());
573 teGeomColl->add(g.release());
579 teGeomColl->add(g.release());
584 #ifdef TERRALIB_LOGGER_ENABLED
585 te::common::Logger::logDebug(
"vp",
"Geometric Operation - Could not insert the geometry in collection.");
586 #endif //TERRALIB_LOGGER_ENABLED
589 if(teGeomColl->getNumGeometries() != 0)
597 return outDSet.release();
601 std::vector<int> tabVec,
602 std::vector<int> geoVec)
604 std::map<std::string, te::gm::Geometry*> geometries;
606 std::auto_ptr<te::da::DataSet> inDsetSrc = m_inDsrc->getDataSet(m_inDsetName);
607 std::auto_ptr<te::da::DataSetAdapter> inDset(
te::da::CreateAdapter(inDsetSrc.get(), m_converter.get()));
614 std::auto_ptr<te::gm::Geometry> seedGeom = inDset->getGeometry(geom_pos);
616 if(inDset->size() > 1)
618 std::map<std::string, std::vector<te::mem::DataSetItem*> > groups;
619 std::map<std::string, std::vector<te::mem::DataSetItem*> >::iterator itg;
620 size_t nprops = inDset->getNumProperties();
623 inDset->moveBeforeFirst();
624 while(inDset->moveNext())
626 std::string key = inDset->getAsString(m_attribute);
628 for(std::size_t j=0; j<nprops; ++j)
630 if (!inDset->isNull(j))
632 std::auto_ptr<te::dt::AbstractData> val = inDset->
getValue(j);
637 itg = groups.find(key);
638 if (itg==groups.end())
640 std::vector<te::mem::DataSetItem*> dataSetItemVector;
641 dataSetItemVector.push_back(item);
642 groups.insert(std::pair<std::string, std::vector<te::mem::DataSetItem*> >(key,dataSetItemVector));
645 itg->second.push_back(item);
648 itg = groups.begin();
649 while(itg != groups.end())
655 geometries.insert(std::pair<std::string, te::gm::Geometry*>(itg->first,geometry));
663 geometries.insert(std::pair<std::string, te::gm::Geometry*>(inDset->getAsString(m_attribute), seedGeom.release()));
668 std::map<std::string, te::gm::Geometry*>::iterator itGeom;
671 itGeom = geometries.begin();
672 while(itGeom != geometries.end())
679 te::dt::Property* prop = m_converter->getResult()->getProperty(m_attribute);
686 outItem->
setInt16(1, boost::lexical_cast<int16_t>(itGeom->first));
689 outItem->
setInt32(1, boost::lexical_cast<int>(itGeom->first));
692 outItem->
setInt64(1, boost::lexical_cast<int>(itGeom->first));
695 outItem->
setDouble(1, boost::lexical_cast<double>(itGeom->first));
698 #ifdef TERRALIB_LOGGER_ENABLED
699 te::common::Logger::logDebug(
"vp",
"Geometric Operation - Could not insert the aggregated value.");
700 #endif //TERRALIB_LOGGER_ENABLED
705 if(tabVec.size() > 0)
707 for(std::size_t tabPos = 0; tabPos < tabVec.size(); ++tabPos)
709 switch(tabVec[tabPos])
714 area = CalculateTabularOp(tabVec[tabPos], itGeom->second);
721 line = CalculateTabularOp(tabVec[tabPos], itGeom->second);
727 double perimeter = 0;
728 perimeter = CalculateTabularOp(tabVec[tabPos], itGeom->second);
729 outItem->
setDouble(
"perimeter", perimeter);
734 #ifdef TERRALIB_LOGGER_ENABLED
735 te::common::Logger::logDebug(
"vp",
"Geometric Operation - Could not insert the tabular value.");
736 #endif //TERRALIB_LOGGER_ENABLED
742 if(geoVec.size() > 0)
744 for(std::size_t geoPos = 0; geoPos < geoVec.size(); ++geoPos)
746 switch(geoVec[geoPos])
751 if(pos < dsType->size())
753 std::auto_ptr<te::gm::Geometry> convexHull(itGeom->second->convexHull());
754 convexHull->setSRID(seedGeom->getSRID());
755 outItem->
setGeometry(
"convex_hull", convexHull.release());
762 if(pos < dsType->size())
774 if(pos < dsType->size())
776 std::auto_ptr<te::gm::Geometry> mbr(itGeom->second->getEnvelope());
777 mbr->setSRID(seedGeom->getSRID());
784 #ifdef TERRALIB_LOGGER_ENABLED
785 te::common::Logger::logDebug(
"vp",
"Geometric Operation - Could not insert the geometric value.");
786 #endif //TERRALIB_LOGGER_ENABLED
795 switch(itGeom->second->getGeomTypeId())
799 if(itGeom->second->isValid())
800 teGeomColl->
add(itGeom->second);
805 if(itGeom->second->isValid())
806 teGeomColl->
add(itGeom->second);
811 if(itGeom->second->isValid())
812 teGeomColl->
add(itGeom->second);
817 #ifdef TERRALIB_LOGGER_ENABLED
818 te::common::Logger::logDebug(
"vp",
"Geometric Operation - Could not insert the geometry in collection.");
819 #endif //TERRALIB_LOGGER_ENABLED
828 outDSet->add(outItem);
833 return outDSet.release();
857 if(type ==
"GeometryCollection")
863 std::vector<te::gm::Geometry*> geomVec = m_geoColl->
getGeometries();
864 for(std::size_t i = 0; i < geomVec.size(); ++i)
921 if(type ==
"GeometryCollection")
927 std::vector<te::gm::Geometry*> geomVec = m_geoColl->
getGeometries();
928 for(std::size_t i = 0; i < geomVec.size(); ++i)
958 #ifdef TERRALIB_LOGGER_ENABLED
959 te::common::Logger::logDebug(
"vp",
"Geometric Operation - Could not calculate the operation.");
960 #endif //TERRALIB_LOGGER_ENABLED
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.
void Save(te::da::DataSource *source, te::da::DataSet *result, te::da::DataSetType *outDsType)
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.
TEDATAACCESSEXPORT DataSetAdapter * CreateAdapter(DataSet *ds, DataSetTypeConverter *converter, bool isOwner=false)
All objects individually.