27 #include "../common/StringUtils.h"
28 #include "../dataaccess/dataset/ObjectIdSet.h"
29 #include "../dataaccess/dataset/PrimaryKey.h"
30 #include "../dataaccess/datasource/DataSource.h"
31 #include "../dataaccess/datasource/DataSourceCapabilities.h"
32 #include "../dataaccess/query/And.h"
33 #include "../dataaccess/query/DataSetName.h"
34 #include "../dataaccess/query/Expression.h"
35 #include "../dataaccess/query/Field.h"
36 #include "../dataaccess/query/Function.h"
37 #include "../dataaccess/query/FunctionNames.h"
38 #include "../dataaccess/query/FromItem.h"
39 #include "../dataaccess/query/Join.h"
40 #include "../dataaccess/query/LiteralEnvelope.h"
41 #include "../dataaccess/query/PropertyName.h"
42 #include "../dataaccess/query/Select.h"
43 #include "../dataaccess/query/SQLVisitor.h"
44 #include "../dataaccess/query/ST_Intersects.h"
45 #include "../dataaccess/query/ST_EnvelopeIntersects.h"
46 #include "../dataaccess/query/Where.h"
47 #include "../dataaccess/utils/Utils.h"
48 #include "../datatype/Property.h"
49 #include "../geometry/GeometryProperty.h"
55 #include <boost/format.hpp>
75 const std::string& title,
98 for(
size_t i = 0; i < fields->size(); ++i)
105 std::vector<std::string> tokens;
108 assert(tokens.size() == 2);
112 for(
size_t j = 0; j < from->size(); ++j)
139 assert(!name.empty());
141 std::auto_ptr<te::da::DataSetType> input = ds->getDataSetType(name);
151 if(input->getPrimaryKey()->has(pRef))
152 outKey->
add(output->getProperty(p->
getId()));
156 output->setPrimaryKey(outKey);
164 return getData(m_query, travType, accessPolicy);
186 std::auto_ptr<te::da::Select> select(static_cast<te::da::Select*>(m_query->clone()));
229 select->setWhere(wh);
232 return getData(select.get(), travType, accessPolicy);
241 throw Exception(
"Not implemented yet!");
249 std::auto_ptr<te::da::Select> select(static_cast<te::da::Select*>(m_query->clone()));
266 select->setWhere(wh);
269 return getData(select.get(), travType, accessPolicy);
277 std::auto_ptr<te::da::Select> select(static_cast<te::da::Select*>(m_query->clone()));
294 select->setWhere(wh);
297 return getData(select.get(), travType, accessPolicy);
305 if(m_datasourceId.empty())
318 if(ds.get() == 0 || !ds->isValid() || !ds->isOpened())
326 if(m_rendererType.empty())
327 throw Exception((boost::format(
TE_TR(
"Could not draw the query layer %1%. The renderer type is empty!")) % getTitle()).str());
331 if(renderer.get() == 0)
332 throw Exception((boost::format(
TE_TR(
"Could not draw the query layer %1%. The renderer %2% could not be created!")) % getTitle() % m_rendererType).str());
334 renderer->draw(
this, canvas, bbox, srid);
358 m_query->accept(visitor);
378 return m_datasourceId;
388 return m_rendererType;
404 std::auto_ptr<te::da::DataSet> dataset;
407 dataset = ds->query(m_query);
408 assert(dataset.get());
420 return ds->query(query, travType, accessPolicy);
TEDATAACCESSEXPORT DataSourcePtr GetDataSource(const std::string &datasourceId, const bool opened=true)
Search for a data source with the informed id in the DataSourceManager.
const std::string & getName() const
It returns the property name.
void add(te::dt::Property *p)
It adds a property to the list of properties of the primary key.
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...
Spatial intersects operator.
This is the base class for layers.
A class that models the name of a dataset used in a From clause.
boost::shared_ptr< DataSource > DataSourcePtr
A class that models the name of any property of an object.
A class that models the description of a dataset.
static const std::string sm_ST_Intersects
std::auto_ptr< LayerSchema > getSchema() const
It returns the layer schema.
Expression * getExpression() const
It returns the expression set for an output select query.
An abstract factory for layer renderers.
virtual Property * clone() const =0
It returns a clone of the object.
SpatialRelation
Spatial relations between geometric objects.
QueryLayer(AbstractLayer *parent=0)
It initializes a new layer.
A class that represents the known capabilities of a specific data source, i.e. this class informs all...
#define TE_TR(message)
It marks a string in order to get translated.
const QueryCapabilities & getQueryCapabilities() const
void setDatasetName(const std::string &dsName)
It sets the property name.
It models a property definition.
Boolean logic operator: AND.
This is an abstract class that models a query expression.
const std::vector< te::dt::Property * > & getProperties() const
It returns the properties that take part of the primary key.
void setId(unsigned int id)
It sets the property identifier.
AccessPolicy
Supported data access policies (can be used as bitfield).
TraverseType
A dataset can be traversed in two ways:
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.
void setRendererType(const std::string &t)
A class that informs the query support of a given data source.
An operator that considers the intersection among approximations or envelopes of geometries.
An Envelope defines a 2D rectangular region.
const std::string & getAlias() const
It returns the alias associated to the source item.
This class represents a set of unique ids created in the same context. i.e. from the same data set...
boost::ptr_vector< Field > Fields
Fields is just a boost::ptr_vector of Field pointers.
const std::string & getDataSourceId() const
A class that can be used to model a filter expression that can be applied to a query.
static const std::string sm_ST_EnvelopeIntersects
void setExp(Expression *exp)
Sets the expression.
Expression * getExp() const
te::da::Select * getQuery() const
A Join clause combines two FromItems.
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
static AbstractRenderer * make(const std::string &factoryKey)
It creates an object with the appropriated factory.
A Select models a query to be used when retrieving data from a DataSource.
const std::set< std::string > & getSpatialTopologicOperators() const
boost::ptr_vector< FromItem > From
It models the FROM clause for a query.
FromItem * getSecond() const
It returns the second item involved in the join.
std::string getQueryAsString() const
A canvas is an abstraction of a drawing area.
void setDataSourceId(const std::string &id)
void draw(Canvas *canvas, const te::gm::Envelope &bbox, int srid)
It draws the layer geographic objects in the given canvas using the informed SRS. ...
void setQuery(te::da::Select *s)
It describes a primary key (pk) constraint.
A layer resulting from a query.
A class that models a literal for Envelope values.
const std::string & getRendererType() const
const std::string & getName() const
It returns the dataset name.
std::auto_ptr< te::da::DataSet > getData(te::common::TraverseType travType=te::common::FORWARDONLY, const te::common::AccessPolicy accessPolicy=te::common::RAccess) const
It gets the dataset identified by the layer name.
A visitor for building an SQL statement from a given Query hierarchy.
virtual Expression * clone() const =0
It creates a new copy of this expression.
TEDATAACCESSEXPORT std::size_t GetFirstPropertyPos(const te::da::DataSet *dataset, int datatype)
static const std::string sm_type
A static data member used in the implementation of getType method.
const std::string & getType() const
It returns the layer type: QUERY_LAYER.
Expression * getExpression() const
It returns the expression that can be used to retrieve the data set that contains the all indentified...
bool isValid() const
It returns true if the layer can be used for instance to draw, otherwise, it returns false...
unsigned int getId() const
It returns the property identifier.
FromItem * getFirst() const
It returns the first from item involved in the join.