24 #include "../core/translator/Translator.h" 25 #include "../core/logger/Logger.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" 33 #include "../dataaccess/datasource/DataSource.h" 34 #include "../dataaccess/datasource/DataSourceInfo.h" 35 #include "../dataaccess/datasource/DataSourceInfoManager.h" 36 #include "../dataaccess/datasource/DataSourceCapabilities.h" 37 #include "../dataaccess/datasource/DataSourceTransactor.h" 39 #include "../dataaccess/query/And.h" 40 #include "../dataaccess/query/DataSetName.h" 41 #include "../dataaccess/query/Expression.h" 42 #include "../dataaccess/query/Field.h" 43 #include "../dataaccess/query/Fields.h" 44 #include "../dataaccess/query/From.h" 45 #include "../dataaccess/query/FromItem.h" 46 #include "../dataaccess/query/Insert.h" 47 #include "../dataaccess/query/Join.h" 48 #include "../dataaccess/query/JoinConditionOn.h" 49 #include "../dataaccess/query/PropertyName.h" 50 #include "../dataaccess/query/Select.h" 51 #include "../dataaccess/query/SubSelect.h" 52 #include "../dataaccess/query/ST_Intersection.h" 53 #include "../dataaccess/query/ST_Intersects.h" 54 #include "../dataaccess/query/ST_Multi.h" 55 #include "../dataaccess/query/Where.h" 57 #include "../dataaccess/utils/Utils.h" 59 #include "../datatype/Property.h" 60 #include "../datatype/SimpleData.h" 61 #include "../datatype/StringProperty.h" 63 #include "../geometry/Geometry.h" 64 #include "../geometry/GeometryCollection.h" 65 #include "../geometry/GeometryProperty.h" 66 #include "../geometry/MultiLineString.h" 67 #include "../geometry/MultiPoint.h" 68 #include "../geometry/MultiPolygon.h" 69 #include "../geometry/Utils.h" 73 #include "../memory/DataSet.h" 74 #include "../memory/DataSetItem.h" 76 #include "../statistics/core/Utils.h" 84 #include <boost/lexical_cast.hpp> 97 const std::map<std::string, te::dt::AbstractData*> specificParams = mainParams->
getSpecificParams();
110 std::unique_ptr<te::mem::DataSet> outputDataSet(
new te::mem::DataSet(outputDataSetType.get()));
123 std::unique_ptr<te::gm::Geometry> currentGeometry = firstDataSet->
getGeometry(firstGeometryProperty->
getName());
125 std::vector<std::size_t> rtreeReport;
126 rtree->search(*currentGeometry->getMBR(), rtreeReport);
128 for (std::size_t i = 0; i < rtreeReport.size(); ++i)
130 secondDataSet->
move(rtreeReport[i]);
132 std::unique_ptr<te::gm::Geometry> candidateGeometry = secondDataSet->
getGeometry(secondGeometryProperty->
getName());
134 if (!currentGeometry->intersects(candidateGeometry.get()))
139 if (!resultingGeometry || !resultingGeometry->
isValid())
141 #ifdef TERRALIB_LOGGER_ENABLED 143 #endif //TERRALIB_LOGGER_ENABLED 149 if(!firstDataSet->
isNull(it->second))
150 item->setValue(it->first, firstDataSet->
getValue(it->second).release());
155 if (!secondDataSet->
isNull(it->second))
156 item->setValue(it->first, secondDataSet->
getValue(it->second).release());
159 if (!resultingGeometry->
isEmpty())
161 std::vector<te::gm::Geometry*> geomVec;
164 geomVec.push_back(resultingGeometry);
168 for (std::size_t g = 0; g < geomVec.size(); ++g)
173 std::unique_ptr<te::mem::DataSetItem> currentItem = item->
clone();
174 currentItem->setGeometry(outputGeometryProperty->
getName(), geomVec[g]);
176 outputDataSet->add(currentItem.release());
180 outputDataSet->moveNext();
184 if (!item->isNull(outputDsGeomePropPosition))
185 outputDataSet->add(item.release());
189 outputDataSet->moveBeforeFirst();
191 std::unique_ptr<te::da::DataSet> dataSetPrepared =
PrepareAdd(outputDataSet.release(), outputDataSetType.get());
193 if (!dataSetPrepared.get())
196 if (dataSetPrepared->size() == 0)
199 te::vp::Save(outputDataSource.get(), dataSetPrepared.get(), outputDataSetType.get());
206 std::vector<te::dt::Property*> result;
208 std::vector<std::pair<std::string, std::string> > selectedProperties =
getSelectedProperties(specificParams);
210 for (std::size_t i = 0; i < selectedProperties.size(); ++i)
212 if (selectedProperties[i].first ==
"FIRST")
214 result.push_back(dataSetType->
getProperty(selectedProperties[i].second));
223 std::vector<te::dt::Property*> result;
225 std::vector<std::pair<std::string, std::string> > selectedProperties =
getSelectedProperties(specificParams);
227 for (std::size_t i = 0; i < selectedProperties.size(); ++i)
229 if (selectedProperties[i].first ==
"SECOND")
231 result.push_back(dataSetType->
getProperty(selectedProperties[i].second));
240 std::vector<std::pair<std::string, std::string> > result;
242 for (std::map<std::string, te::dt::AbstractData*>::const_iterator it = specificParams.begin(); it != specificParams.end(); ++it)
244 if (it->first ==
"ATTRIBUTES")
261 for (std::map<std::string, te::dt::AbstractData*>::const_iterator it = specificParams.begin(); it != specificParams.end(); ++it)
263 if (it->first !=
"IS_COLLECTION")
297 std::vector<te::vp::InputParams> inputParams = mainParams->
getInputParams();
299 if (inputParams.size() < 2)
307 if (inputParams.size() == 2)
309 std::string table1 = inputParams[0].m_inputDataSetName;
310 std::string table2 = inputParams[1].m_inputDataSetName;
317 std::unique_ptr<te::da::DataSetType> dsType_first;
318 std::unique_ptr<te::da::DataSetType> dsType_second;
323 dsType_first = inputParams[0].m_inputDataSource->getDataSetType(inputParams[0].m_inputDataSetName);
326 dsType_second = inputParams[1].m_inputDataSource->getDataSetType(inputParams[1].m_inputDataSetName);
337 fields->push_back(f_intersection);
350 from->push_back(join);
356 for (std::size_t i = 2; i < inputParams.size(); ++i)
361 std::unique_ptr<te::da::DataSetType> external_dsType = inputParams[i].m_inputDataSource->getDataSetType(inputParams[i].m_inputDataSetName);
371 external_fields->push_back(f_externalIntersection);
384 externalFrom->push_back(externalJoin);
397 std::unique_ptr<te::da::DataSourceTransactor> t = outputDataSource->getTransactor();
398 std::map<std::string, std::string> options;
403 if (!inDataSourceInfoPtr)
409 if (!outDataSourceInfoPtr)
415 std::string inputConnection = inDataSourceInfoPtr->getConnInfoAsString();
416 std::string outputConnection = outDataSourceInfoPtr->getConnInfoAsString();
419 if (inputConnection == outputConnection)
423 insertFields->push_back(f_insert);
426 inputParams[0].m_inputDataSource->execute(*insert);
430 std::unique_ptr<te::da::DataSet> dsQuery = inputParams[0].m_inputDataSource->query(mainSelect);
431 dsQuery->moveBeforeFirst();
433 if (dsQuery->size() == 0)
438 std::unique_ptr<te::da::DataSetType> outDataSetType(
new te::da::DataSetType(outputDsName));
442 outDataSetType->add(pkProperty);
446 outDataSetType->setPrimaryKey(pk);
452 newGeomProp->setGeometryType(newType);
454 outDataSetType->add(newGeomProp);
456 std::unique_ptr<te::da::DataSet> outDset(
updateGeomType(outDataSetType.get(), dsQuery.release()));
458 outDset->moveBeforeFirst();
460 t->add(outputDsName, outDset.get(), options);
472 std::size_t type = 0;
473 std::vector<te::dt::Property*> props = dsType->
getProperties();
478 std::string propName;
483 for (std::size_t i = 1; i < props.size(); ++i)
485 type =
static_cast<size_t>(props[i]->getType());
486 propName = props[i]->getName();
490 if (!ds->
isNull(propName))
492 std::unique_ptr<te::dt::AbstractData> value = ds->
getValue(propName);
493 dsItem->
setValue(i, value.release());
498 std::unique_ptr<te::gm::Geometry> geom = ds->
getGeometry(propName);
499 std::unique_ptr<te::gm::GeometryProperty> geomProp(static_cast<te::gm::GeometryProperty*>(props[i]->clone()));
510 newGeom->add(geom.release());
523 newGeom->add(geom.release());
536 newGeom->add(geom.release());
555 const std::map<std::string, te::dt::AbstractData*> specificParams = mainParams->
getSpecificParams();
570 std::vector<std::string> attrNamesAux;
576 outputDataSetType->
add(pkProperty);
583 for (std::size_t i = 0; i < firstSelectedProperties.size(); ++i)
587 std::string pName = clonedProperty->
getName();
596 clonedProperty->
setName(pName);
598 outputDataSetType->
add(clonedProperty);
600 attrNamesAux.push_back(clonedProperty->
getName());
603 for (std::size_t i = 0; i < secondSelectedProperties.size(); ++i)
607 std::string pName = clonedProperty->
getName();
616 clonedProperty->
setName(pName);
618 outputDataSetType->
add(clonedProperty);
620 attrNamesAux.push_back(clonedProperty->
getName());
630 outputDataSetType->
add(newGeometryProperty);
632 return outputDataSetType;
bool executeQuery(te::vp::AlgorithmParams *mainParams)
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.
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 setGeometry(std::size_t i, te::gm::Geometry *value)
It sets the value of the i-th property.
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 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.
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.
TEGEOMEXPORT te::gm::GeomType GetMultiType(te::gm::GeomType geomType)
Get the collection type of GeomType.
#define TE_CORE_LOG_DEBUG(channel, message)
Use this tag in order to log a message to a specified logger with the DEBUG level.
virtual Geometry * intersection(const Geometry *const rhs) const _NOEXCEPT_OP(false)
It returns a geometric object that represents the point set intersection with another geometry...
void setValue(std::size_t i, te::dt::AbstractData *value)
It sets the value of the i-th property.
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.
std::map< std::string, std::string > m_firstAttrNameMap
TEVPEXPORT te::sam::rtree::Index< size_t, 8 > * GetRtree(te::da::DataSet *data)
te::da::DataSetType * getOutputDataSetType(te::vp::AlgorithmParams *mainParams)
TEGEOMEXPORT te::gm::GeomType GetSimpleType(te::gm::GeomType geomType)
Get the simple type of GeomType.
static te::dt::Date ds(2010, 01, 01)
std::vector< te::dt::Property * > getFirstSelectedProperties(const te::da::DataSetType *dataSetType, const std::map< std::string, te::dt::AbstractData * > &specificParams)
#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.
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.
std::vector< std::pair< std::string, std::string > > getSelectedProperties(const std::map< std::string, te::dt::AbstractData * > &specificParams)
It models a property definition.
T getValue() const
It returns the associated value.
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.
virtual bool move(std::size_t i)=0
It moves the dataset internal pointer to a given position.
te::da::DataSet * updateGeomType(te::da::DataSetType *dsType, te::da::DataSet *ds)
bool executeMemory(te::vp::AlgorithmParams *mainParams)
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)
Implementation of a random-access dataset class for the TerraLib In-Memory Data Access driver...
void setName(const std::string &name)
It sets the property name.
TEDATAACCESSEXPORT std::size_t GetFirstSpatialPropertyPos(const te::da::DataSet *dataset)
It returns the first dataset spatial property or NULL if none is found.
const std::vector< Property * > & getProperties() const
It returns the list of properties describing the CompositeProperty.
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()
virtual bool isValid() const _NOEXCEPT_OP(false)
It tells if the geometry is well formed.
const std::string & getAlias() const
It returns the alias associated to the source item.
mydialect insert("+", new te::da::BinaryOpEncoder("+"))
virtual bool isEmpty() const _NOEXCEPT_OP(false)
It returns true if this geometric object is the empty Geometry.
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.
virtual AbstractData * clone() const =0
It returns a clone of this object.
te::da::DataSourcePtr getOutputDataSource()
te::gm::GeomType getGeomResultType(const te::gm::GeomType &firstGeom, const te::gm::GeomType &secondGeom, const bool &isCollection)
std::map< std::string, std::string > m_secondAttrNameMap
A Join clause combines two FromItems.
const std::map< std::string, te::dt::AbstractData * > & getSpecificParams()
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.
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.
std::vector< te::dt::Property * > getSecondSelectedProperties(const te::da::DataSetType *dataSetType, const std::map< std::string, te::dt::AbstractData * > &specificParams)
void add(Constraint *c)
It adds a new constraint.
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.
Spatial intersection operator.
It describes a primary key (pk) constraint.
virtual bool moveBeforeFirst()=0
It moves the internal pointer to a position before the first item in the collection.
TEVPEXPORT void ValidateAlgorithmParams(AlgorithmParams *mainParams, Strategy st)
virtual bool isNull(std::size_t i) const =0
It checks if the attribute value is NULL.
JoinConditionOn is a boolean expression and it specifies which items in a join are considered to matc...
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).
A Select can be used as a source of information in another query.
It is a collection of other geometric objects.
TEDATAACCESSEXPORT te::gm::GeometryProperty * GetFirstGeomProperty(const DataSetType *dt)
TEVPEXPORT te::gm::Geometry * SetGeomAsMulti(const te::gm::Geometry &geom)
void setPrimaryKey(PrimaryKey *pk)
It sets the primary key constraint.
boost::shared_ptr< DataSourceInfo > DataSourceInfoPtr
const std::string & getName() const
It returns the property name.