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"
70 std::auto_ptr<DataSourceTransactor> t = ds->getTransactor();
72 return getDataSet(t.get(),
capabilities, q, travType,
false);
85 return t->
query(q, travType, connected);
90 if(supportsSpatialTopologicOperatos(capabilities, restrictions))
91 return t->
query(q, travType, connected);
94 std::auto_ptr<ObjectIdSet> oids = getOIDSet(t, q);
98 throw(Exception(
TR_DATAACCESS(
"The query result is empty.")));
101 std::string datasetName = getDataSetName(q);
102 assert(!datasetName.empty());
104 return t->
getDataSet(datasetName, oids.get(), travType, connected);
113 std::auto_ptr<DataSourceTransactor> t = ds->getTransactor();
123 std::string datasetName = getDataSetName(q);
124 assert(!datasetName.empty());
134 if(!srv.hasSpatialRestrictions() && supportsSpatialTopologicOperatos(capabilities, srv.getSpatialRestrictions()))
138 assert(dataset.get());
141 std::auto_ptr<ObjectIdSet> oids(
GenerateOIDSet(dataset.get(), type.get()));
149 assert(from->size() == 1);
150 assert(!from->is_null(0));
158 baseSelect.
setFields(fields->clone().release());
159 baseSelect.
setFrom(from->clone().release());
162 const std::vector<SpatialRestriction*>& restrictions = srv.getSpatialRestrictions();
169 std::vector<te::gm::Geometry*> geomRestrictions;
170 for(std::size_t i = 0; i < restrictions.size(); ++i)
171 geomRestrictions.push_back(restrictions[i]->m_geometry);
173 for(std::size_t i = 0; i < restrictions.size(); ++i)
174 oids->
Union(getOIDSet(t, baseSelect, restrictions[i], type.get(), geomRestrictions));
176 return std::auto_ptr<te::da::ObjectIdSet>(oids);
184 std::string datasetName = getDataSetName(q);
185 assert(!datasetName.empty());
195 assert(srv.hasSpatialRestrictions());
200 assert(from->size() == 1);
201 assert(!from->is_null(0));
209 baseSelect.
setFields(fields->clone().release());
210 baseSelect.
setFrom(from->clone().release());
213 const std::vector<SpatialRestriction*>& restrictions = srv.getSpatialRestrictions();
220 std::vector<te::gm::Geometry*> geomRestrictions;
221 for(std::size_t i = 0; i < restrictions.size(); ++i)
222 geomRestrictions.push_back(restrictions[i]->m_geometry);
224 for(std::size_t i = 0; i < restrictions.size(); ++i)
225 oids->
Union(getOIDSet(t, baseSelect, restrictions[i], type.get(), geomRestrictions));
227 return std::auto_ptr<te::da::ObjectIdSet>(oids);
232 const std::vector<te::gm::Geometry*>& geomRestrictions)
240 assert(geomRestriction);
256 assert(dataset.get());
264 const std::vector<std::string>& pnames = oids->getPropertyNames();
266 std::size_t size = dataset->size();
268 while(dataset->moveNext())
270 std::auto_ptr<te::gm::Geometry> currentGeom(0);
273 currentGeom = dataset->getGeometry(restriction->
m_pname);
274 if(currentGeom.get() == 0)
277 catch(std::exception& )
282 assert(currentGeom.get());
284 bool equalsToRestriction =
false;
285 for(std::size_t i = 0; i < geomRestrictions.size(); ++i)
287 if(currentGeom->equals(geomRestrictions[i]))
289 equalsToRestriction =
true;
294 if(equalsToRestriction)
311 for(std::size_t i = 0; i < restrictions.size(); ++i)
325 const std::vector<SpatialRestriction*>& restrictions)
const
329 for(std::size_t i = 0; i < restrictions.size(); ++i)
335 if(ops.find(fname) == ops.end())
349 assert(from->size() == 1);
350 assert(!from->is_null(0));
te::gm::Envelope * computeEnvelope(const std::vector< SpatialRestriction * > &restrictions) const
TEDATAACCESSEXPORT ObjectIdSet * GenerateOIDSet(DataSet *dataset, const DataSetType *type)
SpatialQueryProcessor()
Constructor.
int getSRID() const
It returns the Spatial Reference System ID associated to this geometric object.
void setWhere(Where *w)
It sets the filter codition.
A visitor that retrieves attribute restrictions from a Query hierarchy.
This class represents a set of unique ids created in the same context. i.e. from the same data set...
A class that models the name of a dataset used in a From clause.
A Select models a query to be used when retrieving data from a data source.
A Select models a query to be used when retrieving data from a DataSource.
A class that models a literal for Envelope values.
const std::string & getName() const
It returns the dataset name.
boost::ptr_vector< FromItem > From
It models the FROM clause for a query.
const Function * m_function
The function that represents the spatial restriction.
TEDATAACCESSEXPORT void GetEmptyOIDSet(const DataSetType *type, ObjectIdSet *&set)
Returns an empty ObjectIdSet, with the definitions of fields that compose it.
const QueryCapabilities & getQueryCapabilities() const
A class that models the name of any property of an object.
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.
A class that models the name of any property of an object.
const From * getFrom() const
It returns the list of source information to be used by the query.
te::gm::Geometry * m_geometry
The geometry of the spatial restriction.
An operator that considers the intersection among approximations or envelopes of geometries.
It models the FROM clause for a query.
std::string getDataSetName(const Select &q) const
A struct that represents a spatial restriction.
boost::ptr_vector< Field > Fields
Fields is just a boost::ptr_vector of Field pointers.
bool supportsSpatialTopologicOperatos(const QueryCapabilities &capabilities, const std::vector< SpatialRestriction * > &restrictions) const
bool hasSpatialRestrictions() const
This operator EnvelopeIntersects considers the intersection among approximations or envelopes of geom...
te::gm::SpatialRelation m_type
The spatial restriction type.
TEDATAACCESSEXPORT ObjectId * GenerateOID(DataSet *dataset, const std::vector< std::string > &names)
TEGEOMEXPORT bool SatisfySpatialRelation(const Geometry *g1, const Geometry *g2, SpatialRelation relation)
It returns if two geometries satisfy a given spatial relation.
const std::set< std::string > & getSpatialTopologicOperators() const
void setFields(Fields *f)
It sets the list of output expressions used to form the result set.
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
A class that can be used to model a filter expression that can be applied to a query.
A class that informs the query support of a given data source.
A class that models a literal for Envelope values.
boost::shared_ptr< DataSource > DataSourcePtr
A class that models the name of a dataset used in a From clause.
virtual std::auto_ptr< te::da::DataSetType > getDataSetType(const std::string &name)=0
It gets information about the given dataset.
A basic query processor for spatial restrictions.
The Field class can be used to model an expression that takes part of the output items of a SELECT...
void Union(ObjectIdSet *rhs)
It performs the union operation between this ObjectIdSet and the given ObjectIdSet.
virtual std::auto_ptr< ObjectIdSet > getOIDSet(const DataSourcePtr &ds, const Select &q)
TraverseType
A dataset can be traversed in two ways:
#define TR_DATAACCESS(message)
It marks a string in order to get translated. This is a special mark used in the DataAccess module of...
The Fields class can be used to model a set of expressions that form the output items of a SELECT...
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...
const std::string & getName() const
It returns the function name.
std::string m_pname
The property name of the spatial restriction.
A class that models the description of a dataset.
An abstract class that models a source of data in a query.
A class that informs the query support of a given data source.
const Fields * getFields() const
It returns the list of output expressions used to form the result set.
virtual ReturnType accept(VisitorType &guest) const =0
It call the visit method from the guest object.
const std::vector< te::da::SpatialRestriction * > & getSpatialRestrictions() const
const Envelope * getMBR() const
It returns the minimum bounding rectangle for the geometry in an internal representation.
virtual ~SpatialQueryProcessor()
Virtual destructor.
A visitor that retrieves spatial restrictions from a Query hierarchy.
virtual std::auto_ptr< DataSet > getDataSet(const DataSourcePtr &ds, const Select &q, te::common::TraverseType travType=te::common::FORWARDONLY)
An Envelope defines a 2D rectangular region.
A class that can be used to model a filter expression that can be applied to a query.
void setFrom(From *f)
It sets the list of source information.
te::da::DataSourceCapabilities capabilities
void Union(const Envelope &rhs)
It updates the envelop with coordinates of another envelope.
A DataSourceTransactor can be viewed as a connection to the data source for reading/writing things in...
A visitor for retrieves spatial restrictions from a Query hierarchy.