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"
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/GeometryCollection.h"
42 #include "../geometry/GeometryProperty.h"
43 #include "../geometry/Utils.h"
45 #include "../memory/DataSet.h"
46 #include "../memory/DataSetItem.h"
48 #include "../sam/rtree.h"
61 #include <boost/lexical_cast.hpp>
62 #include <boost/algorithm/string.hpp>
73 std::auto_ptr<te::mem::DataSet> outDSet(
new te::mem::DataSet(outDSType.get()));
78 std::auto_ptr<te::da::DataSet> inDsetSrc;
81 inDsetSrc = m_inDsrc->getDataSet(m_inDsetName);
83 inDsetSrc = m_inDsrc->getDataSet(m_inDsetName, m_oidSet);
85 std::auto_ptr<te::da::DataSetAdapter> inDset(
te::da::CreateAdapter(inDsetSrc.get(), m_converter.get()));
87 inDset->moveBeforeFirst();
89 while(inDset->moveNext())
93 for(
int i = 1; i <= m_levels; ++i)
97 for(std::size_t j = 0; j < inDset->getNumProperties(); ++j)
100 if(m_copyInputColumns)
105 if(inDset->getPropertyName(j) !=
"FID")
106 dataSetItem->
setInt32(j+2, inDset->getInt32(j));
109 dataSetItem->
setInt64(j+2, inDset->getInt64(j));
112 dataSetItem->
setDouble(j+2, inDset->getDouble(j));
115 dataSetItem->
setString(j+2, inDset->getString(j));
121 dataSetItem->
setDouble(2, m_distance*(i));
123 std::auto_ptr<te::gm::Geometry> currentGeom = inDset->getGeometry(j);
124 std::auto_ptr<te::gm::Geometry> outGeom;
126 if (currentGeom->isValid())
128 outGeom.reset(setBuffer(currentGeom.get(), m_distance, i, auxGeom));
132 #ifdef TERRALIB_LOGGER_ENABLED
133 te::common::Logger::logDebug(
"vp",
"Buffer - Invalid geometry found");
134 #endif //TERRALIB_LOGGER_ENABLED
137 if(outGeom.get() && outGeom->isValid())
146 mPolygon->add(outGeom.release());
150 outDSet->add(dataSetItem);
157 #ifdef TERRALIB_LOGGER_ENABLED
158 te::common::Logger::logDebug(
"vp",
"Buffer - Type not found.");
159 #endif //TERRALIB_LOGGER_ENABLED
169 dataSetItem->
setDouble(2, m_distance*(i));
171 std::auto_ptr<te::gm::Geometry> currentGeom = inDset->getGeometry(j);
172 std::auto_ptr<te::gm::Geometry> outGeom;
174 if (currentGeom->isValid())
176 outGeom.reset(setBuffer(currentGeom.get(), m_distance, i, auxGeom));
180 #ifdef TERRALIB_LOGGER_ENABLED
181 te::common::Logger::logDebug(
"vp",
"Buffer - Invalid geometry found");
182 #endif //TERRALIB_LOGGER_ENABLED
185 if(outGeom.get() && outGeom->isValid())
194 mPolygon->add(outGeom.release());
198 outDSet->add(dataSetItem);
209 dissolveMemory(outDSet.get(), m_levels);
212 te::vp::Save(m_outDsrc.get(), outDSet.get(), outDSType.get());
218 const double& distance,
224 std::auto_ptr<te::gm::Geometry> outGeom;
225 std::auto_ptr<te::gm::Geometry> inGeom;
226 switch(m_bufferPolygonRule)
232 geomResult = outGeom->
difference(inGeom.get());
235 if (auxGeom && auxGeom->
isValid())
249 if (auxGeom && auxGeom->
isValid())
263 if (auxGeom && auxGeom->
isValid())
273 #ifdef TERRALIB_LOGGER_ENABLED
274 te::common::Logger::logDebug(
"vp",
"Buffer - Polygon rule not found.");
275 #endif //TERRALIB_LOGGER_ENABLED
284 std::vector<std::vector<te::gm::Geometry*> > vecGeom;
293 for(
int i = 1; i <= levels; ++i)
300 level = outDSet->
getInt32(levelPos);
305 std::vector<te::gm::Geometry*> vec;
311 for(std::size_t t = 0; t < vec.size(); ++t)
315 geom = geom->
Union(vec[t]);
316 rtree.
remove(*(vec[t]->getMBR()), vec[t]);
325 std::vector<te::gm::Geometry*> geomVec;
326 std::auto_ptr<te::gm::Envelope> e = outDSet->
getExtent(geomPos);
327 rtree.
search(*(e.get()), geomVec);
329 vecGeom.push_back(geomVec);
339 std::size_t vecSize = vecGeom.size();
345 for(std::size_t i = vecSize - 1; i > 0; --i)
347 std::vector<te::gm::Geometry*> currentVec = vecGeom[i];
348 std::size_t c_vecSize = currentVec.size();
350 for(std::size_t j = 0; j < i; ++j)
352 std::vector<te::gm::Geometry*> innerVec = vecGeom[j];
353 std::size_t i_vecSize = innerVec.size();
355 for(std::size_t k = 0; k < c_vecSize; ++k)
357 for(std::size_t l = 0; l < i_vecSize; ++l)
367 delete currentVec[k];
368 currentVec[k] = tGeom;
369 vecGeom[i] = currentVec;
381 for(std::size_t i = 0; i < vecSize; ++i)
383 std::vector<te::gm::Geometry*> currentVec = vecGeom[i];
384 std::size_t c_vecSize = currentVec.size();
386 for(
int j = 0; j < c_vecSize; ++j)
402 mPolygon->
add(currentVec[j]);
409 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.
TEDATAACCESSEXPORT DataSetAdapter * CreateAdapter(DataSet *ds, DataSetTypeConverter *converter, bool isOwner=false)
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.