27 #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/GeometryCollection.h" 
   42 #include "../geometry/LineString.h" 
   43 #include "../geometry/MultiLineString.h" 
   44 #include "../geometry/MultiPolygon.h" 
   45 #include "../geometry/Point.h" 
   46 #include "../geometry/Polygon.h" 
   47 #include "../geometry/Utils.h" 
   49 #include "../memory/DataSet.h" 
   50 #include "../memory/DataSetItem.h" 
   64 #include <boost/lexical_cast.hpp> 
   65 #include <boost/algorithm/string.hpp> 
   77   std::vector<int> opGeom;
 
   78   std::vector<int> opTab;
 
   79   std::vector<te::da::DataSetType*> dsTypeVec;
 
   81   for(std::size_t i = 0; i < m_operations.size(); ++i)
 
   83     switch (m_operations[i])
 
  105 #ifdef TERRALIB_LOGGER_ENABLED 
  106         te::common::Logger::logDebug(
"vp", 
"Geometric Operation - The operation is not valid.");
 
  107 #endif //TERRALIB_LOGGER_ENABLED 
  114     bool hasMultiGeomColumns = 
false;
 
  117     switch(m_objStrategy)
 
  121           if(hasMultiGeomColumns) 
 
  127             if(opGeom.size() > 0)
 
  129               for(std::size_t i = 0; i < opGeom.size(); ++i)
 
  138           for(std::size_t dsTypePos = 0; dsTypePos < dsTypeVec.size(); ++dsTypePos)
 
  140             m_outDsetNameVec.push_back(dsTypeVec[dsTypePos]->getName());
 
  142             std::auto_ptr<te::da::DataSetType> outDataSetType(dsTypeVec[dsTypePos]);
 
  143             std::auto_ptr<te::mem::DataSet> outDataSet(SetAllObjects(dsTypeVec[dsTypePos], opTab, opGeom));
 
  147               te::vp::Save(m_outDsrc.get(), outDataSet.get(), outDataSetType.get());
 
  163           if(hasMultiGeomColumns) 
 
  169             if(opGeom.size() > 0)
 
  171               for(std::size_t i = 0; i < opGeom.size(); ++i)
 
  180           for(std::size_t dsTypePos = 0; dsTypePos < dsTypeVec.size(); ++dsTypePos)
 
  182             m_outDsetNameVec.push_back(dsTypeVec[dsTypePos]->getName());
 
  184             std::auto_ptr<te::da::DataSetType> outDataSetType(dsTypeVec[dsTypePos]);
 
  185             std::auto_ptr<te::mem::DataSet> outDataSet(SetAggregObj(dsTypeVec[dsTypePos], opTab, opGeom));
 
  187             te::vp::Save(m_outDsrc.get(), outDataSet.get(), outDataSetType.get());
 
  198           if(hasMultiGeomColumns) 
 
  204             if(opGeom.size() > 0)
 
  206               for(std::size_t i = 0; i < opGeom.size(); ++i)
 
  215           for(std::size_t dsTypePos = 0; dsTypePos < dsTypeVec.size(); ++dsTypePos)
 
  217             m_outDsetNameVec.push_back(dsTypeVec[dsTypePos]->getName());
 
  219             std::auto_ptr<te::da::DataSetType> outDataSetType(dsTypeVec[dsTypePos]);
 
  220             std::auto_ptr<te::mem::DataSet> outDataSet(SetAggregByAttribute(dsTypeVec[dsTypePos], opTab, opGeom));
 
  223               te::vp::Save(m_outDsrc.get(), outDataSet.get(), outDataSetType.get());
 
  238 #ifdef TERRALIB_LOGGER_ENABLED 
  239           te::common::Logger::logDebug(
"vp", 
"Geometric Operation - Strategy Not found!");
 
  240 #endif //TERRALIB_LOGGER_ENABLED 
  256                                                             std::vector<int> tabVec,
 
  257                                                             std::vector<int> geoVec)
 
  262   std::auto_ptr<te::da::DataSet> inDset = m_inDsrc->getDataSet(m_inDsetName);
 
  263   inDset->moveBeforeFirst();
 
  267   while(inDset->moveNext())
 
  274     if(m_selectedProps.size() > 0)
 
  276       for(std::size_t prop_pos = 0; prop_pos < m_selectedProps.size(); ++prop_pos)
 
  278         item->
