27 #include "../../common/Translator.h"
28 #include "../../geometry/Envelope.h"
29 #include "../../geometry/GeometryProperty.h"
30 #include "../../raster/RasterProperty.h"
31 #include "../dataset/DataSet.h"
32 #include "../dataset/DataSetAdapter.h"
33 #include "../dataset/DataSetType.h"
34 #include "../dataset/DataSetTypeConverter.h"
35 #include "../dataset/ObjectId.h"
36 #include "../dataset/ObjectIdSet.h"
37 #include "../dataset/PrimaryKey.h"
38 #include "../dataset/UniqueKey.h"
39 #include "../datasource/DataSourceInfoManager.h"
40 #include "../datasource/DataSourceManager.h"
41 #include "../query/DataSetName.h"
42 #include "../query/Field.h"
43 #include "../query/Fields.h"
44 #include "../query/LiteralEnvelope.h"
45 #include "../query/LiteralGeom.h"
46 #include "../query/PropertyName.h"
47 #include "../query/ST_Contains.h"
48 #include "../query/ST_Crosses.h"
49 #include "../query/ST_Disjoint.h"
50 #include "../query/ST_Equals.h"
51 #include "../query/ST_Intersects.h"
52 #include "../query/ST_Overlaps.h"
53 #include "../query/ST_Touches.h"
54 #include "../query/ST_Within.h"
55 #include "../query/Where.h"
57 #include "../Exception.h"
64 #include <boost/algorithm/string.hpp>
69 assert(!datasourceId.empty());
74 if(datasource.get() == 0)
77 if(dataset->
size() == 0)
79 boost::ptr_vector<te::dt::Property> properties = datasource->getProperties(dataset->
getName());
81 dataset->
add(properties);
119 assert(!datasourceId.empty());
124 if(datasource.get() == 0)
127 boost::ptr_vector<te::dt::Property> properties = datasource->getProperties(dataset->
getName());
129 dataset->
add(properties);
133 const std::string& propertyName,
134 const std::string& datasourceId)
136 assert(!datasourceId.empty());
141 if(datasource.get() == 0)
142 throw Exception(
TR_DATAACCESS(
"Could not retrieve data source in order to search for a property extent!"));
144 std::auto_ptr<te::gm::Envelope> mbr(datasource->getExtent(datasetName, propertyName));
146 return mbr.release();
151 assert(!datasourceId.empty());
157 datasetNames = ds->getDataSetNames();
189 return "Regular File";
198 assert(!datasourceId.empty());
203 if(datasource.get() == 0)
206 return datasource->hasDataSets();
211 assert(!datasourceId.empty());
216 if(datasource.get() == 0)
219 std::auto_ptr<DataSet> dataset(datasource->getDataSet(name));
221 return dataset.release();
226 assert(!datasourceId.empty());
229 if(datasource.get() == 0)
232 std::auto_ptr<DataSetType> datasettype(datasource->getDataSetType(name));
234 return datasettype.release();
260 assert(!datasourceId.empty());
264 if(datasource.get() == 0)
268 if(dsinfo.get() == 0)
269 throw Exception(
TR_DATAACCESS(
"Could not find data source!"));
273 datasource->setConnectionInfo(dsinfo->getConnInfo());
276 if(opened && !datasource->isOpened())
286 std::vector<size_t> ppos;
287 std::vector<int> ptypes;
288 std::vector<std::string> pnames;
289 std::vector<size_t>::iterator it;
294 for(it=ppos.begin(); it!=ppos.end(); ++it)
297 ptypes.push_back(prop->
getType());
298 pnames.push_back(prop->
getName());
301 for(
size_t i=0; i<ppos.size(); i++)
313 const std::vector<te::dt::Property*>& pkProperties = pk->
getProperties();
315 for(std::size_t i = 0; i < pkProperties.size(); ++i)
316 pnames.push_back(pkProperties[i]->getName());
328 const std::vector<te::dt::Property*>& ukProperties = uk->
getProperties();
330 for(std::size_t j = 0; j < ukProperties.size(); ++j)
331 pnames.push_back(ukProperties[j]->getName());
339 const std::vector<te::dt::Property*>& props = type->
getProperties();
340 for(std::size_t i = 0; i < props.size(); ++i)
347 pnames.push_back(props[i]->getName());
355 std::vector<std::string> oidprops;
358 for(std::size_t i = 0; i < oidprops.size(); ++i)
367 std::vector<std::string> oidprops;
376 assert(!names.empty());
380 for(std::size_t i = 0; i < names.size(); ++i)
383 assert(pos != std::string::npos);
396 assert(!names.empty());
400 for(std::size_t i = 0; i < names.size(); ++i)
415 for(std::size_t i = 0; i != np; ++i)
425 return std::string::npos;
434 for(std::size_t i = 0; i != np; ++i)
444 return std::string::npos;
453 for(std::size_t i = 0; i != np; ++i)
457 if(boost::iequals(pname, name))
461 return std::string::npos;
470 for(std::size_t i = 0; i != np; ++i)
474 if(boost::iequals(pname, name))
478 return std::string::npos;
485 const std::size_t np = dt->
size();
487 for(std::size_t i = 0; i != np; ++i)
546 std::vector<std::string>& pnames,
547 std::vector<int>& ptypes)
551 for(std::size_t i = 0; i != dt->
size(); ++i)
555 pnames.push_back(p->
getName());
556 ptypes.push_back(p->
getType());
561 std::vector<std::string>& pnames,
562 std::vector<int>& ptypes)
575 std::map<std::string, std::string> options;
577 Create(ds, dt, d, options, limit);
583 const std::map<std::string, std::string>& options,
600 const std::vector<AttributeConverter>& funcs = converter->
getConverters();
602 assert((type->
size() == indexes.size()) && (type->
size() == funcs.size()));
606 for(std::size_t i = 0; i < type->
size(); ++i)
619 std::string valueNames(
"(");
621 const std::size_t np = dt->
size();
623 for(std::size_t i = 0; i != np; ++i)
638 std::string valueNames(
"(");
642 for(std::size_t i = 0; i != np; ++i)
657 std::vector<int> properties;
661 for(std::size_t i = 0; i != np; ++i)
674 std::auto_ptr<te::da::Expression> op;
718 std::auto_ptr<Fields> fields(
new Fields);
720 for(std::size_t i = 0; i < properties.size(); ++i)
731 std::auto_ptr<te::da::Select>
te::da::BuildSelect(
const std::string& dsname,
const std::string& propertyName)
733 std::vector<std::string> p;
734 p.push_back(propertyName);
739 std::auto_ptr<te::da::Select>
te::da::BuildSelect(
const std::string& dsname,
const std::vector<std::string>& properties)
742 std::auto_ptr<Fields> fields =
BuildFields(properties);
750 std::auto_ptr<Select> select(
new Select(fields.release(), from));
756 const std::vector<std::string>& properties,
757 const std::string& geometryProperty,
763 std::auto_ptr<Fields> fields =
BuildFields(properties);
766 fields->push_back(
new Field(geometryProperty));
777 std::auto_ptr<Expression> spatialOp =
BuildSpatialOp(geomPropertyName, lenv, r);
783 std::auto_ptr<Select> select(
new Select(fields.release(), from, filter));
789 const std::vector<std::string>& properties,
790 const std::string& geometryProperty,
795 std::auto_ptr<Fields> fields =
BuildFields(properties);
798 fields->push_back(
new Field(geometryProperty));
809 std::auto_ptr<Expression> spatialOp =
BuildSpatialOp(geomPropertyName, lgeom, r);
815 std::auto_ptr<Select> select(
new Select(fields.release(), from, filter));
821 const std::vector<std::string>& properties,
832 std::auto_ptr<Fields> fields =
BuildFields(properties);
836 for(std::size_t i = 0; i < oidsProperties.size(); ++i)
838 const std::string& oidPropertyName = oidsProperties[i];
840 bool alreadyIncluded =
false;
842 for(std::size_t j = 0; j < properties.size(); ++j)
844 if(oidPropertyName == properties[j])
846 alreadyIncluded =
true;
852 fields->push_back(
new Field(oidPropertyName));
858 from->push_back(fromItem);
861 std::auto_ptr<Select> select(
new Select(fields.release(), from, filter));
Spatial overlaps operator.
virtual std::string getPropertyName(std::size_t i) const =0
It returns the property name at position pos.
TEDATAACCESSEXPORT std::auto_ptr< Expression > BuildSpatialOp(Expression *e1, Expression *e2, te::gm::SpatialRelation r)
TEDATAACCESSEXPORT void GetDataSetNames(std::vector< std::string > &datasetNames, const std::string &datasourceId)
TEDATAACCESSEXPORT ObjectIdSet * GenerateOIDSet(DataSet *dataset, const DataSetType *type)
virtual std::size_t getNumProperties() const =0
It returns the number of properties that composes an item of the dataset.
This class represents a set of unique ids created in the same context. i.e. from the same data set...
Spatial Disjoint operator.
virtual void createDataSet(DataSetType *dt, const std::map< std::string, std::string > &options)
It creates the dataset schema definition in the target data source.
A class that models the name of a dataset used in a From clause.
TEDATAACCESSEXPORT std::size_t GetFirstSpatialPropertyPos(const te::da::DataSet *dataset)
It returns the first dataset spatial property or NULL if none is found.
TEDATAACCESSEXPORT te::rst::RasterProperty * GetFirstRasterProperty(const DataSetType *dt)
Property * getProperty(std::size_t i) const
It returns the i-th property.
std::size_t size() const
It returns the number of properties of the CompositeProperty.
TEDATAACCESSEXPORT std::auto_ptr< Fields > BuildFields(const std::vector< std::string > &properties)
TEDATAACCESSEXPORT DataSourcePtr GetDataSource(const std::string &datasourceId, const bool opened=true)
Search for a data source with the informed id in the DataSourceManager.
An converter for DataSetType.
TEDATAACCESSEXPORT te::gm::GeometryProperty * GetFirstGeomProperty(const DataSetType *dt)
A Select models a query to be used when retrieving data from a DataSource.
TEDATAACCESSEXPORT DataSet * GetDataSet(const std::string &name, const std::string &datasourceId)
Spatial intersects operator.
The Field class can be used to model an expression that takes part of the output items of a SELECT...
void addValue(te::dt::AbstractData *data)
It adds a property value to uniquely identify a data set element.
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.
TEDATAACCESSEXPORT void GetEmptyOIDSet(const DataSetType *type, ObjectIdSet *&set)
Returns an empty ObjectIdSet, with the definitions of fields that compose it.
void add(const std::string &newPropertyName, int newPropertyType, const std::vector< std::size_t > &adaptedPropertyPos, AttributeConverter conv)
const std::string & getName() const
It returns the property name.
void add(Constraint *c)
It adds a new constraint.
Expression * getExpression() const
It returns the expression that can be used to retrieve the data set that contains the all indentified...
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.
TEDATAACCESSEXPORT te::gm::Envelope * GetExtent(const std::string &datasetName, const std::string &propertyName, const std::string &datasourceId)
UniqueKey * getUniqueKey(std::size_t i) const
It returns the i-th unique key.
const std::vector< AttributeConverter > & getConverters() const
SpatialRelation
Spatial relations between geometric objects.
const std::vector< te::dt::Property * > & getProperties() const
It returns the properties that take part of the primary key.
TEDATAACCESSEXPORT void GetPropertyInfo(const DataSetType *const dt, std::vector< std::string > &pnames, std::vector< int > &ptypes)
A class that models a literal for Geometry values.
TEDATAACCESSEXPORT te::dt::Property * GetFirstSpatialProperty(const DataSetType *dt)
boost::ptr_vector< Field > Fields
Fields is just a boost::ptr_vector of Field pointers.
const std::vector< std::string > & getPropertyNames() const
It returns the property names used to generated the oids.
An abstract class that models a source of data in a query.
TEDATAACCESSEXPORT ObjectId * GenerateOID(DataSet *dataset, const std::vector< std::string > &names)
Spatial contains operator.
Utility functions for the data access module.
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
TEDATAACCESSEXPORT void GetOIDPropertyPos(const DataSetType *type, std::vector< std::size_t > &ppos)
virtual int getPropertyDataType(std::size_t i) const =0
It returns the underlying data type of the property at position pos.
TEDATAACCESSEXPORT std::size_t GetFirstPropertyPos(const te::da::DataSet *dataset, int datatype)
TEDATAACCESSEXPORT std::vector< int > GetPropertyDataTypes(const te::da::DataSet *dataset)
const std::vector< Property * > & getProperties() const
It returns the list of properties describing the CompositeProperty.
A class that models a literal for Envelope values.
std::size_t getPropertyPosition(const std::string &name) const
It returns the property position based on its name.
It describes a unique key (uk) constraint.
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.
boost::shared_ptr< DataSource > DataSourcePtr
Property * findFirstPropertyOfType(const int t) const
returns the first property of the given data type. Caller doesn't take ownership of the returned poin...
TEDATAACCESSEXPORT DataSetType * GetDataSetType(const std::string &name, const std::string &datasourceId)
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.
This class represents an unique id for a data set element.
#define TR_DATAACCESS(message)
It marks a string in order to get translated. This is a special mark used in the DataAccess module of...
Spatial crosses operator.
TEDATAACCESSEXPORT bool HasDataSet(const std::string &datasourceId)
TEDATAACCESSEXPORT std::auto_ptr< Select > BuildSelect(const std::string &dsname)
TEDATAACCESSEXPORT std::size_t GetPropertyPos(const DataSet *dataset, const std::string &name)
An abstract class for data providers like a DBMS, Web Services or a regular file. ...
A class that models the description of a dataset.
DataSetType * getResult() const
TEDATAACCESSEXPORT int GetPropertyIndex(te::da::DataSet *dataSet, const std::string propName)
TEDATAACCESSEXPORT std::string GetDataSetCategoryName(int category)
TEDATAACCESSEXPORT void Create(DataSource *ds, DataSetType *dt, DataSet *d, std::size_t limit=0)
It creates the dataset definition in a data source and then fill it with data from the input dataset...
It models a property definition.
TEDATAACCESSEXPORT void GetOIDPropertyNames(const DataSetType *type, std::vector< std::string > &pnames)
This is an abstract class that models a query expression.
TEDATAACCESSEXPORT void LoadProperties(te::da::DataSetType *dataset, const std::string &datasourceId)
int getType() const
It returns the property data type.
TEDATAACCESSEXPORT std::string GetSQLValueNames(const DataSetType *dt)
void addProperty(const std::string &name, std::size_t pos, int type)
It adds a property that will be used to generate the unique ids.
static DataSourceManager & getInstance()
It returns a reference to the singleton instance.
TEDATAACCESSEXPORT void LoadFull(te::da::DataSetType *dataset, const std::string &datasourceId)
PrimaryKey * getPrimaryKey() const
It returns the primary key associated to the dataset type.
An Envelope defines a 2D rectangular region.
boost::shared_ptr< DataSourceInfo > DataSourceInfoPtr
A class that can be used to model a filter expression that can be applied to a query.
const std::vector< te::dt::Property * > & getProperties() const
It returns the properties that form the unique key.
const std::vector< std::vector< std::size_t > > & getConvertedPropertyIndexes() const
std::size_t getNumberOfUniqueKeys() const
It returns the number of unique keys defined for the dataset type.
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)
Spatial touches operator.