28 #include "../core/logger/Logger.h" 29 #include "../core/translator/Translator.h" 31 #include "../dataaccess/dataset/DataSet.h" 32 #include "../dataaccess/dataset/DataSetAdapter.h" 33 #include "../dataaccess/dataset/DataSetTypeConverter.h" 35 #include "../datatype/Property.h" 36 #include "../datatype/SimpleProperty.h" 37 #include "../datatype/StringProperty.h" 39 #include "../dataaccess/dataset/ObjectIdSet.h" 40 #include "../dataaccess/query/And.h" 41 #include "../dataaccess/query/Cast.h" 42 #include "../dataaccess/query/DataSetName.h" 43 #include "../dataaccess/query/Expression.h" 44 #include "../dataaccess/query/Field.h" 45 #include "../dataaccess/query/Fields.h" 46 #include "../dataaccess/query/From.h" 47 #include "../dataaccess/query/FromItem.h" 48 #include "../dataaccess/query/IsNull.h" 49 #include "../dataaccess/query/LiteralDouble.h" 50 #include "../dataaccess/query/LiteralInt32.h" 51 #include "../dataaccess/query/Not.h" 52 #include "../dataaccess/query/NotEqualTo.h" 53 #include "../dataaccess/query/Or.h" 54 #include "../dataaccess/query/PropertyName.h" 55 #include "../dataaccess/query/Select.h" 56 #include "../dataaccess/query/ST_Buffer.h" 57 #include "../dataaccess/query/ST_Difference.h" 58 #include "../dataaccess/query/ST_Transform.h" 59 #include "../dataaccess/query/Where.h" 60 #include "../dataaccess/utils/Utils.h" 62 #include "../geometry/Geometry.h" 63 #include "../geometry/GeometryCollection.h" 64 #include "../geometry/GeometryProperty.h" 65 #include "../geometry/Utils.h" 67 #include "../memory/DataSet.h" 68 #include "../memory/DataSetItem.h" 70 #include "../sam/rtree.h" 84 #include <boost/lexical_cast.hpp> 85 #include <boost/algorithm/string.hpp> 95 std::vector<te::dt::Property*> props =
m_converter->getResult()->getProperties();
99 for(std::size_t i=0; i < props.size(); ++i)
104 fields->push_back(f_props);
110 int sourceSRID = geom->
getSRID();
121 std::stringstream ss;
123 std::string index = ss.str();
134 e_distance =
new te::da::PropertyName(distancePropName +
"*" + boost::lexical_cast<std::string>(i));
140 distancePropName +
"*" + boost::lexical_cast<std::string>(i));
143 "-" + distancePropName +
"*" + boost::lexical_cast<std::string>(i));
149 distancePropName +
"*" + boost::lexical_cast<std::string>(i));
152 "-" + distancePropName +
"*" + boost::lexical_cast<std::string>(i));
182 e_distance =
new te::da::PropertyName(distancePropName +
"*" + boost::lexical_cast<std::string>(i));
187 distancePropName +
"*" + boost::lexical_cast<std::string>(i));
193 distancePropName +
"*" + boost::lexical_cast<std::string>(i));
221 e_distance =
new te::da::PropertyName(distancePropName +
"*" + boost::lexical_cast<std::string>(i));
225 "-" + distancePropName +
"*" + boost::lexical_cast<std::string>(i));
229 "-" + distancePropName +
"*" + boost::lexical_cast<std::string>(i));
255 fields->push_back(f_buffer);
262 fields->push_back(f_buffer);
266 fields->push_back(f_distance);
271 from->push_back(fromItem);
304 std::unique_ptr<te::da::DataSet> dsQuery =
m_inDsrc->query(select);
307 std::unique_ptr<te::mem::DataSet> outDSet(
new te::mem::DataSet(outDSType.get()));
311 std::vector<std::vector<te::gm::Geometry*> > vecDissolvedGeom =
dissolveQuery(dsQuery.get(),
m_levels);
321 int layerSRID = geomPropertyLayer->
getSRID();
336 std::vector<std::vector<te::gm::Geometry*> > vecGeom;
338 for(
int i = 0; i < levels*2; ++i)
350 std::vector<te::gm::Geometry*> vec;
356 for(std::size_t t = 0; t < vec.size(); ++t)
360 geom = geom->
Union(vec[t]);
361 rtree.
remove(*(vec[t]->getMBR()), vec[t]);
368 std::vector<te::gm::Geometry*> geomVec;
369 std::unique_ptr<te::gm::Envelope> e = dsQuery->
getExtent(i);
370 rtree.
search(*(e.get()), geomVec);
371 vecGeom.push_back(geomVec);
377 std::size_t vecSize = vecGeom.size();
381 for(std::size_t i = vecSize - 1; i > 0; --i)
383 std::vector<te::gm::Geometry*> currentVec = vecGeom[i];
384 std::size_t c_vecSize = currentVec.size();
386 for(std::size_t j = 0; j < i; ++j)
388 std::vector<te::gm::Geometry*> innerVec = vecGeom[j];
389 std::size_t i_vecSize = innerVec.size();
391 for(std::size_t k = 0; k < c_vecSize; ++k)
393 for(std::size_t l = 0; l < i_vecSize; ++l)
403 delete currentVec[k];
404 currentVec[k] = tGeom;
405 vecGeom[i] = currentVec;
419 const int& sourceSRID)
423 int numItems = (
int)numProps - (
int)firstGeomPos;
433 for(
int i = 0; i < numItems; ++i)
437 for(std::size_t j = 0; j < numProps; ++j)
441 if(dataSetQuery->
isNull(j))
467 switch (typeDistance){
469 distance = (double)dataSetQuery->
getInt32(j+i+1);
473 distance = (double)dataSetQuery->
getInt64(j+i+1);
478 std::string strDistance = dataSetQuery->
getNumeric(j+i+1);
479 distance = boost::lexical_cast<
double>(strDistance);
484 distance = dataSetQuery->
getDouble(j+i+1);
492 std::unique_ptr<te::gm::Geometry> geom = dataSetQuery->
getGeometry(j+i);
496 if(geom->getSRID() != sourceSRID)
497 geom->transform(sourceSRID);
506 mPolygon->add(geom.release());
510 outputDataSet->
add(dataSetItem);
521 TE_LOG_INFO(
"Vector Processing - Buffer - Type not found.");
531 const int& sourceSRID,
532 const double& distance)
536 for(std::size_t i = 0; i < vecDissolvedGeom.size(); ++i)
538 std::vector<te::gm::Geometry*> vecGeom = vecDissolvedGeom[i];
539 std::size_t sizeVecGeom = vecGeom.size();
541 for(std::size_t j=0; j < sizeVecGeom; ++j)
546 dataSetItem->
setDouble(2, distance*((
int)i+1));
548 std::unique_ptr<te::gm::Geometry> geom(vecGeom[j]);
550 if(geom->getSRID() != sourceSRID)
551 geom->transform(sourceSRID);
560 mPolygon->add(geom.release());
564 outputDataSet->
add(dataSetItem);
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 std::unique_ptr< te::gm::Geometry > getGeometry(std::size_t i) const =0
Method for retrieving a geometric attribute value.
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...
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.
An abstract class that models a source of data in a query.
The Field class can be used to model an expression that takes part of the output items of a SELECT...
void setDouble(std::size_t i, double value)
It sets the value of the i-th property.
A class that models the name of a dataset used in a From clause.
TEDATAACCESSEXPORT void AssociateDataSetTypeConverterSRID(DataSetTypeConverter *converter, const int &inputSRID, const int &outputSRID=TE_UNKNOWN_SRS)
A class that represents an R-tree.
A class that models the name of any property of an object.
Base exception class for plugin module.
A class that models the description of a dataset.
virtual std::string getNumeric(std::size_t i) const =0
Method for retrieving a numeric attribute value.
const te::da::ObjectIdSet * m_oidSet
The input objectid set.
DataSetType * getResult() const
std::vector< std::vector< te::gm::Geometry * > > dissolveQuery(te::da::DataSet *dsQuery, const int &levels)
It dissolves the bounders between buffers.
~BufferQuery()
Destructor.
Buffer Vector Processing functions.
std::unique_ptr< te::da::DataSetTypeConverter > m_converter
The input datasettype.
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.
#define TE_LOG_INFO(message)
Use this tag in order to log a message to the TerraLib default logger with the INFO level...
Boolean logic operator: AND.
void setNumeric(std::size_t i, const std::string &value)
It sets the value of the i-th property.
This is an abstract class that models a query expression.
void add(DataSetItem *item)
It adds a new item to the dataset and takes its ownership.
An converter for DataSetType.
void setInt32(std::size_t i, boost::int32_t value)
It sets the value of the i-th property.
virtual bool moveNext()=0
It moves the internal pointer to the next item of the collection.
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).
TEDATAACCESSEXPORT std::size_t GetFirstSpatialPropertyPos(const te::da::DataSet *dataset)
It returns the first dataset spatial property or NULL if none is found.
int m_levels
The number of levels buffer will have.
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.
virtual bool isValid() const _NOEXCEPT_OP(false)
It tells if the geometry is well formed.
te::da::DataSetType * GetDataSetType()
It builds the output DataSetType.
int m_bufferBoundariesRule
The buffer boundary rule (DISSOLVE = 0 and NOT_DISSOLVE = 1).
Tells if two values are not equal.
virtual boost::int32_t getInt32(std::size_t i) const =0
Method for retrieving a 32-bit integer attribute value (4 bytes long).
boost::ptr_vector< Field > Fields
Fields is just a boost::ptr_vector of Field pointers.
Spatial difference operator.
A class that can be used to model a filter expression that can be applied to a query.
BufferQuery()
Default constructor.
Tells if a value is NULL.
A class that models a literal for double values.
int search(const te::gm::Envelope &mbr, std::vector< DATATYPE > &report) const
Range search query.
Utility functions for the data access module.
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
A Select models a query to be used when retrieving data from a DataSource.
boost::ptr_vector< FromItem > From
It models the FROM clause for a query.
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.
bool run()
It executes the operation.
void insert(const te::gm::Envelope &mbr, const DATATYPE &data)
It inserts an item into the tree.
virtual bool moveBeforeFirst()=0
It moves the internal pointer to a position before the first item in the collection.
Configuration flags for the Terrralib Vector Processing module.
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.
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.
virtual std::size_t getNumProperties() const =0
It returns the number of properties that composes an item of the dataset.
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)
virtual std::unique_ptr< te::gm::Envelope > getExtent(std::size_t i)=0
It computes the bounding rectangle for a spatial property of the dataset.
Expression * getExpression() const
It returns the expression that can be used to retrieve the data set that contains the all indentified...
void prepareDataSet(te::da::DataSet *dataSetQuery, te::mem::DataSet *outputDataSet, const int &sourceSRID)
It prepare the dataset to be persisted.
virtual std::string getString(std::size_t i) const =0
Method for retrieving a string value attribute.
int m_newSRID
A new SRID if it's necessary to transform the data.
The boundaries between buffers will be dissolved.
const std::string & getName() const
It returns the property name.