setValue(m_selectedProps[prop_pos], inDset->getValue(m_selectedProps[prop_pos]).release());
 
  282     std::auto_ptr<te::gm::Geometry> in_geom = inDset->getGeometry(geom_pos);
 
  284     if(tabVec.size() > 0)
 
  286       for(std::size_t tabPos = 0; tabPos < tabVec.size(); ++tabPos)
 
  288         switch(tabVec[tabPos])
 
  293               area = CalculateTabularOp(tabVec[tabPos], in_geom.get());
 
  300               line = CalculateTabularOp(tabVec[tabPos], in_geom.get());
 
  306               double perimeter = 0;
 
  307               perimeter = CalculateTabularOp(tabVec[tabPos], in_geom.get());
 
  313 #ifdef TERRALIB_LOGGER_ENABLED 
  314               te::common::Logger::logDebug(
"vp", 
"Geometric Operation - Could not insert the tabular value.");
 
  315 #endif //TERRALIB_LOGGER_ENABLED 
  321     if(geoVec.size() > 0)
 
  323       for(std::size_t geoPos = 0; geoPos < geoVec.size(); ++geoPos)
 
  325         switch(geoVec[geoPos])
 
  330               if(pos < dsType->size())
 
  332                 std::auto_ptr<te::gm::Geometry> convexHull(in_geom->convexHull());
 
  333                 convexHull->setSRID(in_geom->getSRID());
 
  337                   item->
setGeometry(
"convex_hull", convexHull.release());
 
  348               if(pos < dsType->size())
 
  360               if(pos < dsType->size())
 
  362                 std::auto_ptr<te::gm::Geometry> mbr(in_geom->getEnvelope());
 
  363                 mbr->setSRID(in_geom->getSRID());
 
  373   #ifdef TERRALIB_LOGGER_ENABLED 
  374               te::common::Logger::logDebug(
"vp", 
"Geometric Operation - Could not insert the geometric value.");
 
  375   #endif //TERRALIB_LOGGER_ENABLED 
  382       std::auto_ptr<te::gm::Geometry> g(in_geom.release());
 
  385       switch(g->getGeomTypeId())
 
  390               teGeomColl->add(g.release());
 
  396               teGeomColl->add(g.release());
 
  402               teGeomColl->add(g.release());
 
  407 #ifdef TERRALIB_LOGGER_ENABLED 
  408             te::common::Logger::logDebug(
"vp", 
"Geometric Operation - Could not insert the geometry in collection.");
 
  409 #endif //TERRALIB_LOGGER_ENABLED 
  412       if(teGeomColl->getNumGeometries() != 0)
 
  425   return outDSet.release();
 
  430                                                           std::vector<int> tabVec,
 
  431                                                           std::vector<int> geoVec)
 
  436   std::auto_ptr<te::da::DataSet> inDset = m_inDsrc->getDataSet(m_inDsetName);
 
  444   std::auto_ptr<te::gm::Geometry> seedGeom = inDset->getGeometry(geom_pos);
 
  445   int srid = seedGeom->getSRID();
 
  448   if(inDset->size() > 1)
 
  450     while(inDset->moveNext())
 
  452       std::auto_ptr<te::gm::Geometry> c_geom = inDset->getGeometry(geom_pos);
 
  453       if(c_geom->isValid())
 
  454         teGeomColl->
