24 #include "../core/translator/Translator.h" 25 #include "../core/logger/Logger.h" 26 #include "../common/STLUtils.h" 27 #include "../dataaccess/utils/Utils.h" 28 #include "../datatype/SimpleData.h" 29 #include "../geometry/Geometry.h" 30 #include "../geometry/GeometryProperty.h" 31 #include "../geometry/MultiLineString.h" 32 #include "../geometry/MultiPoint.h" 33 #include "../geometry/MultiPolygon.h" 34 #include "../geometry/Utils.h" 46 std::vector<te::vp::InputParams> inputParams = mainParams->
getInputParams();
62 std::map<std::string, te::dt::AbstractData*> specificParams = mainParams->
getSpecificParams();
68 std::unique_ptr<te::mem::DataSet> outputDataSet(
new te::mem::DataSet(outputDataSetType.get()));
87 if (!firstDs->
isNull(it.second))
88 mainItem->setValue(it.first, firstDs->
getValue(it.second).release());
93 outputDataSet->add(mainItem.release());
97 std::unique_ptr<te::gm::Geometry> firstCurrGeom = firstDs->
getGeometry(firstGeomProp->
getName());
99 if(!firstCurrGeom->isValid())
101 TE_LOG_ERROR(
"Vector Processing - Union - Input layer with invalid geometry.");
106 std::vector<te::gm::Geometry*> vectorToDiff;
108 std::vector<std::size_t> report;
109 rtreeSecond->
search(*firstCurrGeom->getMBR(), report);
111 for (
auto i : report)
118 std::unique_ptr<te::gm::Geometry> secondCurrGeom = secondDs->
getGeometry(secondGeomProp->
getName());
120 if(!secondCurrGeom->isValid())
122 TE_LOG_ERROR(
"Vector Processing - Union - Overlay layer with invalid geometry.");
126 if(firstCurrGeom->intersects(secondCurrGeom.get()) &&
127 !firstCurrGeom->touches(secondCurrGeom.get()))
129 std::unique_ptr<te::gm::Geometry> intersectionGeometry(firstCurrGeom->intersection(secondCurrGeom.get()));
131 if(!intersectionGeometry->isEmpty())
133 vectorToDiff.push_back(static_cast<te::gm::Geometry*>(secondCurrGeom->clone()));
135 std::unique_ptr<te::mem::DataSetItem> clonedItem = mainItem->clone();
139 if (!secondDs->
isNull(it.second))
140 clonedItem->setValue(it.first, secondDs->
getValue(it.second).release());
145 std::vector<te::gm::Geometry*> singleGeometries;
148 for(
auto g : singleGeometries)
152 std::unique_ptr<te::mem::DataSetItem> singleItem = clonedItem->clone();
153 singleItem->setGeometry(outputGeometryProperty->
getName(), g);
154 outputDataSet->add(singleItem.release());
163 if(intersectionGeometry->getGeomTypeId() == outputGeometryProperty->
getGeometryType())
165 clonedItem->setGeometry(outputGeometryProperty->
getName(), intersectionGeometry.release());
166 outputDataSet->add(clonedItem.release());
173 std::unique_ptr<te::gm::Geometry> unionGeometry(
nullptr);
174 if(!vectorToDiff.empty())
180 std::unique_ptr<te::gm::Geometry> differenceGeometry(
nullptr);
181 if(unionGeometry !=
nullptr && !unionGeometry->isEmpty())
182 differenceGeometry.reset(firstCurrGeom->difference(unionGeometry.get()));
184 differenceGeometry.reset(firstCurrGeom.release());
186 if(!differenceGeometry->isEmpty())
190 std::vector<te::gm::Geometry*> singleGeometries;
193 for(
auto g : singleGeometries)
197 std::unique_ptr<te::mem::DataSetItem> singleItem = mainItem->clone();
198 singleItem->setGeometry(outputGeometryProperty->
getName(), g);
199 outputDataSet->add(singleItem.release());
208 if(differenceGeometry->getGeomTypeId() == outputGeometryProperty->
getGeometryType())
210 mainItem->setGeometry(outputGeometryProperty->
getName(), differenceGeometry.release());
211 outputDataSet->add(mainItem.release());
234 if (!secondDs->
isNull(it.second))
235 mainItem->setValue(it.first, secondDs->
getValue(it.second).release());
240 outputDataSet->add(mainItem.release());
244 std::unique_ptr<te::gm::Geometry> secondCurrGeom = secondDs->
getGeometry(secondGeomProp->
getName());
246 if(!secondCurrGeom->isValid())
248 TE_LOG_ERROR(
"Vector Processing - Union - Overlay layer with invalid geometry.");
253 std::vector<te::gm::Geometry*> vectorToDiff;
255 std::vector<std::size_t> report;
256 rtreeFirst->
search(*secondCurrGeom->getMBR(), report);
258 for (
auto i : report)
262 std::unique_ptr<te::gm::Geometry> firstCurrGeom = firstDs->
getGeometry(firstGeomProp->
getName());
264 if(!firstCurrGeom->isValid())
267 if(secondCurrGeom->intersects(firstCurrGeom.get()) &&
268 !secondCurrGeom->touches(firstCurrGeom.get()))
269 vectorToDiff.push_back(static_cast<te::gm::Geometry*>(firstCurrGeom->clone()));
272 std::unique_ptr<te::gm::Geometry> unionGeometry(
nullptr);
273 if(!vectorToDiff.empty())
279 std::unique_ptr<te::gm::Geometry> differenceGeometry(
nullptr);
281 if(unionGeometry !=
nullptr && !unionGeometry->isEmpty())
282 differenceGeometry.reset(secondCurrGeom->difference(unionGeometry.get()));
284 differenceGeometry.reset(secondCurrGeom.release());
286 if(!differenceGeometry->isEmpty())
290 std::vector<te::gm::Geometry*> singleGeometries;
293 for(
auto g : singleGeometries)
295 std::unique_ptr<te::mem::DataSetItem> singleItem = mainItem->clone();
297 singleItem->setGeometry(outputGeometryProperty->
getName(), g);
298 outputDataSet->add(singleItem.release());
306 mainItem->setGeometry(outputGeometryProperty->
getName(), differenceGeometry.release());
307 outputDataSet->add(mainItem.release());
318 outputDataSet->moveBeforeFirst();
320 std::unique_ptr<te::da::DataSet> dataSetPrepared =
PrepareAdd(outputDataSet.release(), outputDataSetType.get());
322 if (!dataSetPrepared.get())
324 TE_TR(
"Output DataSet was not prepared to save."));
326 if (dataSetPrepared->size() == 0)
330 outputDataSetType.get());
336 const std::map<std::string, te::dt::AbstractData*>& specificParams)
340 for(std::map<std::string, te::dt::AbstractData*>::const_iterator it =
341 specificParams.begin();
342 it != specificParams.end(); ++it)
344 if(it->first !=
"IS_COLLECTION")
361 const std::map<std::string, te::dt::AbstractData*>& specificParams)
363 std::map<std::string, te::dt::AbstractData*>::const_iterator it =
364 specificParams.begin();
366 std::vector<std::pair<std::string, std::string> > propNames;
368 while(it != specificParams.end())
370 if(it->first !=
"ATTRIBUTES")
380 std::vector<std::pair<std::string, std::string>
> >*>(abData);
404 const std::map<std::string, te::dt::AbstractData*> specificParams =
419 std::vector<te::dt::Property*> firstSelectedProperties =
422 std::vector<te::dt::Property*> secondSelectedProperties =
428 std::vector<std::string> attrNamesAux;
435 outputDataSetType->
add(pkProperty);
443 for(std::size_t i = 0; i < firstSelectedProperties.size(); ++i)
455 std::string pName = clonedProperty->
getName();
464 clonedProperty->
setName(pName);
466 outputDataSetType->
add(clonedProperty);
468 attrNamesAux.push_back(clonedProperty->
getName());
471 for(std::size_t i = 0; i < secondSelectedProperties.size(); ++i)
483 std::string pName = clonedProperty->
getName();
492 clonedProperty->
setName(pName);
494 outputDataSetType->
add(clonedProperty);
496 attrNamesAux.push_back(clonedProperty->
getName());
509 outputDataSetType->
add(newGeometryProperty);
511 return outputDataSetType;
587 const std::map<std::string, te::dt::AbstractData*>& specificParams)
589 std::vector<te::dt::Property*> result;
591 std::vector<std::pair<std::string, std::string> > selectedProperties =
594 for(std::size_t i = 0; i < selectedProperties.size(); ++i)
596 if(selectedProperties[i].first ==
"FIRST")
598 result.push_back(dataSetType->
getProperty(selectedProperties[i].second));
607 const std::map<std::string, te::dt::AbstractData*>& specificParams)
609 std::vector<te::dt::Property*> result;
611 std::vector<std::pair<std::string, std::string> > selectedProperties =
614 for(std::size_t i = 0; i < selectedProperties.size(); ++i)
616 if(selectedProperties[i].first ==
"SECOND")
618 result.push_back(dataSetType->
getProperty(selectedProperties[i].second));
virtual std::unique_ptr< te::gm::Geometry > getGeometry(std::size_t i) const =0
Method for retrieving a geometric attribute value.
std::vector< te::dt::Property * > getSecondSelectedProperties(const te::da::DataSetType *dataSetType, const std::map< std::string, te::dt::AbstractData * > &specificParams)
void setAutoNumber(bool a)
It tells if the property is an autonumber or not.
std::vector< std::pair< std::string, std::string > > getProperties(const std::map< std::string, te::dt::AbstractData * > &specificParams)
Property * getProperty(std::size_t i) const
It returns the i-th property.
MultiPolygon is a MultiSurface whose elements are Polygons.
bool executeQuery(te::vp::AlgorithmParams *mainParams)
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.
void setSRID(int srid)
It sets the spatial reference system identifier associated to this property.
void setGeometryType(GeomType t)
It sets the geometry subtype.
bool isCollection(const std::map< std::string, te::dt::AbstractData * > &specificParams)
An atomic property like an integer or double.
boost::shared_ptr< DataSource > DataSourcePtr
A class that models the description of a dataset.
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.
std::map< std::string, std::string > m_firstAttrNameMap
std::vector< te::dt::Property * > getFirstSelectedProperties(const te::da::DataSetType *dataSetType, const std::map< std::string, te::dt::AbstractData * > &specificParams)
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.
TEVPEXPORT te::sam::rtree::Index< size_t, 8 > * GetRtree(te::da::DataSet *data)
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.
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.
T getValue() const
It returns the associated value.
virtual bool move(std::size_t i)=0
It moves the dataset internal pointer to a given position.
std::map< std::string, std::string > m_secondAttrNameMap
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.
void setName(const std::string &name)
It sets the property name.
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.
const std::string & getOutputDataSetName()
GeomType getGeometryType() const
It returns the geometry subtype allowed for the property.
A base class for values that can be retrieved from the data access module.
te::da::DataSourcePtr getOutputDataSource()
const std::map< std::string, te::dt::AbstractData * > & getSpecificParams()
int search(const te::gm::Envelope &mbr, std::vector< DATATYPE > &report) const
Range search query.
Utility functions for the data access module.
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.
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.
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.
virtual bool moveBeforeFirst()=0
It moves the internal pointer to a position before the first item in the collection.
void setRequired(bool r)
It tells if the property is required or not.
#define TE_LOG_ERROR(message)
Use this tag in order to log a message to the TerraLib default logger with the ERROR level...
TEVPEXPORT void ValidateAlgorithmParams(AlgorithmParams *mainParams, Strategy st)
bool executeMemory(te::vp::AlgorithmParams *mainParams)
virtual bool isNull(std::size_t i) const =0
It checks if the attribute value is NULL.
TEVPEXPORT std::string GetDistinctName(const std::string &name, std::vector< std::string > names, std::size_t maxSize=0)
A template for atomic data types (integers, floats, strings and others).
te::da::DataSetType * getOutputDataSetType(te::vp::AlgorithmParams *mainParams)
TEDATAACCESSEXPORT te::gm::GeometryProperty * GetFirstGeomProperty(const DataSetType *dt)
void FreeContents(boost::unordered_map< K, V * > &m)
This function can be applied to a map of pointers. It will delete each pointer in the map...
TEVPEXPORT te::gm::Geometry * SetGeomAsMulti(const te::gm::Geometry &geom)
te::gm::GeomType getGeomResultType(const te::gm::GeomType &firstGeom, const te::gm::GeomType &secondGeom, const bool &isCollection)
TEDATAACCESSEXPORT te::dt::Property * GetFirstSpatialProperty(const DataSetType *dt)
void setPrimaryKey(PrimaryKey *pk)
It sets the primary key constraint.
te::gm::Geometry * setGeomAsMulti(te::gm::Geometry *geom)
const std::string & getName() const
It returns the property name.