25 #include "../common/StringUtils.h" 27 #include "../core/logger/Logger.h" 28 #include "../core/translator/Translator.h" 30 #include "../dataaccess/dataset/DataSet.h" 31 #include "../dataaccess/dataset/ObjectIdSet.h" 33 #include "../dataaccess/utils/Utils.h" 35 #include "../geometry/Geometry.h" 36 #include "../geometry/GeometryProperty.h" 38 #include "../memory/DataSet.h" 39 #include "../memory/DataSetItem.h" 52 std::vector<te::vp::InputParams> inputParams = mainParams->
getInputParams();
54 if(inputParams.size() < 2)
56 "It is necessary more than one item for performing the operation."));
59 std::unique_ptr<te::da::DataSetType> inputDsType(
60 inputParams[0].m_inputDataSetType);
65 std::unique_ptr<te::da::DataSet> inputDataSet(inputParams[0].m_inputDataSet);
67 std::string inputDsName = inputDsType->getName();
69 std::vector<std::string> tokens;
73 inputDsName = tokens[1];
75 inputDsName = tokens[0];
78 std::unique_ptr<te::da::DataSetType> intersectionDsType(
79 inputParams[1].m_inputDataSetType);
84 std::unique_ptr<te::da::DataSet> intersectionDataSet(
85 inputParams[1].m_inputDataSet);
87 std::string intersectionDsName = intersectionDsType->getName();
93 intersectionDsName = tokens[1];
95 intersectionDsName = tokens[0];
101 std::unique_ptr<te::da::DataSetType> outputDataSetType(
112 const std::map<std::string, te::dt::AbstractData*>& specificParams =
116 std::unique_ptr<te::mem::DataSet> outputDataSet(
120 int inputSRID = inputGeomProp->
getSRID();
121 int intersectionSRID = intersectionGeomProp->
getSRID();
123 std::string intupGeomName = inputGeomProp->
getName();
124 std::string intersectionGeomName = intersectionGeomProp->
getName();
126 intersectionDataSet->moveBeforeFirst();
127 while(intersectionDataSet->moveNext())
131 if (intersectionDataSet->isNull(intersectionGeomName))
134 std::unique_ptr<te::gm::Geometry> g =
135 intersectionDataSet->getGeometry(intersectionGeomName);
140 rtree->insert(*g->getMBR(),
p);
145 TE_LOG_ERROR(
"Vector Processing - Identity - Intersection Layer: " + e.
what());
150 std::vector<std::string> inputPropNames =
151 this->
getPropNames(specificParams, inputDsType->getName());
153 std::vector<std::string> intersectionPropNames =
154 this->
getPropNames(specificParams, intersectionDsType->getName());
156 inputDataSet->moveBeforeFirst();
157 while(inputDataSet->moveNext())
162 std::unique_ptr<te::mem::DataSetItem> item(
166 for(std::size_t p = 0; p < inputPropNames.size(); ++
p)
168 int pos =
static_cast<int>(inputDsType->getPropertyPosition(inputPropNames[p]));
170 if(!inputDataSet->isNull(pos))
172 item->setValue(
"A_" + inputPropNames[p],
173 inputDataSet->getValue(pos).release());
177 if(inputDataSet->isNull(intupGeomName))
181 std::unique_ptr<te::gm::Geometry> inputGeometry =
182 inputDataSet->getGeometry(intupGeomName);
184 if(!inputGeometry->isValid())
189 if(inputSRID != intersectionSRID)
190 inputGeometry->transform(intersectionSRID);
192 std::vector<size_t> report;
193 rtree->search(*inputGeometry->getMBR(), report);
196 if(inputGeometry->getSRID() != inputSRID)
197 inputGeometry->transform(inputSRID);
202 std::vector<te::gm::Geometry*> inputGeomVec;
206 for(std::size_t g = 0; g < inputGeomVec.size(); ++g)
210 std::unique_ptr<te::mem::DataSetItem> currentItem = item->clone();
211 currentItem->setGeometry(geomProp->
getName(), inputGeomVec[g]);
212 outputDataSet->add(currentItem.release());
220 std::vector<te::gm::Geometry*> geomUnionVec;
222 for(
size_t i = 0; i < report.size(); ++i)
224 intersectionDataSet->move(report[i]);
226 std::unique_ptr<te::gm::Geometry> geometry =
227 intersectionDataSet->getGeometry(intersectionGeomName);
229 if(geometry->getSRID() != inputSRID)
230 geometry->transform(inputSRID);
232 std::unique_ptr<te::mem::DataSetItem> intersectionItem = item->clone();
235 for(std::size_t p = 0; p < intersectionPropNames.size(); ++
p)
237 int pos =
static_cast<int>(intersectionDsType->getPropertyPosition(intersectionPropNames[p]));
239 if(!intersectionDataSet->isNull(pos))
241 intersectionItem->setValue(
"B_" + intersectionPropNames[p],
242 intersectionDataSet->getValue(pos).release());
246 geomUnionVec.push_back(
247 dynamic_cast<te::gm::Geometry*>(geometry->clone()));
249 geometry.reset(geometry->intersection(inputGeometry.get()));
250 if(!geometry->isEmpty())
253 std::vector<te::gm::Geometry*> intersectionGeomVec;
257 for(std::size_t g = 0; g < intersectionGeomVec.size(); ++g)
260 intersectionGeomVec[g]->getGeomTypeId())
262 std::unique_ptr<te::mem::DataSetItem> currentItem =
263 intersectionItem->clone();
265 currentItem->setGeometry(geomProp->
getName(),
266 intersectionGeomVec[g]);
268 outputDataSet->add(currentItem.release());
274 std::unique_ptr<te::gm::Geometry> geometryUnion;
275 if(!geomUnionVec.empty())
278 if(geometryUnion.get())
280 if(inputSRID != intersectionSRID)
281 geometryUnion->transform(inputSRID);
283 inputGeometry.reset(inputGeometry->difference(geometryUnion.get()));
286 if(!inputGeometry->isEmpty())
289 std::vector<te::gm::Geometry*> inputGeomVec;
293 for(std::size_t g = 0; g < inputGeomVec.size(); ++g)
295 std::unique_ptr<te::mem::DataSetItem> currentItem = item->clone();
296 currentItem->setGeometry(geomProp->
getName(), inputGeomVec[g]);
297 outputDataSet->add(currentItem.release());
308 std::unique_ptr<te::da::DataSet> dataSetPrepared =
309 PrepareAdd(outputDataSet.release(), outputDataSetType.get());
311 if(!dataSetPrepared.get())
313 TE_TR(
"Output DataSet was not prepared to save."));
315 if(dataSetPrepared->size() == 0)
318 Save(outputDataSource.get(), dataSetPrepared.get(), outputDataSetType.get());
329 const std::map<std::string, te::dt::AbstractData*>& specificParams,
330 const std::string& dataSetName)
332 std::vector<std::string> propNameVec;
334 if(specificParams.empty())
337 std::map<std::string, te::dt::AbstractData*>::const_iterator it =
338 specificParams.find(dataSetName);
340 if(it != specificParams.end())
357 std::vector<te::vp::InputParams> inputParams = mainParams->
getInputParams();
370 outputDataSetType->
add(pkProperty);
382 const std::map<std::string, te::dt::AbstractData*> specificParams =
387 for(std::size_t i = 0; i < inputParams.size(); ++i)
389 if(inputParams[i].m_inputDataSetType)
390 dsType = inputParams[i].m_inputDataSetType;
394 inputParams[i].m_inputDataSource->getId());
408 std::vector<std::string> propNames =
411 for(std::size_t i = 0; i < propNames.size(); ++i)
415 prop->
setName(alias + propNames[i]);
420 outputDataSetType->
add(prop);
431 outputGeomType = inputGeomType;
438 outputDataSetType->
add(newGeomProp);
440 return outputDataSetType;
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.
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.
An atomic property like an integer or double.
boost::shared_ptr< DataSource > DataSourcePtr
A class that represents an R-tree.
A class that models the description of a dataset.
virtual const char * what() const
It outputs the exception message.
TEGEOMEXPORT bool IsMultiType(te::gm::GeomType geomType)
Verifies if the geomType is a collection type.
std::vector< te::vp::InputParams > getInputParams()
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.
bool executeQuery(te::vp::AlgorithmParams *mainParams)
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.
TEVPEXPORT void Save(te::da::DataSource *source, te::da::DataSet *result, te::da::DataSetType *outDsType, const bool &enableProgress=true)
void Tokenize(const std::string &str, std::vector< std::string > &tokens, const std::string &delimiters=" ")
It tokenizes a given string with a delimiter of your own choice.
Implementation of a random-access dataset class for the TerraLib In-Memory Data Access driver...
bool executeMemory(te::vp::AlgorithmParams *mainParams)
void setName(const std::string &name)
It sets the property name.
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.
te::da::DataSourcePtr getOutputDataSource()
const std::map< std::string, te::dt::AbstractData * > & getSpecificParams()
Utility functions for the data access module.
te::da::DataSetType * getOutputDataSetType(te::vp::AlgorithmParams *mainParams)
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
std::vector< std::string > getPropNames(const std::map< std::string, te::dt::AbstractData * > &specificParams, const std::string &dataSetName)
void add(Constraint *c)
It adds a new constraint.
An implementation of the DatasetItem class for the TerraLib In-Memory Data Access driver...
It describes a primary key (pk) constraint.
#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)
TEDATAACCESSEXPORT DataSetType * GetDataSetType(const std::string &name, const std::string &datasourceId)
TEDATAACCESSEXPORT te::gm::GeometryProperty * GetFirstGeomProperty(const DataSetType *dt)
void setPrimaryKey(PrimaryKey *pk)
It sets the primary key constraint.
const std::string & getName() const
It returns the property name.