add(c_geom.release());
 
  460     seedGeom.reset(seedGeom->Union(teGeomColl));
 
  461     seedGeom->setSRID(srid);
 
  464   if(tabVec.size() > 0)
 
  466     for(std::size_t tabPos = 0; tabPos < tabVec.size(); ++tabPos)
 
  468       switch(tabVec[tabPos])
 
  473             area = CalculateTabularOp(tabVec[tabPos], seedGeom.get());
 
  480             line = CalculateTabularOp(tabVec[tabPos], seedGeom.get());
 
  486             double perimeter = 0;
 
  487             perimeter = CalculateTabularOp(tabVec[tabPos], seedGeom.get());
 
  493 #ifdef TERRALIB_LOGGER_ENABLED 
  494             te::common::Logger::logDebug(
"vp", 
"Geometric Operation - Could not insert the tabular value.");
 
  495 #endif //TERRALIB_LOGGER_ENABLED 
  501   if(geoVec.size() > 0)
 
  503     for(std::size_t geoPos = 0; geoPos < geoVec.size(); ++geoPos)
 
  505       switch(geoVec[geoPos])
 
  510             if(pos < dsType->size())
 
  512               std::auto_ptr<te::gm::Geometry> convexHull(seedGeom->convexHull());
 
  513               convexHull->setSRID(seedGeom->getSRID());
 
  514               item->
setGeometry(
"convex_hull", convexHull.release());
 
  521             if(pos < dsType->size())
 
  533             if(pos < dsType->size())
 
  535               std::auto_ptr<te::gm::Geometry> mbr(seedGeom->getEnvelope());
 
  536               mbr->setSRID(seedGeom->getSRID());
 
  543 #ifdef TERRALIB_LOGGER_ENABLED 
  544             te::common::Logger::logDebug(
"vp", 
"Geometric Operation - Could not insert the geometry in collection.");
 
  545 #endif //TERRALIB_LOGGER_ENABLED 
  552     std::auto_ptr<te::gm::Geometry> g(seedGeom.release());
 
  555     switch(g->getGeomTypeId())
 
  560             teGeomColl->add(g.release());
 
  566             teGeomColl->add(g.release());
 
  572             teGeomColl->add(g.release());
 
  577 #ifdef TERRALIB_LOGGER_ENABLED 
  578           te::common::Logger::logDebug(
"vp", 
"Geometric Operation - Could not insert the geometry in collection.");
 
  579 #endif //TERRALIB_LOGGER_ENABLED 
  582     if(teGeomColl->getNumGeometries() != 0)
 
  590   return outDSet.release();
 
  594                                                                   std::vector<int> tabVec,
 
  595                                                                   std::vector<int> geoVec)
 
  597   std::map<std::string, te::gm::Geometry*> geometries;
 
  599   std::auto_ptr<te::da::DataSet> inDset = m_inDsrc->getDataSet(m_inDsetName);
 
  606   std::auto_ptr<te::gm::Geometry> seedGeom = inDset->getGeometry(geom_pos);
 
  608   if(inDset->size() > 1)
 
  610     std::map<std::string, std::vector<te::mem::DataSetItem*> > groups;
 
  611     std::map<std::string, std::vector<te::mem::DataSetItem*> >::iterator itg;
 
  612     size_t nprops = inDset->getNumProperties();
 
  615     inDset->moveBeforeFirst();
 
  616     while(inDset->moveNext())
 
  618       std::string key = inDset->getAsString(m_attribute);
 
  620       for(std::size_t j=0; j<nprops; ++j)
 
  622         if (!inDset->isNull(j))
 
  624           std::auto_ptr<te::dt::AbstractData> val = inDset->
getValue(j);
 
  629       itg = groups.find(key);
 
  630       if (itg==groups.end())
 
  632         std::vector<te::mem::DataSetItem*> dataSetItemVector;
 
  633         dataSetItemVector.push_back(item);
 
  634         groups.insert(std::pair<std::string, std::vector<te::mem::DataSetItem*> >(key,dataSetItemVector));
 
  637         itg->second.push_back(item);
 
  640     itg = groups.begin();
 
  641     while(itg != groups.end())
 
  647         geometries.insert(std::pair<std::string, te::gm::Geometry*>(itg->first,geometry));
 
  655     geometries.insert(std::pair<std::string, te::gm::Geometry*>(inDset->getAsString(m_attribute), seedGeom.release()));
 
  660   std::map<std::string, te::gm::Geometry*>::iterator itGeom;
 
  663   itGeom = geometries.begin();
 
  664   while(itGeom != geometries.end())
 
  678           outItem->
