27 #include "../../common/Translator.h"
28 #include "../../geometry/Utils.h"
29 #include "../../srs/Config.h"
30 #include "../dataset/DataSet.h"
31 #include "../dataset/FilteredDataSet.h"
32 #include "../datasource/DataSourceTransactor.h"
33 #include "../datasource/DataSourceCapabilities.h"
34 #include "../utils/Utils.h"
35 #include "../Exception.h"
72 std::auto_ptr<DataSourceTransactor> t = ds->getTransactor();
74 return getDataSet(t.get(),
capabilities, q, travType,
false);
87 return t->
query(q, travType, connected);
92 if(supportsSpatialTopologicOperatos(capabilities, restrictions))
93 return t->
query(q, travType, connected);
96 std::auto_ptr<ObjectIdSet> oids = getOIDSet(t, q);
100 throw(Exception(
TE_TR(
"The query result is empty.")));
103 std::string datasetName = getDataSetName(q);
104 assert(!datasetName.empty());
106 return t->
getDataSet(datasetName, oids.get(), travType, connected);
115 std::auto_ptr<DataSourceTransactor> t = ds->getTransactor();
125 std::string datasetName = getDataSetName(q);
126 assert(!datasetName.empty());
136 if(!srv.hasSpatialRestrictions() && supportsSpatialTopologicOperatos(capabilities, srv.getSpatialRestrictions()))
140 assert(dataset.get());
143 std::auto_ptr<ObjectIdSet> oids(
GenerateOIDSet(dataset.get(), type.get()));
151 assert(from->size() == 1);
152 assert(!from->is_null(0));
160 baseSelect.
setFields(fields->clone().release());
161 baseSelect.
setFrom(from->clone().release());
167 const std::vector<SpatialRestriction*>& restrictions = srv.getSpatialRestrictions();
174 std::vector<te::gm::Geometry*> geomRestrictions;
175 for(std::size_t i = 0; i < restrictions.size(); ++i)
176 geomRestrictions.push_back(restrictions[i]->m_geometry);
178 for(std::size_t i = 0; i < restrictions.size(); ++i)
179 oids->
Union(getOIDSet(t, baseSelect, attrRestrictions, restrictions[i], type.get(), geomRestrictions));
181 return std::auto_ptr<te::da::ObjectIdSet>(oids);
189 std::string datasetName = getDataSetName(q);
190 assert(!datasetName.empty());
200 assert(srv.hasSpatialRestrictions());
205 assert(from->size() == 1);
206 assert(!from->is_null(0));
214 baseSelect.
setFields(fields->clone().release());
215 baseSelect.
setFrom(from->clone().release());
221 const std::vector<SpatialRestriction*>& restrictions = srv.getSpatialRestrictions();
228 std::vector<te::gm::Geometry*> geomRestrictions;
229 for(std::size_t i = 0; i < restrictions.size(); ++i)
230 geomRestrictions.push_back(restrictions[i]->m_geometry);
232 for(std::size_t i = 0; i < restrictions.size(); ++i)
233 oids->
Union(getOIDSet(t, baseSelect, attrRestrictions, restrictions[i], type.get(), geomRestrictions));
235 return std::auto_ptr<te::da::ObjectIdSet>(oids);
240 const std::vector<te::gm::Geometry*>& geomRestrictions)
248 assert(geomRestriction);
260 if(attrRestrictions == 0)
267 assert(dataset.get());
275 const std::vector<std::string>& pnames = oids->getPropertyNames();
277 while(dataset->moveNext())
279 std::auto_ptr<te::gm::Geometry> currentGeom(0);
282 currentGeom = dataset->getGeometry(restriction->
m_pname);
283 if(currentGeom.get() == 0)
286 catch(std::exception& )
291 assert(currentGeom.get());
293 bool equalsToRestriction =
false;
294 for(std::size_t i = 0; i < geomRestrictions.size(); ++i)
296 if(currentGeom->equals(geomRestrictions[i]))
298 equalsToRestriction =
true;
303 if(equalsToRestriction)
320 for(std::size_t i = 0; i < restrictions.size(); ++i)
334 const std::vector<SpatialRestriction*>& restrictions)
const
338 for(std::size_t i = 0; i < restrictions.size(); ++i)
344 if(ops.find(fname) == ops.end())
358 assert(from->size() == 1);
359 assert(!from->is_null(0));
377 if(attrRestrictions.size() == 1)
378 return attrRestrictions[0]->m_function->clone();
380 assert(attrRestrictions.size() >= 2);
383 And* andOp =
new And(attrRestrictions[0]->m_function->clone(), attrRestrictions[1]->m_function->clone());
385 for(std::size_t i = 2; i < attrRestrictions.size(); ++i)
387 And* nextAndOp =
new And(result, attrRestrictions[i]->m_function->clone());
A visitor for retrieves spatial restrictions from a Query hierarchy.
virtual ~SpatialQueryProcessor()
Virtual destructor.
te::gm::SpatialRelation m_type
The spatial restriction type.
int getSRID() const
It returns the Spatial Reference System ID associated to this geometric object.
An abstract class that models a source of data in a query.
A visitor that retrieves spatial restrictions from a Query hierarchy.
TEDATAACCESSEXPORT void GetEmptyOIDSet(const DataSetType *type, ObjectIdSet *&set)
Returns an empty ObjectIdSet, with the definitions of fields that compose it.
virtual std::auto_ptr< ObjectIdSet > getOIDSet(const DataSourcePtr &ds, const Select &q)
Expression * getAttrRestrictions(const Select &q) const
TEDATAACCESSEXPORT ObjectId * GenerateOID(DataSet *dataset, const std::vector< std::string > &names)
const std::vector< te::da::SpatialRestriction * > & getSpatialRestrictions() const
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 name of any property of an object.
SpatialQueryProcessor()
Constructor.
A class that models the description of a dataset.
bool supportsSpatialTopologicOperatos(const QueryCapabilities &capabilities, const std::vector< SpatialRestriction * > &restrictions) const
TEGEOMEXPORT bool SatisfySpatialRelation(const Geometry *g1, const Geometry *g2, SpatialRelation relation)
It returns if two geometries satisfy a given spatial relation.
A class that models the name of a dataset used in a From clause.
bool hasSpatialRestrictions() const
#define TE_TR(message)
It marks a string in order to get translated.
const QueryCapabilities & getQueryCapabilities() const
Boolean logic operator: AND.
void Union(const Envelope &rhs)
It updates the envelop with coordinates of another envelope.
const From * getFrom() const
It returns the list of source information to be used by the query.
This is an abstract class that models a query expression.
This operator EnvelopeIntersects considers the intersection among approximations or envelopes of geom...
virtual std::auto_ptr< te::da::DataSetType > getDataSetType(const std::string &name)=0
It gets information about the given dataset.
A class that models a literal for Envelope values.
TraverseType
A dataset can be traversed in two ways:
void setWhere(Where *w)
It sets the filter codition.
bool hasAttributeRestrictions() const
const Function * m_function
The function that represents the spatial restriction.
A class that informs the query support of a given data source.
A basic query processor for spatial restrictions.
An operator that considers the intersection among approximations or envelopes of geometries.
An Envelope defines a 2D rectangular region.
const std::vector< te::da::AttributeRestriction * > & getAttributeRestrictions() const
This class represents a set of unique ids created in the same context. i.e. from the same data set...
te::da::DataSourceCapabilities capabilities
A visitor that retrieves attribute restrictions from a Query hierarchy.
A struct that represents a spatial restriction.
Boolean logic operator: OR - syntatic-suggar.
virtual std::auto_ptr< DataSet > query(const Select &q, te::common::TraverseType travType=te::common::FORWARDONLY, bool connected=false, const te::common::AccessPolicy accessPolicy=te::common::RAccess)=0
It executes a query that may return some data using a generic query. A dataset can be connected or di...
The Field class can be used to model an expression that takes part of the output items of a SELECT...
boost::ptr_vector< Field > Fields
Fields is just a boost::ptr_vector of Field pointers.
A class that can be used to model a filter expression that can be applied to a query.
const Fields * getFields() const
It returns the list of output expressions used to form the result set.
A Select models a query to be used when retrieving data from a data source.
A DataSourceTransactor can be viewed as a connection to the data source for reading/writing things in...
TEDATAACCESSEXPORT ObjectIdSet * GenerateOIDSet(DataSet *dataset, const DataSetType *type)
const std::string & getName() const
It returns the function name.
std::string m_pname
The property name of the spatial restriction.
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.
te::gm::Envelope * computeEnvelope(const std::vector< SpatialRestriction * > &restrictions) const
Boolean logic operator: AND - syntatic-suggar.
const std::set< std::string > & getSpatialTopologicOperators() const
A visitor that retrieves attribute restrictions from a Query hierarchy.
A class that can be used to model a filter expression that can be applied to a query.
boost::ptr_vector< FromItem > From
It models the FROM clause for a query.
te::gm::Geometry * m_geometry
The geometry of the spatial restriction.
virtual std::auto_ptr< DataSet > getDataSet(const DataSourcePtr &ds, const Select &q, te::common::TraverseType travType=te::common::FORWARDONLY)
virtual ReturnType accept(VisitorType &guest) const =0
It call the visit method from the guest object.
void Union(ObjectIdSet *rhs)
It performs the union operation between this ObjectIdSet and the given ObjectIdSet.
A class that models a literal for Envelope values.
const std::string & getName() const
It returns the dataset name.
It models the FROM clause for a query.
std::string getDataSetName(const Select &q) const
virtual std::auto_ptr< DataSet > getDataSet(const std::string &name, te::common::TraverseType travType=te::common::FORWARDONLY, bool connected=false, const te::common::AccessPolicy accessPolicy=te::common::RAccess)=0
It gets the dataset identified by the given name. A dataset can be connected or disconnected. A connected dataset, after its creation through the data source transactor, continues to depend on the connection given by its associated data source. Differently, a disconnected dataset, after its creation, no more depends of the connection given by the data source, and it continues to live after the connection has been released to the data source.
The Fields class can be used to model a set of expressions that form the output items of a SELECT...
A class that informs the query support of a given data source.
const Envelope * getMBR() const
It returns the minimum bounding rectangle for the geometry in an internal representation.
void setFields(Fields *f)
It sets the list of output expressions used to form the result set.
void setFrom(From *f)
It sets the list of source information.