SpatialRestrictionVisitor.h
Go to the documentation of this file.
1 /* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 /*!
21  \file terralib/dataaccess/query/SpatialRestrictionVisitor.h
22 
23  \brief A visitor that retrieves spatial restrictions from a Query hierarchy.
24 */
25 
26 #ifndef __TERRALIB_DATAACCESS_INTERNAL_SPATIALRESTRICTIONVISITOR_H
27 #define __TERRALIB_DATAACCESS_INTERNAL_SPATIALRESTRICTIONVISITOR_H
28 
29 // TerraLib
30 #include "../../geometry/Enums.h"
31 #include "QueryVisitor.h"
32 
33 // Boost
34 #include <boost/noncopyable.hpp>
35 
36 // STL
37 #include <map>
38 #include <string>
39 #include <vector>
40 
41 namespace te
42 {
43 // Forward declaration
44  namespace gm
45  {
46  class Geometry;
47  }
48 
49  namespace da
50  {
51  /*!
52  \struct SpatialRestriction
53 
54  \brief A struct that represents a spatial restriction.
55  */
57  {
58  /*! \brief Default constructor. */
60 
61  /*! \brief Destructor. */
63 
64  std::size_t m_index; //!< Internal index of the spatial restriction.
65  te::gm::SpatialRelation m_type; //!< The spatial restriction type.
66  te::gm::Geometry* m_geometry; //!< The geometry of the spatial restriction.
67  std::string m_pname; //!< The property name of the spatial restriction.
68  bool m_isFromEnvelope; //!< A flag that indicates if the spatial restriction uses an envelope.
69  const Function* m_function; //!< The function that represents the spatial restriction.
70  };
71 
72  /*!
73  \class SpatialRestrictionVisitor
74 
75  \brief A visitor for retrieves spatial restrictions from a Query hierarchy.
76  */
77  class TEDATAACCESSEXPORT SpatialRestrictionVisitor : public QueryVisitor, public boost::noncopyable
78  {
79  public:
80 
81  /*! \brief Default constructor. */
83 
84  /*! \brief Virtual destructor. */
85  virtual ~SpatialRestrictionVisitor();
86 
87  virtual void visit(const Expression& visited) {}
88  virtual void visit(const DataSetName& visited) {}
89  virtual void visit(const FromItem& visited) {}
90  virtual void visit(const Function& visited);
91  virtual void visit(const Insert& visited) {}
92  virtual void visit(const Join& visited) {}
93  virtual void visit(const JoinCondition& visited) {}
94  virtual void visit(const JoinConditionOn& visited) {}
95  virtual void visit(const JoinConditionUsing& visited) {}
96  virtual void visit(const Literal& visited) {}
97  virtual void visit(const LiteralBool& visited) {}
98  virtual void visit(const LiteralByteArray& visited) {}
99  virtual void visit(const LiteralDateTime& visited) {}
100  virtual void visit(const LiteralDouble& visited) {}
101  virtual void visit(const LiteralEnvelope& visited) {}
102  virtual void visit(const LiteralGeom& visited) {}
103  virtual void visit(const LiteralInt16& visited) {}
104  virtual void visit(const LiteralInt32& visited) {}
105  virtual void visit(const LiteralInt64& visited) {}
106  virtual void visit(const LiteralString& visited) {}
107  virtual void visit(const PropertyName& visited) {}
108  virtual void visit(const Query& visited) {}
109  virtual void visit(const Select& visited);
110  virtual void visit(const SelectExpression& visited) {}
111  virtual void visit(const SubSelect& visited) {}
112  virtual void visit(const In& visited) {}
113  virtual void visit(const Cast& visited) {}
114 
115  bool hasSpatialRestrictions() const;
116 
117  const std::vector<te::da::SpatialRestriction*>& getSpatialRestrictions() const;
118 
119  protected:
120 
121  virtual void initialize();
122 
123  bool isSpatialRestrictionFunction(const Function& f) const;
124 
125  te::gm::SpatialRelation getSpatialRelation(const Function& f) const;
126 
127  bool isFromEnvelope(const Function& f) const;
128 
129  te::gm::Geometry* getGeometryRestriction(const Function& f) const;
130 
131  std::string getPropertyName(const Function& f) const;
132 
133  void addSpatialRestriction(const Function& f);
134 
135  protected:
136 
137  std::map<std::string, te::gm::SpatialRelation> m_spatialFunctions; //!< A map of spatial restriction functions.
138  std::size_t m_index; //!< An internal visitor index.
139  std::vector<te::da::SpatialRestriction*> m_spatialRestrictions; //!< The set of spatial restrictions.
140  };
141 
142  } // end namespace da
143 } // end namespace te
144 
145 #endif // __TERRALIB_DATAACCESS_INTERNAL_SPATIALRESTRICTIONVISITOR_H
A visitor for retrieves spatial restrictions from a Query hierarchy.
te::gm::SpatialRelation m_type
The spatial restriction type.
virtual void visit(const LiteralBool &visited)
An abstract class that models a source of data in a query.
Definition: FromItem.h:50
virtual void visit(const LiteralEnvelope &visited)
std::size_t m_index
Internal index of the spatial restriction.
A class that models the name of a dataset used in a From clause.
Definition: DataSetName.h:43
std::vector< te::da::SpatialRestriction * > m_spatialRestrictions
The set of spatial restrictions.
A class that models the name of any property of an object.
Definition: PropertyName.h:50
virtual void visit(const JoinConditionUsing &visited)
virtual void visit(const SubSelect &visited)
SpatialRestriction()
Default constructor.
virtual void visit(const PropertyName &visited)
virtual void visit(const LiteralString &visited)
virtual void visit(const Literal &visited)
This class models a bool Literal value.
Definition: LiteralBool.h:43
A visitor interface for the Query hierarchy.
SpatialRelation
Spatial relations between geometric objects.
Definition: Enums.h:127
virtual void visit(const LiteralByteArray &visited)
virtual void visit(const Join &visited)
The Insert object can add the return of a select object.
Definition: Insert.h:50
virtual void visit(const LiteralDouble &visited)
This is an abstract class that models a query expression.
Definition: Expression.h:47
virtual void visit(const JoinConditionOn &visited)
virtual void visit(const JoinCondition &visited)
A class that models a literal for Date and Time values.
const Function * m_function
The function that represents the spatial restriction.
A visitor interface for the Query hierarchy.
Definition: QueryVisitor.h:47
This class models a literal value.
Definition: Literal.h:53
A struct that represents a spatial restriction.
virtual void visit(const LiteralDateTime &visited)
URI C++ Library.
A class that models a literal for ByteArray values.
bool m_isFromEnvelope
A flag that indicates if the spatial restriction uses an envelope.
A condition to be used in a Join clause.
Definition: JoinCondition.h:44
std::size_t m_index
An internal visitor index.
virtual void visit(const Query &visited)
A class that models a Function expression.
Definition: Function.h:47
A Join clause combines two FromItems.
Definition: Join.h:50
A class that models a literal for double values.
Definition: LiteralDouble.h:43
std::string m_pname
The property name of the spatial restriction.
virtual void visit(const FromItem &visited)
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
Definition: Geometry.h:74
A Select models a query to be used when retrieving data from a DataSource.
Definition: Select.h:65
virtual void visit(const Cast &visited)
virtual void visit(const Insert &visited)
virtual void visit(const LiteralInt16 &visited)
virtual void visit(const LiteralInt64 &visited)
virtual void visit(const In &visited)
te::gm::Geometry * m_geometry
The geometry of the spatial restriction.
virtual void visit(const LiteralGeom &visited)
A Select can be used as a source of information in another query.
virtual void visit(const Expression &visited)
virtual void visit(const LiteralInt32 &visited)
JoinConditionUsing class can be used to model a USING clause in a Join.
std::map< std::string, te::gm::SpatialRelation > m_spatialFunctions
A map of spatial restriction functions.
A class that models a literal for Envelope values.
Cast a expression function.
Definition: Cast.h:46
~SpatialRestriction()
Destructor.
A class that represents the IN operator.
Definition: In.h:52
JoinConditionOn is a boolean expression and it specifies which items in a join are considered to matc...
#define TEDATAACCESSEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:97
A Select can be used as a source of information in another query.
Definition: SubSelect.h:49
A Query is independent from the data source language/dialect.
Definition: Query.h:46
virtual void visit(const DataSetName &visited)
A class that models a literal for Geometry values.
Definition: LiteralGeom.h:46
virtual void visit(const SelectExpression &visited)
This class models a string Literal value.
Definition: LiteralString.h:46