setInt16(1, boost::lexical_cast<int>(itGeom->first));
 
  681           outItem->
setInt32(1, boost::lexical_cast<int>(itGeom->first));
 
  684           outItem->
setInt64(1, boost::lexical_cast<int>(itGeom->first));
 
  687           outItem->
setDouble(1, boost::lexical_cast<double>(itGeom->first));
 
  690 #ifdef TERRALIB_LOGGER_ENABLED 
  691         te::common::Logger::logDebug(
"vp", 
"Geometric Operation - Could not insert the aggregated value.");
 
  692 #endif //TERRALIB_LOGGER_ENABLED 
  697     if(tabVec.size() > 0)
 
  699       for(std::size_t tabPos = 0; tabPos < tabVec.size(); ++tabPos)
 
  701         switch(tabVec[tabPos])
 
  706               area = CalculateTabularOp(tabVec[tabPos], itGeom->second);
 
  713               line = CalculateTabularOp(tabVec[tabPos], itGeom->second);
 
  719               double perimeter = 0;
 
  720               perimeter = CalculateTabularOp(tabVec[tabPos], itGeom->second);
 
  721               outItem->
setDouble(
"perimeter", perimeter);
 
  726 #ifdef TERRALIB_LOGGER_ENABLED 
  727               te::common::Logger::logDebug(
"vp", 
"Geometric Operation - Could not insert the tabular value.");
 
  728 #endif //TERRALIB_LOGGER_ENABLED 
  734     if(geoVec.size() > 0)
 
  736       for(std::size_t geoPos = 0; geoPos < geoVec.size(); ++geoPos)
 
  738         switch(geoVec[geoPos])
 
  743               if(pos < dsType->size())
 
  745                 std::auto_ptr<te::gm::Geometry> convexHull(itGeom->second->convexHull());
 
  746                 convexHull->setSRID(seedGeom->getSRID());
 
  747                 outItem->
setGeometry(
"convex_hull", convexHull.release());
 
  754               if(pos < dsType->size())
 
  766               if(pos < dsType->size())
 
  768                 std::auto_ptr<te::gm::Geometry> mbr(itGeom->second->getEnvelope());
 
  769                 mbr->setSRID(seedGeom->getSRID());
 
  776 #ifdef TERRALIB_LOGGER_ENABLED 
  777               te::common::Logger::logDebug(
"vp", 
"Geometric Operation - Could not insert the geometric value.");
 
  778 #endif //TERRALIB_LOGGER_ENABLED 
  787       switch(itGeom->second->getGeomTypeId())
 
  791             if(itGeom->second->isValid())
 
  792               teGeomColl->
add(itGeom->second);
 
  797             if(itGeom->second->isValid())
 
  798               teGeomColl->
add(itGeom->second);
 
  803             if(itGeom->second->isValid())
 
  804               teGeomColl->
add(itGeom->second);
 
  809 #ifdef TERRALIB_LOGGER_ENABLED 
  810             te::common::Logger::logDebug(
"vp", 
"Geometric Operation - Could not insert the geometry in collection.");
 
  811 #endif //TERRALIB_LOGGER_ENABLED 
  820     outDSet->add(outItem);
 
  825   return outDSet.release();
 
  849           if(type == 
"GeometryCollection")
 
  855               std::vector<te::gm::Geometry*> geomVec = m_geoColl->
getGeometries();
 
  856               for(std::size_t i = 0; i < geomVec.size(); ++i)
 
  913           if(type == 
"GeometryCollection")
 
  919               std::vector<te::gm::Geometry*> geomVec = m_geoColl->
getGeometries();
 
  920               for(std::size_t i = 0; i < geomVec.size(); ++i)
 
  950 #ifdef TERRALIB_LOGGER_ENABLED 
  951         te::common::Logger::logDebug(
"vp", 
"Geometric Operation - Could not calculate the operation.");
 
  952 #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. 
 
All objects individually.