24 #include "../core/logger/Logger.h" 25 #include "../core/translator/Translator.h" 27 #include "../dataaccess/dataset/DataSet.h" 28 #include "../dataaccess/dataset/DataSetAdapter.h" 29 #include "../dataaccess/dataset/DataSetType.h" 30 #include "../dataaccess/dataset/DataSetTypeConverter.h" 31 #include "../dataaccess/dataset/ObjectIdSet.h" 32 #include "../dataaccess/datasource/DataSource.h" 33 #include "../dataaccess/datasource/DataSourceInfo.h" 34 #include "../dataaccess/datasource/DataSourceInfoManager.h" 35 #include "../dataaccess/datasource/DataSourceCapabilities.h" 36 #include "../dataaccess/datasource/DataSourceTransactor.h" 38 #include "../dataaccess/query/And.h" 39 #include "../dataaccess/query/Coalesce.h" 40 #include "../dataaccess/query/DataSetName.h" 41 #include "../dataaccess/query/EqualTo.h" 42 #include "../dataaccess/query/Expression.h" 43 #include "../dataaccess/query/Field.h" 44 #include "../dataaccess/query/Fields.h" 45 #include "../dataaccess/query/From.h" 46 #include "../dataaccess/query/GeometryType.h" 47 #include "../dataaccess/query/Insert.h" 48 #include "../dataaccess/query/LiteralString.h" 49 #include "../dataaccess/query/PropertyName.h" 50 #include "../dataaccess/query/Not.h" 51 #include "../dataaccess/query/Select.h" 52 #include "../dataaccess/query/SelectExpression.h" 53 #include "../dataaccess/query/SubSelect.h" 54 #include "../dataaccess/query/ST_Difference.h" 55 #include "../dataaccess/query/ST_Dump.h" 56 #include "../dataaccess/query/ST_Intersects.h" 57 #include "../dataaccess/query/ST_IsEmpty.h" 58 #include "../dataaccess/query/ST_Multi.h" 59 #include "../dataaccess/query/ST_Union.h" 60 #include "../dataaccess/query/Where.h" 62 #include "../dataaccess/utils/Utils.h" 64 #include "../datatype/Property.h" 65 #include "../datatype/SimpleData.h" 66 #include "../datatype/StringProperty.h" 68 #include "../geometry/Geometry.h" 69 #include "../geometry/GeometryCollection.h" 70 #include "../geometry/GeometryProperty.h" 71 #include "../geometry/MultiLineString.h" 72 #include "../geometry/MultiPoint.h" 73 #include "../geometry/MultiPolygon.h" 74 #include "../geometry/Utils.h" 76 #include "../memory/DataSet.h" 77 #include "../memory/DataSetItem.h" 86 #include <boost/lexical_cast.hpp> 87 #include <boost/uuid/random_generator.hpp> 88 #include <boost/uuid/uuid_io.hpp> 97 std::vector<te::vp::InputParams> inputParams = mainParams->
getInputParams();
99 if(inputParams.size() < 2)
101 "It is necessary more than one item for performing the operation."));
120 std::unique_ptr<te::da::DataSetType> outputDataSetType(
131 const std::map<std::string, te::dt::AbstractData*>& specificParams =
137 std::unique_ptr<te::mem::DataSet> outputDataSet(
141 int inputSRID = inputGeomProp->
getSRID();
142 int differenceSRID = differenceGeomProp->
getSRID();
144 std::string intupGeomName = inputGeomProp->
getName();
145 std::string differenceGeomName = differenceGeomProp->
getName();
148 while(differenceDataSet->
moveNext())
152 if (differenceDataSet->
isNull(differenceGeomName))
155 std::unique_ptr<te::gm::Geometry> g = differenceDataSet->
getGeometry(differenceGeomName);
160 rtree->insert(*g->getMBR(),
p);
171 std::vector<std::string> propNames = this->
getPropNames(specificParams);
177 std::unique_ptr<te::mem::DataSetItem> item(
181 for(std::size_t p = 0; p < propNames.size(); ++
p)
182 item->setValue(propNames[p],
183 inputDataSet->
getValue(propNames[p]).release());
188 std::unique_ptr<te::gm::Geometry> geom =
191 if(!geom.get() || !geom->isValid())
193 TE_LOG_INFO(
"Vector Processing - Difference: Input layer has invalid geometry.");
199 if(inputSRID != differenceSRID)
200 geom->transform(differenceSRID);
202 std::vector<size_t> report;
203 rtree->search(*geom->getMBR(), report);
206 if(geom->getSRID() != inputSRID)
207 geom->transform(inputSRID);
210 std::vector<te::gm::Geometry*> unionVec;
211 std::unique_ptr<te::gm::Geometry> unionGeom;
213 for(
size_t i = 0; i < report.size(); ++i)
215 differenceDataSet->
move(report[i]);
217 std::unique_ptr<te::gm::Geometry> diffGeom =
218 differenceDataSet->
getGeometry(differenceGeomName);
220 if(diffGeom->isValid())
221 unionVec.push_back(diffGeom.release());
228 std::vector<te::gm::Geometry*> geomVec;
231 geomVec.push_back(geom.release());
235 for(std::size_t g = 0; g < geomVec.size(); ++g)
240 std::unique_ptr<te::mem::DataSetItem> currentItem = item->
clone();
241 currentItem->setGeometry(geomProp->
getName(), geomVec[g]);
244 outputDataSet->add(currentItem.release());
252 if(inputSRID != differenceSRID)
253 unionGeom->transform(inputSRID);
255 geom.reset(geom->difference(unionGeom.get()));
260 std::vector<te::gm::Geometry*> geomVec;
263 geomVec.push_back(geom.release());
267 for(std::size_t g = 0; g < geomVec.size(); ++g)
272 std::unique_ptr<te::mem::DataSetItem> currentItem = item->
clone();
273 currentItem->setGeometry(geomProp->
getName(), geomVec[g]);
276 outputDataSet->add(currentItem.release());
280 catch(
const std::exception& e)
282 std::string str =
"Vector Processing - Difference: GEOS Exception - ";
290 std::unique_ptr<te::da::DataSet> dataSetPrepared =
291 PrepareAdd(outputDataSet.release(), outputDataSetType.get());
293 if(!dataSetPrepared.get())
295 TE_TR(
"Output DataSet was not prepared to save."));
297 if(dataSetPrepared->size() == 0)
300 Save(outputDataSource.get(), dataSetPrepared.get(), outputDataSetType.get());
310 std::vector<te::vp::InputParams> inputParams = mainParams->
getInputParams();
312 if(inputParams.size() < 2)
314 "It is necessary more than one item for performing the operation."));
321 std::string aliasInput = dsType_input->
getName();
328 std::string aliasDifference = dsType_difference->
getName();
333 aliasInput = subSelectInput->
getAlias();
338 aliasDifference = subSelectDifference->
getAlias();
346 aliasDifference +
"." + geom_difference->
getName()));
348 fieldsUnion->push_back(f_union);
351 if(!subSelectDifference)
353 TE_TR(
"A problem was found. SubSelect Difference with problem."));
356 fromUnion->push_back(subSelectDifference);
374 subSelectExpression);
379 const std::map<std::string, te::dt::AbstractData*> specificParams =
381 std::vector<std::string> propNames = this->
getPropNames(specificParams);
383 for(std::size_t i = 0; i < propNames.size(); ++i)
386 fieldsExpressions->push_back(f_att);
401 fieldsExpressions->push_back(f_multi);
408 fieldsExpressions->push_back(f_dump);
414 TE_TR(
"A problem was found. SubSelect Input with problem."));
417 fromDifference->push_back(subSelectInput);
426 outerFields->push_back(f_outer);
429 outerFrom->push_back(subSelectIn);
443 inputParams[0].m_inputDataSource->getId());
447 outputDataSource->getId());
450 std::map<std::string, std::string> options;
452 std::unique_ptr<te::da::DataSetType> outputDataSetType(
455 outputDataSource->createDataSet(outputDataSetType.get(), options);
460 std::unique_ptr<te::da::DataSetType> outDt = outSource->getDataSetType(mainParams->
getOutputDataSetName());
464 std::string geometryTypeName = outSource->getGeometryTypeName(outGeomProp->
getGeometryType());
477 if(inDataSourceInfoPtr ==
nullptr)
480 std::string inputConnection = inDataSourceInfoPtr->getConnInfoAsString();
482 std::string outputConnection;
483 if(outDataSourceInfoPtr !=
nullptr)
484 outputConnection = outDataSourceInfoPtr->getConnInfoAsString();
487 if(inputConnection == outputConnection)
491 for(std::size_t
p = 0;
p < propNames.size(); ++
p)
494 insertFields->push_back(f_att);
498 insertFields->push_back(f_insert);
502 insertFields, outerSelect);
504 outputDataSource->execute(*insert);
508 std::unique_ptr<te::da::DataSet> dsQuery =
509 inputParams[0].m_inputDataSource->query(outerSelect);
510 dsQuery->moveBeforeFirst();
512 if(dsQuery->size() == 0)
517 dsQuery->moveBeforeFirst();
519 outputDataSource->add(outputDsName, dsQuery.get(), options);
526 const std::map<std::string, te::dt::AbstractData*>& specificParams)
528 std::vector<std::string> propNames;
530 if(specificParams.empty())
533 std::map<std::string, te::dt::AbstractData*>::const_iterator it =
534 specificParams.begin();
536 while(it != specificParams.end())
538 if(it->first !=
"ATTRIBUTES")
558 const std::map<std::string, te::dt::AbstractData*>& specificParams)
562 std::map<std::string, te::dt::AbstractData*>::const_iterator it =
563 specificParams.begin();
565 while (it != specificParams.end())
567 if (it->first !=
"IS_COLLECTION")
590 std::vector<te::vp::InputParams> inputParams = mainParams->
getInputParams();
603 outputDataSetType->
add(pkProperty);
613 if(inputParams[0].m_inputDataSetType)
615 dsType = inputParams[0].m_inputDataSetType;
620 inputParams[0].m_inputDataSource->getId());
623 const std::map<std::string, te::dt::AbstractData*> specificParams =
625 std::vector<std::string> propNames =
getPropNames(specificParams);
627 for (std::size_t i = 0; i < propNames.size(); ++i)
634 outputDataSetType->
add(prop);
651 outputDataSetType->
add(newGeomProp);
653 return outputDataSetType;
An exception class for the Vector processing module.
virtual std::unique_ptr< te::gm::Geometry > getGeometry(std::size_t i) const =0
Method for retrieving a geometric attribute value.
void setAutoNumber(bool a)
It tells if the property is an autonumber or not.
Property * getProperty(std::size_t i) const
It returns the i-th property.
MultiPolygon is a MultiSurface whose elements are Polygons.
TEVPEXPORT std::unique_ptr< te::da::DataSet > PrepareAdd(te::da::DataSet *ds, te::da::DataSetType *dt)
void add(te::dt::Property *p)
It adds a property to the list of properties of the primary key.
GeomType
Each enumerated type is compatible with a Well-known Binary (WKB) type code.
The Field class can be used to model an expression that takes part of the output items of a SELECT...
void setSRID(int srid)
It sets the spatial reference system identifier associated to this property.
void setGeometryType(GeomType t)
It sets the geometry subtype.
An atomic property like an integer or double.
Spatial intersects operator.
A class that models the name of a dataset used in a From clause.
boost::shared_ptr< DataSource > DataSourcePtr
A class that represents an R-tree.
A class that models the name of any property of an object.
A class that models the description of a dataset.
te::da::DataSetType * getOutputDataSetType(te::vp::AlgorithmParams *mainParams)
TEGEOMEXPORT te::gm::GeomType GetMultiType(te::gm::GeomType geomType)
Get the collection type of GeomType.
virtual const char * what() const
It outputs the exception message.
GeomType getGeomTypeId() const _NOEXCEPT_OP(true)
It returns the geometry subclass type identifier.
TEGEOMEXPORT bool IsMultiType(te::gm::GeomType geomType)
Verifies if the geomType is a collection type.
std::vector< te::vp::InputParams > getInputParams()
T getValue() const
It returns the associated value.
TEGEOMEXPORT std::unique_ptr< te::gm::Geometry > GetGeometryUnion(const std::vector< te::gm::Geometry * > &geomVec)
It returns the union of a geometry vector.
TEGEOMEXPORT te::gm::GeomType GetSimpleType(te::gm::GeomType geomType)
Get the simple type of GeomType.
#define TE_TR(message)
It marks a string in order to get translated.
virtual Property * clone() const =0
It returns a clone of the object.
#define TE_LOG_INFO(message)
Use this tag in order to log a message to the TerraLib default logger with the INFO level...
The Insert object can add the return of a select object.
TEGEOMEXPORT void Multi2Single(const te::gm::Geometry *g, std::vector< te::gm::Geometry * > &geoms)
It will get a GeometryCollection and distribute in a vector.
It models a property definition.
Boolean logic operator: AND.
T getValue() const
It returns the associated value.
This is an abstract class that models a query expression.
virtual bool move(std::size_t i)=0
It moves the dataset internal pointer to a given position.
bool executeQuery(te::vp::AlgorithmParams *mainParams)
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)
Implementation of a random-access dataset class for the TerraLib In-Memory Data Access driver...
int getSRID() const _NOEXCEPT_OP(true)
It returns the Spatial Reference System ID associated to this geometric object.
Spatial is empty operator.
MultiPoint is a GeometryCollection whose elements are restricted to points.
A template for complex data types.
int getSRID() const
It returns the spatial reference system identifier associated to this property.
static DataSourceInfoManager & getInstance()
It returns a reference to the singleton instance.
const std::string & getOutputDataSetName()
const std::string & getAlias() const
It returns the alias associated to the source item.
mydialect insert("+", new te::da::BinaryOpEncoder("+"))
GeomType getGeometryType() const
It returns the geometry subtype allowed for the property.
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.
virtual AbstractData * clone() const =0
It returns a clone of this object.
bool isCollection(const std::map< std::string, te::dt::AbstractData * > &specificParams)
te::da::DataSourcePtr getOutputDataSource()
std::vector< std::string > getPropNames(const std::map< std::string, te::dt::AbstractData * > &specificParams)
const std::map< std::string, te::dt::AbstractData * > & getSpecificParams()
Utility functions for the data access module.
ST_Dump statistical function.
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.
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.
void add(Constraint *c)
It adds a new constraint.
MultiLineString is a MultiCurve whose elements are LineStrings.
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.
A Select can be used as a source of information in another query.
te::gm::GeomType setGeomResultType(const te::gm::GeomType &geomType, const bool &isCollection)
virtual std::unique_ptr< te::dt::AbstractData > getValue(std::size_t i) const
Method for retrieving any other type of data value stored in the data source.
It describes a primary key (pk) constraint.
void add(Geometry *g)
It adds the geometry into the collection.
It models the comparison operator.
virtual bool moveBeforeFirst()=0
It moves the internal pointer to a position before the first item in the collection.
#define TE_LOG_ERROR(message)
Use this tag in order to log a message to the TerraLib default logger with the ERROR level...
bool executeMemory(te::vp::AlgorithmParams *mainParams)
TEVPEXPORT void ValidateAlgorithmParams(AlgorithmParams *mainParams, Strategy st)
ST_Union statistical function.
virtual bool isNull(std::size_t i) const =0
It checks if the attribute value is NULL.
TEDATAACCESSEXPORT DataSetType * GetDataSetType(const std::string &name, const std::string &datasourceId)
A template for atomic data types (integers, floats, strings and others).
A Select can be used as a source of information in another query.
te::gm::Geometry * setGeomAsMulti(te::gm::Geometry *geom)
TEDATAACCESSEXPORT te::gm::GeometryProperty * GetFirstGeomProperty(const DataSetType *dt)
void setPrimaryKey(PrimaryKey *pk)
It sets the primary key constraint.
boost::shared_ptr< DataSourceInfo > DataSourceInfoPtr
This class models a string Literal value.
const std::string & getName() const
It returns the property name.