27 #include "../common/Translator.h"
28 #include "../common/progress/TaskProgress.h"
29 #include "../dataaccess/dataset/PrimaryKey.h"
30 #include "../dataaccess/dataset/DataSet.h"
31 #include "../dataaccess/dataset/DataSetAdapter.h"
32 #include "../dataaccess/dataset/DataSetType.h"
33 #include "../dataaccess/datasource/DataSourceCapabilities.h"
34 #include "../dataaccess/datasource/DataSourceInfo.h"
35 #include "../dataaccess/datasource/DataSourceManager.h"
36 #include "../dataaccess/datasource/DataSourceFactory.h"
37 #include "../dataaccess/dataset/DataSetTypeConverter.h"
38 #include "../dataaccess/query_h.h"
39 #include "../dataaccess/utils/Utils.h"
40 #include "../datatype/Property.h"
41 #include "../datatype/SimpleProperty.h"
42 #include "../datatype/StringProperty.h"
43 #include "../geometry/Geometry.h"
44 #include "../geometry/GeometryCollection.h"
45 #include "../geometry/GeometryProperty.h"
46 #include "../geometry/MultiPolygon.h"
47 #include "../maptools/AbstractLayer.h"
48 #include "../memory/DataSet.h"
49 #include "../memory/DataSetItem.h"
50 #include "../qt/widgets/layer/utils/DataSet2Layer.h"
51 #include "../sam/rtree.h"
65 #include <boost/lexical_cast.hpp>
66 #include <boost/algorithm/string.hpp>
72 const std::string& outputLayerName,
73 const int& bufferBoundariesRule,
74 const bool& copyInputColumns);
78 const double& distance,
79 const int& bufferPolygonRule,
80 const int& bufferBoundariesRule,
81 const bool& copyInputColumns,
89 const std::string& distance,
90 const int& bufferPolygonRule,
91 const int& bufferBoundariesRule,
92 const bool& copyInputColumns,
100 const double& fixedDistance,
101 const int& bufferPolygonRule,
102 const int& bufferBoundariesRule,
103 const bool& copyInputColumns,
111 const std::string& fromAttDistance,
112 const int& bufferPolygonRule,
113 const int& bufferBoundariesRule,
114 const bool& copyInputColumns,
121 const int& bufferPolygonRule,
122 const double& distance,
129 const double& distance);
136 const int& bufferPolygonRule,
137 const int& bufferBoundariesRule,
138 const bool& copyInputColumns,
140 const std::string& outDataSetName,
142 const double& fixedDistance,
143 const std::string& fromAttDistance)
145 assert(inDataSource);
146 assert(outDataSource);
149 std::auto_ptr<te::da::DataSetType> outputDataSetType(
GetDataSetType(inDatasetName, inDataSource, outDataSetName, bufferBoundariesRule, copyInputColumns));
150 std::auto_ptr<te::mem::DataSet> outputDataSet(
new te::mem::DataSet(outputDataSetType.get()));
159 if(fromAttDistance ==
"")
160 res =
BufferQuery(inDatasetName, inDataSource, fixedDistance, bufferPolygonRule, bufferBoundariesRule, copyInputColumns, levels, outputDataSet.get(), outputDataSetType.get(),
te::gm::MultiPolygonType);
162 res =
BufferQuery(inDatasetName, inDataSource, fromAttDistance, bufferPolygonRule, bufferBoundariesRule, copyInputColumns,levels, outputDataSet.get(), outputDataSetType.get(),
te::gm::MultiPolygonType);
166 res =
BufferMemory(inDatasetName, inDataSource, fixedDistance, bufferPolygonRule, bufferBoundariesRule, copyInputColumns, levels, outputDataSet.get(), outputDataSetType.get(),
te::gm::MultiPolygonType);
175 std::auto_ptr<te::da::DataSetAdapter> dsAdapter(
te::da::CreateAdapter(outputDataSet.get(), converter));
177 std::map<std::string, std::string> options;
183 outputDataSet->moveBeforeFirst();
184 outDataSource->
add(dsTypeResult->getName(),outputDataSet.get(), options);
191 const std::string& outputLayerName,
192 const int& bufferBoundariesRule,
193 const bool& copyInputColumns)
200 dsType->
add(pkProperty);
207 dsType->
add(levelProperty);
210 dsType->
add(distanceProperty);
215 boost::ptr_vector<te::dt::Property> props = inDataSource->
getProperties(inDatasetName);
216 boost::ptr_vector<te::dt::Property>::iterator it = props.begin();
218 while(it != props.end())
221 dsType->
add(it->clone());
227 std::auto_ptr<te::da::DataSetType> inputDataSetType = inDataSource->
getDataSetType(inDatasetName);
233 dsType->
add(geometry);
240 const double& distance,
241 const int& bufferPolygonRule,
242 const int& bufferBoundariesRule,
243 const bool& copyInputColumns,
249 std::auto_ptr<te::da::DataSet> inputDataSet = inDataSource->
getDataSet(inDataSetName);
259 inputDataSet->moveBeforeFirst();
260 while(inputDataSet->moveNext())
264 for(
int i = 1; i <= levels; ++i)
268 for(std::size_t j = 0; j < inputDataSet->getNumProperties(); ++j)
270 type = inputDataSet->getPropertyDataType(j);
276 if(inputDataSet->getPropertyName(j) !=
"FID")
277 dataSetItem->
setInt32(j+2, inputDataSet->getInt32(j));
280 dataSetItem->
setInt64(j+2, inputDataSet->getInt64(j));
283 dataSetItem->
setDouble(j+2, inputDataSet->getDouble(j));
286 dataSetItem->
setString(j+2, inputDataSet->getString(j));
293 std::auto_ptr<te::gm::Geometry> currentGeom = inputDataSet->getGeometry(j);
294 std::auto_ptr<te::gm::Geometry> outGeom;
296 if(currentGeom->isValid())
297 outGeom.reset(
SetBuffer(currentGeom.get(), bufferPolygonRule, distance, i, auxGeom));
299 if(outGeom.get() && outGeom->isValid())
308 mPolygon->add(outGeom.release());
312 outputDataSet->
add(dataSetItem);
325 std::auto_ptr<te::gm::Geometry> currentGeom = inputDataSet->getGeometry(j);
326 std::auto_ptr<te::gm::Geometry> outGeom;
328 if(currentGeom->isValid())
329 outGeom.reset(
SetBuffer(currentGeom.get(), bufferPolygonRule, distance, i, auxGeom));
331 if(outGeom.get() && outGeom->isValid())
340 mPolygon->add(outGeom.release());
344 outputDataSet->
add(dataSetItem);
358 std::map<int, std::vector<te::gm::Geometry*> > mapGeom;
367 for(
int i = 1; i <= levels; ++i)
374 level = outputDataSet->
getInt32(levelPos);
379 std::vector<te::gm::Geometry*> vec;
385 for(std::size_t t = 0; t < vec.size(); ++t)
389 geom = geom->
Union(vec[t]);
390 rtree.
remove(*(vec[t]->getMBR()), vec[t]);
399 std::vector<te::gm::Geometry*> geomVec;
400 std::auto_ptr<te::gm::Envelope> e = outputDataSet->
getExtent(geomPos);
401 rtree.
search(*(e.get()), geomVec);
402 mapGeom.insert(std::pair<
int, std::vector<te::gm::Geometry*> >(i, geomVec));
406 outputDataSet->
clear();
412 std::map<int, std::vector<te::gm::Geometry*> >::iterator it = mapGeom.begin();
413 while(it != mapGeom.end())
415 for(std::size_t i = 0; i < it->second.size(); ++i)
419 dataSetItem->
setInt32(1, it->first);
429 mPolygon->add(it->second[i]);
433 outputDataSet->
add(dataSetItem);
446 const std::string& distance,
447 const int& bufferPolygonRule,
448 const int& bufferBoundariesRule,
459 const double& distance,
460 const int& bufferPolygonRule,
461 const int& bufferBoundariesRule,
462 const bool& copyInputColumns,
468 std::auto_ptr<te::da::DataSetType> dsType = inDataSource->
getDataSetType(inDatasetName);
474 std::vector<te::dt::Property*> props = dsType->getProperties();
475 for(std::size_t i=0; i < props.size(); ++i)
480 fields->push_back(f_props);
492 for(
int i=1; i <= levels; ++i)
494 std::stringstream ss;
496 std::string index = ss.str();
529 fields->push_back(f_buffer);
536 fields->push_back(f_buffer);
544 fields->push_back(f_buffer);
551 fields->push_back(f_buffer);
559 from->push_back(fromItem);
562 std::auto_ptr<te::da::DataSet> dsQuery = inDataSource->
query(select);
564 PrepareDataSet(outputDataSetType, dsQuery.get(), outputDataSet, distance);
571 const std::string& distance,
572 const int& bufferPolygonRule,
573 const int& bufferBoundariesRule,
574 const bool& copyInputColumns,
580 std::auto_ptr<te::da::DataSetType> dsType = inDataSource->
getDataSetType(inDatasetName);
584 std::vector<te::dt::Property*> props = dsType->getProperties();
585 for(std::size_t i=0; i < props.size(); ++i)
588 fields->push_back(f_props);
596 for(
int i=1; i <= levels; ++i)
598 std::stringstream ss;
600 std::string index = ss.str();
624 fields->push_back(f_buffer);
631 fields->push_back(f_buffer);
639 fields->push_back(f_buffer);
646 fields->push_back(f_buffer);
654 from->push_back(fromItem);
657 std::auto_ptr<te::da::DataSet> dsQuery = inDataSource->
query(select);
665 const int& bufferPolygonRule,
666 const double& distance,
672 std::auto_ptr<te::gm::Geometry> outGeom;
673 std::auto_ptr<te::gm::Geometry> inGeom;
674 switch(bufferPolygonRule)
679 geomResult = outGeom->
difference(inGeom.get());
682 if(auxGeom && auxGeom->
isValid())
695 if(auxGeom && auxGeom->
isValid())
708 if(auxGeom && auxGeom->
isValid())
722 const double& distance)
726 int numItems = numProps - firstGeomPos;
734 int numCurrentItem = 0;
736 for(
int i = 0; i < numItems; ++i)
740 for(std::size_t j = 0; j < numProps; ++j)
760 dataSetItem->
setDouble(2, distance*(i+1));
762 std::auto_ptr<te::gm::Geometry> geom = dataSetQuery->
getGeometry(j+numCurrentItem);
770 mPolygon->add(geom.release());
774 outputDataSet->
add(dataSetItem);
virtual double getDouble(std::size_t i) const =0
Method for retrieving a double attribute value.
void setGeometryType(GeomType t)
It sets the geometry subtype.
void PrepareDataSet(te::da::DataSetType *dataSetType, te::da::DataSet *dataSetQuery, te::mem::DataSet *outputDataSet, const double &distance)
virtual std::size_t getNumProperties() const =0
It returns the number of properties that composes an item of the dataset.
virtual AbstractData * clone() const =0
It returns a clone of this object.
virtual void createDataSet(DataSetType *dt, const std::map< std::string, std::string > &options)
It creates the dataset schema definition in the target data source.
void setGeometry(std::size_t i, te::gm::Geometry *value)
It sets the value of the i-th property.
A class that models the name of a dataset used in a From clause.
virtual boost::ptr_vector< te::dt::Property > getProperties(const std::string &datasetName)
It retrieves the properties of the dataset.
TEDATAACCESSEXPORT std::size_t GetFirstSpatialPropertyPos(const te::da::DataSet *dataset)
It returns the first dataset spatial property or NULL if none is found.
An atomic property like an integer or double.
std::size_t size() const
It returns the collection size, if it is known.
An converter for DataSetType.
Implementation of a random-access dataset class for the TerraLib In-Memory Data Access driver...
TEDATAACCESSEXPORT te::gm::GeometryProperty * GetFirstGeomProperty(const DataSetType *dt)
virtual const DataSourceCapabilities & getCapabilities() const =0
It returns the known capabilities of the data source.
A Select models a query to be used when retrieving data from a DataSource.
int getSRID() const
It returns the spatial reference system identifier associated to this property.
void setTotalSteps(int value)
Set the task total stepes.
virtual bool intersects(const Geometry *const rhs) const
It returns true if the geometry object spatially intersects rhs geometry.
bool supportsSpatialSQLDialect() const
virtual boost::int32_t getInt32(std::size_t i) const =0
Method for retrieving a 32-bit integer attribute value (4 bytes long).
void add(DataSetItem *item)
It adds a new item to the dataset and takes its ownership.
The Field class can be used to model an expression that takes part of the output items of a SELECT...
std::auto_ptr< te::gm::Geometry > getGeometry(std::size_t i) const
Method for retrieving a geometric attribute value.
virtual std::string getString(std::size_t i) const =0
Method for retrieving a string value attribute.
boost::int32_t getInt32(std::size_t i) const
Method for retrieving a 32-bit integer attribute value (4 bytes long).
virtual bool moveNext()=0
It moves the internal pointer to the next item of the collection.
It describes a primary key (pk) constraint.
boost::ptr_vector< FromItem > From
It models the FROM clause for a query.
const QueryCapabilities & getQueryCapabilities() const
An implementation of the DatasetItem class for the TerraLib In-Memory Data Access driver...
const std::string & getName() const
It returns the property name.
A class that represents an R-tree.
void add(Constraint *c)
It adds a new constraint.
void setInt64(std::size_t i, boost::int64_t value)
It sets the value of the i-th property.
void setInt32(std::size_t i, boost::int32_t value)
It sets the value of the i-th property.
A class that models the name of any property of an object.
A class that represents the known capabilities of a specific data source, i.e. this class informs all...
void setCurrentStep(int value)
Set the task current step.
boost::ptr_vector< Field > Fields
Fields is just a boost::ptr_vector of Field pointers.
virtual Geometry * buffer(const double &distance) const
This method calculates the buffer of a geometry.
virtual bool isValid() const
It tells if the geometry is well formed.
void setPrimaryKey(PrimaryKey *pk)
It sets the primary key constraint.
ST_Union statistical function.
Configuration flags for the Terrralib Vector Processing module.
Spatial difference operator.
An abstract class that models a source of data in a query.
The boundaries between buffers will be dissolved.
bool remove(const te::gm::Envelope &mbr, const DATATYPE &data)
It removes an item from the tree.
Utility functions for the data access module.
The buffer is generated only outside of the polygons.
void setDouble(std::size_t i, double value)
It sets the value of the i-th property.
void pulse()
Calls setCurrentStep() function using getCurrentStep() + 1.
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
void setAutoNumber(bool a)
It tells if the property is an autonumber or not.
virtual int getPropertyDataType(std::size_t i) const =0
It returns the underlying data type of the property at position pos.
GeomType
Each enumerated type is compatible with a Well-known Binary (WKB) type code.
The buffer is generated Inside and outside of the polygons.
virtual Geometry * Union(const Geometry *const rhs) const
It returns a geometric object that represents the point set union with another geometry.
virtual boost::int64_t getInt64(std::size_t i) const =0
Method for retrieving a 64-bit integer attribute value (8 bytes long).
virtual std::auto_ptr< DataSet > query(const Select &q, te::common::TraverseType travType=te::common::FORWARDONLY, const te::common::AccessPolicy accessPolicy=te::common::RAccess)
It executes a query that may return some data using a generic query. This method always returns a dis...
void clear()
It clears all the dataset items.
virtual bool moveBeforeFirst()=0
It moves the internal pointer to a position before the first item in the collection.
void setString(std::size_t i, const std::string &value)
It sets the value of the i-th property.
virtual void add(const std::string &datasetName, DataSet *d, const std::map< std::string, std::string > &options, std::size_t limit=0)
It adds data items to the dataset in the data source.
An exception class for the Vector processing module.
bool supportsPreparedQueryAPI() const
TEDATAACCESSEXPORT std::size_t GetPropertyPos(const DataSet *dataset, const std::string &name)
An abstract class for data providers like a DBMS, Web Services or a regular file. ...
bool BufferQuery(const std::string &inDatasetName, te::da::DataSource *inDataSource, const double &fixedDistance, const int &bufferPolygonRule, const int &bufferBoundariesRule, const bool ©InputColumns, const int &levels, te::mem::DataSet *outputDataSet, te::da::DataSetType *outputDataSetType, te::gm::GeomType outGeoType)
It is a collection of other geometric objects.
A class that models the description of a dataset.
DataSetType * getResult() const
bool moveNext()
It moves the internal pointer to the next item of the collection.
te::da::DataSetType * GetDataSetType(const std::string &inDatasetName, te::da::DataSource *inDataSource, const std::string &outputLayerName, const int &bufferBoundariesRule, const bool ©InputColumns)
void add(te::dt::Property *p)
It adds a property to the list of properties of the primary key.
This is an abstract class that models a query expression.
bool moveBeforeFirst()
It moves the internal pointer to a position before the first item in the collection.
void useTimer(bool flag)
Used to define if task use progress timer information.
bool BufferMemory(const std::string &inDatasetName, te::da::DataSource *inDataSource, const double &distance, const int &bufferPolygonRule, const int &bufferBoundariesRule, const bool ©InputColumns, const int &levels, te::mem::DataSet *outputDataSet, te::da::DataSetType *outputDataSetType, te::gm::GeomType outGeoType)
virtual Geometry * difference(const Geometry *const rhs) const
It returns a geometric object that represents the point set difference with another geometry...
void setMessage(const std::string &message)
Set the task message.
This class can be used to inform the progress of a task.
virtual std::auto_ptr< DataSet > getDataSet(const std::string &name, te::common::TraverseType travType=te::common::FORWARDONLY, const te::common::AccessPolicy accessPolicy=te::common::RAccess)
It gets the dataset identified by the given name. This method always returns a disconnected dataset...
const Envelope * getMBR() const
It returns the minimum bounding rectangle for the geometry in an internal representation.
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.
int search(const te::gm::Envelope &mbr, std::vector< DATATYPE > &report) const
Range search query.
void insert(const te::gm::Envelope &mbr, const DATATYPE &data)
It inserts an item into the tree.
Buffer Vector Processing functions.
virtual std::auto_ptr< te::gm::Geometry > getGeometry(std::size_t i) const =0
Method for retrieving a geometric attribute value.
te::gm::Geometry * SetBuffer(te::gm::Geometry *geom, const int &bufferPolygonRule, const double &distance, const int &level, te::gm::Geometry *&auxGeom)
void setSRID(int srid)
It sets the spatial reference system identifier associated to this property.
A dialog buffer operation.
A dataset is the unit of information manipulated by the data access module of TerraLib.
TEDATAACCESSEXPORT DataSetAdapter * CreateAdapter(DataSet *ds, DataSetTypeConverter *converter, bool isOwner=false)
virtual std::auto_ptr< te::da::DataSetType > getDataSetType(const std::string &name)
It gets information about the given dataset.
TEVPEXPORT bool Buffer(const std::string &inDataset, te::da::DataSource *inDatasource, const int &bufferPolygonRule, const int &bufferBoundariesRule, const bool ©InputColumns, const int &levels, const std::string &outDataset, te::da::DataSource *outDatasource, const double &fixedDistance=0, const std::string &fromAttDistance="")
Executes the Buffer Geographical Operation and persists the result as a dataset in a given output dat...