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"
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/GeometryCollection.h"
41 #include "../geometry/GeometryProperty.h"
42 #include "../geometry/Utils.h"
44 #include "../memory/DataSet.h"
45 #include "../memory/DataSetItem.h"
47 #include "../sam/rtree.h"
60 #include <boost/lexical_cast.hpp>
61 #include <boost/algorithm/string.hpp>
72 std::auto_ptr<te::mem::DataSet> outDSet(
new te::mem::DataSet(outDSType.get()));
77 std::auto_ptr<te::da::DataSet> inDset;
80 inDset = m_inDsrc->getDataSet(m_inDsetName);
82 inDset = m_inDsrc->getDataSet(m_inDsetName, m_oidSet);
84 inDset->moveBeforeFirst();
86 while(inDset->moveNext())
90 for(
int i = 1; i <= m_levels; ++i)
94 for(std::size_t j = 0; j < inDset->getNumProperties(); ++j)
97 if(m_copyInputColumns)
102 if(inDset->getPropertyName(j) !=
"FID")
103 dataSetItem->
setInt32(j+2, inDset->getInt32(j));
106 dataSetItem->
setInt64(j+2, inDset->getInt64(j));
109 dataSetItem->
setDouble(j+2, inDset->getDouble(j));
112 dataSetItem->
setString(j+2, inDset->getString(j));
118 dataSetItem->
setDouble(2, m_distance*(i));
120 std::auto_ptr<te::gm::Geometry> currentGeom = inDset->getGeometry(j);
121 std::auto_ptr<te::gm::Geometry> outGeom;
123 if (currentGeom->isValid())
125 outGeom.reset(setBuffer(currentGeom.get(), m_distance, i, auxGeom));
129 #ifdef TERRALIB_LOGGER_ENABLED
130 te::common::Logger::logDebug(
"vp",
"Buffer - Invalid geometry found");
131 #endif //TERRALIB_LOGGER_ENABLED
134 if(outGeom.get() && outGeom->isValid())
143 mPolygon->add(outGeom.release());
147 outDSet->add(dataSetItem);
154 #ifdef TERRALIB_LOGGER_ENABLED
155 te::common::Logger::logDebug(
"vp",
"Buffer - Type not found.");
156 #endif //TERRALIB_LOGGER_ENABLED
166 dataSetItem->
setDouble(2, m_distance*(i));
168 std::auto_ptr<te::gm::Geometry> currentGeom = inDset->getGeometry(j);
169 std::auto_ptr<te::gm::Geometry> outGeom;
171 if (currentGeom->isValid())
173 outGeom.reset(setBuffer(currentGeom.get(), m_distance, i, auxGeom));
177 #ifdef TERRALIB_LOGGER_ENABLED
178 te::common::Logger::logDebug(
"vp",
"Buffer - Invalid geometry found");
179 #endif //TERRALIB_LOGGER_ENABLED
182 if(outGeom.get() && outGeom->isValid())
191 mPolygon->add(outGeom.release());
195 outDSet->add(dataSetItem);
206 dissolveMemory(outDSet.get(), m_levels);
209 te::vp::Save(m_outDsrc.get(), outDSet.get(), outDSType.get());
215 const double& distance,
221 std::auto_ptr<te::gm::Geometry> outGeom;
222 std::auto_ptr<te::gm::Geometry> inGeom;
223 switch(m_bufferPolygonRule)
229 geomResult = outGeom->
difference(inGeom.get());
232 if (auxGeom && auxGeom->
isValid())
246 if (auxGeom && auxGeom->
isValid())
260 if (auxGeom && auxGeom->
isValid())
270 #ifdef TERRALIB_LOGGER_ENABLED
271 te::common::Logger::logDebug(
"vp",
"Buffer - Polygon rule not found.");
272 #endif //TERRALIB_LOGGER_ENABLED
281 std::vector<std::vector<te::gm::Geometry*> > vecGeom;
290 for(
int i = 1; i <= levels; ++i)
297 level = outDSet->
getInt32(levelPos);
302 std::vector<te::gm::Geometry*> vec;
308 for(std::size_t t = 0; t < vec.size(); ++t)
312 geom = geom->
Union(vec[t]);
313 rtree.
remove(*(vec[t]->getMBR()), vec[t]);
322 std::vector<te::gm::Geometry*> geomVec;
323 std::auto_ptr<te::gm::Envelope> e = outDSet->
getExtent(geomPos);
324 rtree.
search(*(e.get()), geomVec);
326 vecGeom.push_back(geomVec);
336 std::size_t vecSize = vecGeom.size();
342 for(std::size_t i = vecSize - 1; i > 0; --i)
344 std::vector<te::gm::Geometry*> currentVec = vecGeom[i];
345 std::size_t c_vecSize = currentVec.size();
347 for(std::size_t j = 0; j < i; ++j)
349 std::vector<te::gm::Geometry*> innerVec = vecGeom[j];
350 std::size_t i_vecSize = innerVec.size();
352 for(std::size_t k = 0; k < c_vecSize; ++k)
354 for(std::size_t l = 0; l < i_vecSize; ++l)
364 delete currentVec[k];
365 currentVec[k] = tGeom;
366 vecGeom[i] = currentVec;
378 for(std::size_t i = 0; i < vecSize; ++i)
380 std::vector<te::gm::Geometry*> currentVec = vecGeom[i];
381 std::size_t c_vecSize = currentVec.size();
383 for(std::size_t j = 0; j < c_vecSize; ++j)
399 mPolygon->
add(currentVec[j]);
406 outDSet->
add(dataSetItem);
bool remove(const te::gm::Envelope &mbr, const DATATYPE &data)
It removes an item from the tree.
std::auto_ptr< te::gm::Geometry > getGeometry(std::size_t i) const
Method for retrieving a geometric attribute value.
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.
virtual Geometry * buffer(const double &distance) const
This method calculates the buffer of a geometry.
void setDouble(std::size_t i, double value)
It sets the value of the i-th property.
virtual bool intersects(const Geometry *const rhs) const
It returns true if the geometry object spatially intersects rhs geometry.
A class that represents an R-tree.
int getPropertyDataType(std::size_t pos) const
It returns the type of the pos-th property.
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)
te::gm::Geometry * setBuffer(te::gm::Geometry *geom, const double &distance, const int &level, te::gm::Geometry *&auxGeom)
void add(DataSetItem *item)
It adds a new item to the dataset and takes its ownership.
void setInt32(std::size_t i, boost::int32_t value)
It sets the value of the i-th property.
The buffer is generated only outside of the polygons.
Implementation of a random-access dataset class for the TerraLib In-Memory Data Access driver...
boost::int32_t getInt32(std::size_t i) const
Method for retrieving a 32-bit integer attribute value (4 bytes long).
void SplitGeometryCollection(te::gm::GeometryCollection *geomIn, te::gm::GeometryCollection *gcOut)
The buffer is generated only inside of the polygons.
std::auto_ptr< te::gm::Envelope > getExtent(std::size_t i)
It computes the bounding rectangle for a spatial property of the dataset.
virtual bool isValid() const
It tells if the geometry is well formed.
int search(const te::gm::Envelope &mbr, std::vector< DATATYPE > &report) const
Range search query.
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
bool moveBeforeFirst()
It moves the internal pointer to a position before the first item in the collection.
void dissolveMemory(te::mem::DataSet *outDSet, const int &levels)
bool moveNext()
It moves the internal pointer to the next item of the collection.
The buffer is generated Inside and outside of the polygons.
An implementation of the DatasetItem class for the TerraLib In-Memory Data Access driver...
void insert(const te::gm::Envelope &mbr, const DATATYPE &data)
It inserts an item into the tree.
void add(Geometry *g)
It adds the geometry into the collection.
TEDATAACCESSEXPORT DataSetType * GetDataSetType(const std::string &name, const std::string &datasourceId)
void clear()
It clears all the dataset items.
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.
virtual Geometry * Union(const Geometry *const rhs) const
It returns a geometric object that represents the point set union with another geometry.
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 AbstractData * clone() const =0
It returns a clone of this object.
const Envelope * getMBR() const
It returns the minimum bounding rectangle for the geometry in an internal representation.
virtual Geometry * difference(const Geometry *const rhs) const
It returns a geometric object that represents the point set difference with another geometry...
The boundaries between buffers will be dissolved.