28 #include "../common/progress/TaskProgress.h" 29 #include "../core/logger/Logger.h" 30 #include "../core/translator/Translator.h" 32 #include "../dataaccess/dataset/DataSet.h" 33 #include "../dataaccess/dataset/DataSetAdapter.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> 70 std::unique_ptr<te::mem::DataSet> outDSet(
new te::mem::DataSet(outDSType.get()));
76 std::unique_ptr<te::da::DataSet> inDsetSrc;
85 inDset->moveBeforeFirst();
87 while(inDset->moveNext())
93 for(
int level = 1; level <=
m_levels; ++level)
97 for(std::size_t property = 0;
property < inDset->getNumProperties(); ++property)
99 if(inDset->isNull(property))
108 if(inDset->getPropertyName(property) !=
"FID")
109 dataSetItem->
setInt32(property+2, inDset->getInt32(property));
112 dataSetItem->
setInt64(property+2, inDset->getInt64(property));
115 dataSetItem->
setDouble(property+2, inDset->getDouble(property));
118 dataSetItem->
setString(property+2, inDset->getString(property));
122 std::unique_ptr<te::gm::Geometry> currentGeom = inDset->getGeometry(property);
123 std::unique_ptr<te::gm::Geometry> outGeom;
125 if (!currentGeom->isValid())
127 TE_LOG_INFO(
"Vector Processing - Buffer - Invalid geometry found");
132 int sourceSRID = currentGeom->getSRID();
142 dataSetItem->
setDouble(2, distance*(level));
145 outGeom.reset(
setBuffer(currentGeom.get(), distance, level, auxGeom));
159 if(outGeom.get() && outGeom->isValid())
161 outGeom->setSRID(geomProp->
getSRID());
165 dataSetItem->
setGeometry(property+2, outGeom.release());
170 mPolygon->add(outGeom.release());
171 dataSetItem->
setGeometry(property+2, mPolygon.release());
174 outDSet->add(dataSetItem);
182 "Vector Processing - Buffer - The type of input layer " 184 inDset->getPropertyName(property) +
") was not found.");
192 std::unique_ptr<te::gm::Geometry> currentGeom = inDset->getGeometry(property);
193 std::unique_ptr<te::gm::Geometry> outGeom;
195 if (!currentGeom->isValid())
197 TE_LOG_INFO(
"Vector Processing - Buffer - Invalid geometry found");
203 int sourceSRID = currentGeom->getSRID();
213 dataSetItem->
setDouble(2, distance*(level));
216 outGeom.reset(
setBuffer(currentGeom.get(), distance, level, auxGeom));
230 if(outGeom.get() && outGeom->isValid())
232 outGeom->setSRID(geomProp->
getSRID());
241 mPolygon->add(outGeom.release());
245 outDSet->add(dataSetItem);
272 const double& distance,
278 std::unique_ptr<te::gm::Geometry> outGeom;
279 std::unique_ptr<te::gm::Geometry> inGeom;
286 geomResult = outGeom->
difference(inGeom.get());
289 if (auxGeom && auxGeom->
isValid())
303 if (auxGeom && auxGeom->
isValid())
317 if (auxGeom && auxGeom->
isValid())
327 TE_LOG_INFO(
"Vector Processing - Buffer - Polygon rule not found.");
336 std::vector<std::vector<te::gm::Geometry*> > vecGeom;
345 for(
int i = 1; i <= levels; ++i)
352 level = outDSet->
getInt32(levelPos);
355 if (outDSet->
isNull(geomPos))
360 std::vector<te::gm::Geometry*> vec;
366 for(std::size_t t = 0; t < vec.size(); ++t)
370 geom = geom->
Union(vec[t]);
371 rtree.
remove(*(vec[t]->getMBR()), vec[t]);
380 std::vector<te::gm::Geometry*> geomVec;
381 std::unique_ptr<te::gm::Envelope> e = outDSet->
getExtent(geomPos);
382 rtree.
search(*(e.get()), geomVec);
384 vecGeom.push_back(geomVec);
394 std::size_t vecSize = vecGeom.size();
400 for(std::size_t i = vecSize - 1; i > 0; --i)
402 std::vector<te::gm::Geometry*> currentVec = vecGeom[i];
403 std::size_t c_vecSize = currentVec.size();
405 for(std::size_t j = 0; j < i; ++j)
407 std::vector<te::gm::Geometry*> innerVec = vecGeom[j];
408 std::size_t i_vecSize = innerVec.size();
410 for(std::size_t k = 0; k < c_vecSize; ++k)
412 for(std::size_t l = 0; l < i_vecSize; ++l)
422 delete currentVec[k];
423 currentVec[k] = tGeom;
424 vecGeom[i] = currentVec;
436 for (std::size_t i = 0; i < vecSize; ++i)
438 std::vector<te::gm::Geometry*> currentVec = vecGeom[i];
439 int c_vecSize = (
int)currentVec.size();
441 for(
int j = 0; j < c_vecSize; ++j)
463 mPolygon->
add(currentVec[j]);
470 outDSet->
add(dataSetItem);
482 if(dataSet.
isNull(position))
491 distance = (double)dataSet.
getInt16(position);
496 distance = (double)dataSet.
getInt32(position);
500 distance = (double)dataSet.
getInt64(position);
504 distance = (double)dataSet.
getFloat(position);
An exception class for the Vector processing module.
bool remove(const te::gm::Envelope &mbr, const DATATYPE &data)
It removes an item from the tree.
virtual Geometry * difference(const Geometry *const rhs) const _NOEXCEPT_OP(false)
It returns a geometric object that represents the point set difference with another geometry...
Buffer Vector Processing functions.
void setGeometry(std::size_t i, te::gm::Geometry *value)
It sets the value of the i-th property.
virtual double getDouble(std::size_t i) const =0
Method for retrieving a double attribute value.
double m_distance
The fixed distance.
void setDouble(std::size_t i, double value)
It sets the value of the i-th property.
A class that represents an R-tree.
std::unique_ptr< te::gm::Envelope > getExtent(std::size_t i)
It computes the bounding rectangle for a spatial property of the dataset.
int getPropertyDataType(std::size_t pos) const
It returns the type of the pos-th property.
Base exception class for plugin module.
A class that models the description of a dataset.
virtual float getFloat(std::size_t i) const =0
Method for retrieving a float attribute value.
virtual const char * what() const
It outputs the exception message.
virtual Geometry * buffer(const double &distance) const _NOEXCEPT_OP(false)
This method calculates the buffer of a geometry.
const te::da::ObjectIdSet * m_oidSet
The input objectid set.
TEDATAACCESSEXPORT std::size_t GetPropertyPos(const DataSet *dataset, const std::string &name)
double getDistanceByAttribute(te::da::DataSet &dataSet, const int &position)
It returns the distance of buffer by the attribute chosen.
std::unique_ptr< te::da::DataSetTypeConverter > m_converter
The input datasettype.
#define TE_TR(message)
It marks a string in order to get translated.
virtual Geometry * Union(const Geometry *const rhs) const _NOEXCEPT_OP(false)
It returns a geometric object that represents the point set union with another geometry.
virtual bool intersects(const Geometry *const rhs) const _NOEXCEPT_OP(false)
It returns true if the geometry object spatially intersects rhs geometry.
bool isNull(std::size_t i) const
It checks if the attribute value is NULL.
#define TE_LOG_INFO(message)
Use this tag in order to log a message to the TerraLib default logger with the INFO level...
te::gm::Geometry * setBuffer(te::gm::Geometry *geom, const double &distance, const int &level, te::gm::Geometry *&auxGeom)
It executes the buffer operator.
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.
TEVPEXPORT void Save(te::da::DataSource *source, te::da::DataSet *result, te::da::DataSetType *outDsType, const bool &enableProgress=true)
The buffer is generated only outside of the polygons.
Implementation of a random-access dataset class for the TerraLib In-Memory Data Access driver...
int m_bufferPolygonRule
The buffer polygon rule (INSIDE_OUTSIDE = 0, ONLY_OUTSIDE = 1, ONLY_INSIDE = 2).
const std::vector< Property * > & getProperties() const
It returns the list of properties describing the CompositeProperty.
int m_levels
The number of levels buffer will have.
virtual boost::int16_t getInt16(std::size_t i) const =0
Method for retrieving a 16-bit integer attribute value (2 bytes long).
int getSRID() const
It returns the spatial reference system identifier associated to this property.
const Envelope * getMBR() const _NOEXCEPT_OP(true)
It returns the minimum bounding rectangle for the geometry in an internal representation.
virtual int getPropertyDataType(std::size_t i) const =0
It returns the underlying data type of the property at position pos.
boost::int32_t getInt32(std::size_t i) const
Method for retrieving a 32-bit integer attribute value (4 bytes long).
virtual bool isValid() const _NOEXCEPT_OP(false)
It tells if the geometry is well formed.
TEVPEXPORT void SplitGeometryCollection(te::gm::GeometryCollection *geomIn, te::gm::GeometryCollection *gcOut)
te::da::DataSetType * GetDataSetType()
It builds the output DataSetType.
int m_bufferBoundariesRule
The buffer boundary rule (DISSOLVE = 0 and NOT_DISSOLVE = 1).
std::unique_ptr< te::gm::Geometry > getGeometry(std::size_t i) const
Method for retrieving a geometric attribute value.
The buffer is generated only inside of the polygons.
virtual boost::int32_t getInt32(std::size_t i) const =0
Method for retrieving a 32-bit integer attribute value (4 bytes long).
virtual AbstractData * clone() const =0
It returns a clone of this object.
~BufferMemory()
Destructor.
int search(const te::gm::Envelope &mbr, std::vector< DATATYPE > &report) const
Range search query.
Utility functions for the data access module.
bool run()
It executes the operation.
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
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)
It dissolves the bounders between buffers.
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...
A dataset is the unit of information manipulated by the data access module of TerraLib.
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.
BufferMemory()
Default constructor.
Configuration flags for the Terrralib Vector Processing module.
#define TE_LOG_ERROR(message)
Use this tag in order to log a message to the TerraLib default logger with the ERROR level...
int m_attributePosition
The buffer can be calculated by attribute values. The attribute must be numeric type.
bool m_copyInputColumns
Copy columns from input DataSet.
virtual bool isNull(std::size_t i) const =0
It checks if the attribute value is NULL.
void clear()
It clears all the dataset items.
virtual boost::int64_t getInt64(std::size_t i) const =0
Method for retrieving a 64-bit integer attribute value (8 bytes long).
te::da::DataSourcePtr m_inDsrc
The input datasource.
void setString(std::size_t i, const std::string &value)
It sets the value of the i-th property.
te::da::DataSourcePtr m_outDsrc
The output datasource.
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 te::gm::GeometryProperty * GetFirstGeomProperty(const DataSetType *dt)
TEDATAACCESSEXPORT DataSetAdapter * CreateAdapter(DataSet *ds, DataSetTypeConverter *converter, bool isOwner=false)
std::string m_inDsetName
The input dataset name.
int m_newSRID
A new SRID if it's necessary to transform the data.
The boundaries between buffers will be dissolved.