27 #include "../../core/translator/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" 68 std::unique_ptr<DataSourceTransactor> t = ds->getTransactor();
83 return t->
query(q, travType, connected);
89 return t->
query(q, travType, connected);
92 std::unique_ptr<ObjectIdSet> oids =
getOIDSet(t, q);
100 assert(!datasetName.empty());
102 return t->
getDataSet(datasetName, oids.get(), travType, connected);
111 std::unique_ptr<DataSourceTransactor> t = ds->getTransactor();
122 assert(!datasetName.empty());
125 std::unique_ptr<DataSetType> type = t->
getDataSetType(datasetName);
136 assert(dataset.get());
139 std::unique_ptr<ObjectIdSet> oids(
GenerateOIDSet(dataset.get(), type.get()));
147 assert(from->size() == 1);
148 assert(!from->is_null(0));
156 baseSelect.
setFields(fields->clone().release());
157 baseSelect.
setFrom(from->clone().release());
163 const std::vector<SpatialRestriction*>& restrictions = srv.getSpatialRestrictions();
170 std::vector<te::gm::Geometry*> geomRestrictions;
171 for(std::size_t i = 0; i < restrictions.size(); ++i)
172 geomRestrictions.push_back(restrictions[i]->m_geometry);
174 for(std::size_t i = 0; i < restrictions.size(); ++i)
175 oids->
Union(
getOIDSet(t, baseSelect, attrRestrictions, restrictions[i], type.get(), geomRestrictions));
177 return std::unique_ptr<te::da::ObjectIdSet>(oids);
186 assert(!datasetName.empty());
189 std::unique_ptr<DataSetType> type = t->
getDataSetType(datasetName);
196 assert(srv.hasSpatialRestrictions());
201 assert(from->size() == 1);
202 assert(!from->is_null(0));
210 baseSelect.
setFields(fields->clone().release());
211 baseSelect.
setFrom(from->clone().release());
217 const std::vector<SpatialRestriction*>& restrictions = srv.getSpatialRestrictions();
224 std::vector<te::gm::Geometry*> geomRestrictions;
225 for(std::size_t i = 0; i < restrictions.size(); ++i)
226 geomRestrictions.push_back(restrictions[i]->m_geometry);
228 for(std::size_t i = 0; i < restrictions.size(); ++i)
229 oids->
Union(
getOIDSet(t, baseSelect, attrRestrictions, restrictions[i], type.get(), geomRestrictions));
231 return std::unique_ptr<te::da::ObjectIdSet>(oids);
236 const std::vector<te::gm::Geometry*>& geomRestrictions)
244 assert(geomRestriction);
256 if(attrRestrictions == 0)
263 assert(dataset.get());
271 const std::vector<std::string>& pnames = oids->getPropertyNames();
273 while(dataset->moveNext())
275 std::unique_ptr<te::gm::Geometry> currentGeom;
278 currentGeom = std::move(dataset->getGeometry(restriction->
m_pname));
279 if(currentGeom.get() == 0)
282 catch(std::exception& )
287 assert(currentGeom.get());
289 bool equalsToRestriction =
false;
290 for(std::size_t i = 0; i < geomRestrictions.size(); ++i)
292 if(currentGeom->equals(geomRestrictions[i]))
294 equalsToRestriction =
true;
299 if(equalsToRestriction)
316 for(std::size_t i = 0; i < restrictions.size(); ++i)
330 const std::vector<SpatialRestriction*>& restrictions)
const 334 for(std::size_t i = 0; i < restrictions.size(); ++i)
340 if(ops.find(fname) == ops.end())
354 assert(from->size() == 1);
355 assert(!from->is_null(0));
373 if(attrRestrictions.size() == 1)
374 return attrRestrictions[0]->m_function->clone();
376 assert(attrRestrictions.size() >= 2);
379 And* andOp =
new And(attrRestrictions[0]->m_function->clone(), attrRestrictions[1]->m_function->clone());
381 for(std::size_t i = 2; i < attrRestrictions.size(); ++i)
383 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.
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.
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.
Base exception class for plugin module.
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.
virtual std::unique_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...
bool hasSpatialRestrictions() const
virtual ReturnType accept(VisitorType &guest) const =0
It call the visit method from the guest object.
static te::dt::Date ds(2010, 01, 01)
#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...
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.
int getSRID() const _NOEXCEPT_OP(true)
It returns the Spatial Reference System ID associated to this geometric object.
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.
const Envelope * getMBR() const _NOEXCEPT_OP(true)
It returns the minimum bounding rectangle for the geometry in an internal representation.
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::unique_ptr< ObjectIdSet > getOIDSet(const DataSourcePtr &ds, const Select &q)
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.
virtual std::unique_ptr< DataSet > getDataSet(const DataSourcePtr &ds, const Select &q, te::common::TraverseType travType=te::common::FORWARDONLY)
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::unique_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.
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.
The Field class can be used to model an expression that takes part of the output items of a SELECT...
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
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.
virtual std::unique_ptr< te::da::DataSetType > getDataSetType(const std::string &name)=0
It gets information about the given dataset.
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.