27 #include "../common/Exception.h"
28 #include "../common/progress/TaskProgress.h"
29 #include "../common/Translator.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/dataset/DataSetTypeConverter.h"
37 #include "../dataaccess/query_h.h"
38 #include "../dataaccess/utils/Utils.h"
39 #include "../datatype/Property.h"
40 #include "../geometry/Geometry.h"
41 #include "../geometry/GeometryCollection.h"
42 #include "../geometry/GeometryProperty.h"
43 #include "../geometry/MultiLineString.h"
44 #include "../geometry/MultiPoint.h"
45 #include "../geometry/MultiPolygon.h"
46 #include "../maptools/AbstractLayer.h"
47 #include "../memory/DataSet.h"
48 #include "../memory/DataSetItem.h"
49 #include "../qt/widgets/layer/utils/DataSet2Layer.h"
56 #include <boost/lexical_cast.hpp>
57 #include <boost/uuid/random_generator.hpp>
58 #include <boost/uuid/uuid_io.hpp>
69 std::vector<te::dt::Property*>
props;
75 const std::string& inSecondDataSetName,
77 const std::string& outDataSetName,
80 const bool& copyInputColumns,
85 const std::string& inSecondDataSetName,
87 const std::string& outDataSetName,
90 const bool& copyInputColumns,
95 std::vector<te::dt::Property*> firstProps,
97 std::vector<te::dt::Property*> secondProps);
104 std::size_t outputSRID = 0);
113 const std::string& inSecondDataSetName,
115 const bool& copyInputColumns,
116 const std::string& outDataSetName,
119 assert(inFirstDataSource);
120 assert(inSecondDataSource);
121 assert(outDataSource);
123 std::pair<te::da::DataSetType*, te::da::DataSet*> resultPair;
124 std::size_t outputSRID = 0;
135 (inFirstDataSource->
getId() == inSecondDataSource->
getId()))
167 std::map<std::string, std::string> options;
173 outDataSource->
add(dsTypeResult->getName(),outDataSet, options);
179 const std::string& inSecondDataSetName,
181 const std::string& outDataSetName,
184 const bool& copyInputColumns,
189 std::auto_ptr<te::da::DataSetType> inDataSetType = inFirstDataSource->
getDataSetType(inFirstDataSetName);
198 std::auto_ptr<te::da::DataSetType> firstDSType(inFirstDataSource->
getDataSetType(inFirstDataSetName));
199 std::auto_ptr<te::da::DataSetType> secondDSType(inFirstDataSource->
getDataSetType(inSecondDataSetName));
202 std::vector<te::dt::Property*> secondProps;
215 for(std::size_t i = 0; i < firstProps.size(); ++i)
217 te::da::Field* f_field =
new te::da::Field(firstTableName +
"." + firstProps[i]->getName() +
" ", firstTableName +
"_" + firstProps[i]->getName());
218 fields->push_back(f_field);
221 for(std::size_t i = 0; i < secondProps.size(); ++i)
223 te::da::Field* f_field =
new te::da::Field(secondTableName +
"." + secondProps[i]->getName() +
" ", secondTableName +
"_" + secondProps[i]->getName());
224 fields->push_back(f_field);
230 fields->push_back(f_intersection);
240 from->push_back(join);
245 std::auto_ptr<te::da::DataSet> dsQuery = inFirstDataSource->
query(select);
246 dsQuery->moveBeforeFirst();
248 outDataSetType =
CreateDataSetType(outDataSetName, firstDSType.get(), firstProps, secondDSType.get(), secondProps);
258 const std::string& inSecondDataSetName,
260 const std::string& outDataSetName,
263 const bool& copyInputColumns,
268 std::auto_ptr<te::da::DataSetType> inDataSetType = inFirstDataSource->
getDataSetType(inFirstDataSetName);
274 std::auto_ptr<te::da::DataSetType> firstDSType(inFirstDataSource->
getDataSetType(inFirstDataSetName));
275 std::auto_ptr<te::da::DataSetType> secondDSType(inSecondDataSource->
getDataSetType(inSecondDataSetName));
280 firstMember.
dt = firstDSType.release();
281 firstMember.ds = inFirstDataSource->
getDataSet(inFirstDataSetName).release();
282 firstMember.props = firstProps;
287 secondMember.
dt = secondDSType.release();
288 secondMember.ds = inSecondDataSource->
getDataSet(inSecondDataSetName).release();
290 secondMember.props = secondProps;
292 std::pair<te::da::DataSetType*, te::da::DataSet*> resultPair;
295 if(resultPair.second->size() < 1)
298 outDataSetType = resultPair.first;
299 outDataSet = resultPair.second;
306 std::vector<te::dt::Property*> firstProps,
308 std::vector<te::dt::Property*> secondProps)
316 outputDt->
add(pkProperty);
322 for(
size_t i = 0; i < firstProps.size(); ++i)
330 for(
size_t i = 0; i < secondProps.size(); ++i)
343 outputDt->
add(newGeomProp);
354 size_t secondDsCount = 0;
357 std::auto_ptr<te::gm::Geometry> g = ds->
getGeometry(secGeomPropPos);
359 rtree->
insert(*g->getMBR(), secondDsCount);
370 std::size_t outputSRID)
387 std::pair<te::da::DataSetType*, te::da::DataSet*> resultPair;
397 std::auto_ptr<te::gm::Geometry> currGeom = firstMember.
ds->
getGeometry(fiGeomPropPos);
399 if(currGeom->getSRID() != outputSRID && outputSRID != 0)
400 currGeom->transform(outputSRID);
402 std::vector<size_t> report;
403 rtree->
search(*currGeom->getMBR(), report);
405 for(
size_t i = 0; i < report.size(); ++i)
407 secondMember.
ds->
move(report[i]);
408 std::auto_ptr<te::gm::Geometry> secGeom = secondMember.
ds->
getGeometry(secGeomPropPos);
410 if(secGeom->getSRID() != outputSRID && outputSRID != 0)
411 secGeom->transform(outputSRID);
413 if(!currGeom->intersects(secGeom.get()))
417 std::auto_ptr<te::gm::Geometry> resultGeom;
419 if(currGeom->isValid() && secGeom->isValid())
420 resultGeom.reset(currGeom->intersection(secGeom.get()));
422 if(resultGeom.get()!=0 && resultGeom->isValid())
435 newGeom->
add(resultGeom.release());
448 newGeom->
add(resultGeom.release());
461 newGeom->
add(resultGeom.release());
471 for(
size_t j = 0; j < firstMember.
props.size(); ++j)
473 std::string name = firstMember.
props[j]->getName();
483 for(
size_t j = 0; j < secondMember.
props.size(); ++j)
485 std::string name = secondMember.
props[j]->getName();
495 item->
setInt32(newName +
"_id", pk);
519 resultPair.first = outputDt;
520 resultPair.second = outputDs;
526 std::vector<te::dt::Property*> props;
529 for(std::size_t i = 0; i < dsType->
getProperties().size(); ++i)
535 props.push_back(prop);
546 std::size_t type = 0;
547 std::vector<te::dt::Property*> props = dsType->
getProperties();
552 std::string propName;
557 for(std::size_t i = 1; i < props.size(); ++i)
559 type = props[i]->getType();
560 propName = props[i]->getName();
564 if (!ds->
isNull(propName))
566 std::auto_ptr<te::dt::AbstractData> value = ds->
getValue(propName);
567 dsItem->
setValue(i, value.release());
572 std::auto_ptr<te::gm::Geometry> geom = ds->
getGeometry(propName);
584 newGeom->add(geom.release());
597 newGeom->add(geom.release());
610 newGeom->add(geom.release());
MultiLineString is a MultiCurve whose elements are LineStrings.
void setGeometryType(GeomType t)
It sets the geometry subtype.
bool isActive() const
Verify if the task is active.
const std::string & getTitle() const
A human descriptive title for the DataSetType.
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
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.
te::gm::GeomType GeomOpResultType(te::gm::GeomType firstGeom, te::gm::GeomType secondGeom)
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.
Property * getProperty(std::size_t i) const
It returns the i-th property.
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.
bool supportsSpatialSQLDialect() const
Spatial intersects operator.
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...
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 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.
virtual bool isNull(std::size_t i) const =0
It checks if the attribute value is NULL.
A class that represents the known capabilities of a specific data source, i.e. this class informs all...
JoinConditionOn is a boolean expression and it specifies which items in a join are considered to matc...
boost::ptr_vector< Field > Fields
Fields is just a boost::ptr_vector of Field pointers.
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
void setValue(std::size_t i, te::dt::AbstractData *value)
It sets the value of the i-th property.
void setName(const std::string &name)
It sets the property name.
TEVPEXPORT bool Intersection(const std::string &inFirstDataSetName, te::da::DataSource *inFirstDataSource, const std::string &inSecondDataSetName, te::da::DataSource *inSecondDataSource, const bool ©InputColumns, const std::string &outDataSetName, te::da::DataSource *outDataSource)
void add(Geometry *g)
It adds the geometry into the collection.
bool IntersectionMemory(const std::string &inFirstDataSetName, te::da::DataSource *inFirstDataSource, const std::string &inSecondDataSetName, te::da::DataSource *inSecondDataSource, const std::string &outDataSetName, te::da::DataSetType *&outDataSetType, te::da::DataSet *&outDataSet, const bool ©InputColumns, size_t outputSRID)
void setPrimaryKey(PrimaryKey *pk)
It sets the primary key constraint.
GeomType getGeometryType() const
It returns the geometry subtype allowed for the property.
Configuration flags for the Terrralib Vector Processing module.
MultiPolygon is a MultiSurface whose elements are Polygons.
An abstract class that models a source of data in a query.
Utility functions for the data access module.
void setFields(Fields *f)
It sets the list of output expressions used to form the result set.
void pulse()
Calls setCurrentStep() function using getCurrentStep() + 1.
void setAutoNumber(bool a)
It tells if the property is an autonumber or not.
std::vector< te::dt::Property * > GetTabularProperties(te::da::DataSetType *dsType)
const std::vector< Property * > & getProperties() const
It returns the list of properties describing the CompositeProperty.
std::size_t getPropertyPosition(const std::string &name) const
It returns the property position based on its name.
virtual std::auto_ptr< te::dt::AbstractData > getValue(std::size_t i) const
Method for retrieving any other type of data value stored in the data source.
GeomType
Each enumerated type is compatible with a Well-known Binary (WKB) type code.
Spatial intersection operator.
Property * findFirstPropertyOfType(const int t) const
returns the first property of the given data type. Caller doesn't take ownership of the returned poin...
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...
virtual bool moveBeforeFirst()=0
It moves the internal pointer to a position before the first item in the collection.
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.
std::string GetSimpleTableName(std::string fullName)
A base class for values that can be retrieved from the data access module.
An abstract class for data providers like a DBMS, Web Services or a regular file. ...
bool isNull(std::size_t i) const
It is a collection of other geometric objects.
A class that models the description of a dataset.
DataSetRTree CreateRTree(te::da::DataSetType *dt, te::da::DataSet *ds)
DataSetType * getResult() const
bool moveNext()
It moves the internal pointer to the next item of the collection.
void add(te::dt::Property *p)
It adds a property to the list of properties of the primary key.
It models a property definition.
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.
std::pair< te::da::DataSetType *, te::da::DataSet * > PairwiseIntersection(std::string newName, IntersectionMember firstMember, IntersectionMember secondMember, std::size_t outputSRID=0)
void useTimer(bool flag)
Used to define if task use progress timer information.
te::da::DataSetType * CreateDataSetType(std::string newName, te::da::DataSetType *firstDt, std::vector< te::dt::Property * > firstProps, te::da::DataSetType *secondDt, std::vector< te::dt::Property * > secondProps)
std::vector< te::dt::Property * > props
MultiPoint is a GeometryCollection whose elements are restricted to points.
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...
virtual std::size_t size() const =0
It returns the collection size, if it is known.
const std::string & getId() const
An identification value for the data source.
te::sam::rtree::Index< size_t, 8 > * DataSetRTree
int search(const te::gm::Envelope &mbr, std::vector< DATATYPE > &report) const
Range search query.
int getType() const
It returns the property data type.
void insert(const te::gm::Envelope &mbr, const DATATYPE &data)
It inserts an item into the tree.
virtual std::auto_ptr< te::gm::Geometry > getGeometry(std::size_t i) const =0
Method for retrieving a geometric attribute value.
void setSRID(int srid)
It sets the spatial reference system identifier associated to this property.
A Join clause combines two FromItems.
bool IntersectionQuery(const std::string &inFirstDataSetName, const std::string &inSecondDataSetName, te::da::DataSource *inFirstDataSource, const std::string &outDataSetName, te::da::DataSetType *&outDataSetType, te::da::DataSet *&outDataSet, const bool ©InputColumns, size_t outputSRID)
virtual Property * clone() const =0
It returns a clone of the object.
virtual bool move(std::size_t i)=0
It moves the dataset internal pointer to a given position.
#define TR_VP(message)
It marks a string in order to get translated. This is a special mark used in the Terrralib Vector Pro...
void setFrom(From *f)
It sets the list of source information.
te::da::DataSet * UpdateGeometryType(te::da::DataSetType *dsType, te::da::DataSet *ds)
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.