QueryEncoder.cpp
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/maptools/QueryEncoder.cpp
22 
23  \brief A visitor that converts a OGC Filter Expression to TerraLib Expression.
24  */
25 
26 // TerraLib
27 #include "../dataaccess/query_h.h"
28 #include "../fe.h"
29 #include "../gml/Envelope.h"
30 #include "QueryEncoder.h"
31 
32 std::map<std::string, std::string> te::map::QueryEncoder::sm_fnameMap;
33 
35  : m_expression(nullptr)
36 {
37 }
38 
40 
42 {
43  te::fe::AbstractOp* ops = f->getOp();
44  if(ops)
45  {
46  ops->accept(*this);
47  return m_expression;
48  }
49  else
50  {
51  te::da::In* in = new te::da::In(""); // TODO: What is the PropertyName?
52  // ids
53  size_t nids = f->getNumberOfOids();
54  for(size_t i = 0; i < nids; ++i)
55  {
56  te::fe::ObjectId* objId = f->getOid(i);
57  in->add(new te::da::LiteralString(objId->getId()));
58  }
59  return in;
60  }
61 
62  return nullptr;
63 }
64 
66 {
67  // no need
68 }
69 
71 {
72  // no need
73 }
74 
76 {
77  // no need
78 }
79 
81 {
82  // no need
83 }
84 
86 {
87  te::da::Expression* l = nullptr;
88  te::gml::Envelope* e = visited.getEnvelope();
89  if(e)
91 
92  te::fe::PropertyName* p = visited.getProperty();
93  assert(p);
94  p->accept(*this);
95 
97 
98  m_expression = f;
99 }
100 
102 {
103  visited.getFirst()->accept(*this);
105 
106  visited.getSecond()->accept(*this);
108 
110  f->add(e1);
111  f->add(e2);
112 
113  m_expression = f;
114 }
115 
117 {
119  size_t n = visited.size();
120  for(size_t i = 0; i < n; ++i)
121  {
122  visited.getOp(i)->accept(*this);
124  f->add(e);
125  }
126  m_expression = f;
127 }
128 
130 {
131  te::da::Expression* l = nullptr;
132  te::gml::Envelope* e = visited.getEnvelope();
133  if(e)
134  {
135  l = new te::da::LiteralEnvelope(e->getCoordinates(), e->getSRID());
136  }
137  else
138  {
139  te::gm::Geometry* g = visited.getGeometry();
140  if(g)
141  l = new te::da::LiteralGeom(g);
142  }
143 
144  te::fe::PropertyName* p = visited.getProperty();
145  assert(p);
146  p->accept(*this);
147 
149 
150  m_expression = f;
151 }
152 
154 {
155  te::fe::PropertyName* p = visited.getProperty();
156  assert(p);
157  p->accept(*this);
158 
159  te::gm::Geometry* g = visited.getGeometry();
160  te::common::Distance* d = visited.getDistance();
161 
163 
164  m_expression = dbuffer;
165 }
166 
168 {
169  visited.getExpression()->accept(*this);
171 
172  visited.getLowerBoundary()->accept(*this);
174 
175  visited.getUpperBoundary()->accept(*this);
177 
178  te::da::GreaterThan* gt = new te::da::GreaterThan(v, e1);
179  te::da::LessThan* lt = new te::da::LessThan(v, e2);
180 
181  te::da::And* and_op = new te::da::And(gt, lt);
182 
183  m_expression = and_op;
184 }
185 
187 {
188  te::fe::Literal* l = visited.getLiteral();
189  assert(l);
190  std::string pattern = l->getValue();
191  std::string wildCard = visited.getWildCard();
192  std::string singleChar = visited.getSingleChar();
193  std::string escapeChar = visited.getEscapeChar();
194 
196  assert(p);
197  p->accept(*this);
198 
199  te::da::Like* like = new te::da::Like(m_expression, pattern, wildCard, singleChar, escapeChar);
200 
201  m_expression = like;
202 }
203 
205 {
207  assert(p);
208  p->accept(*this);
209 
211 
212  m_expression = f;
213 }
214 
216 {
217  visited.getOp()->accept(*this);
218 
220 
221  m_expression = op;
222 }
223 
225 {
226  // no need
227 }
228 
230 {
231  visited.getFirst()->accept(*this);
233 
234  visited.getSecond()->accept(*this);
236 
238 
239  m_expression = f;
240 }
241 
243 {
244  // no need
245 }
246 
248 {
249  te::da::Literal* l = new te::da::LiteralString(visited.getValue());
250  m_expression = l;
251 }
252 
254 {
256  m_expression = p;
257 }
258 
260 {
261  // BinaryComparisonOp
267 
268  // BinaryLogicOp
271 
272  // BinarySpatialOp
280 
281  // DistanceBuffer
284 
285  // UnaryLogicOp
287 
288  // BinaryOperator
293 }
It models the inequality operator greater than (>).
Definition: GreaterThan.h:46
const std::string & getName() const
It returns the property name.
static const char * sm_propertyIsLessThan
static const char * sm_touches
static const char * sm_mul
void add(Expression *arg)
It adds the argument to the function list of arguments.
const char * getName() const
It returns the operator name.
Definition: AbstractOp.h:82
te::gm::Envelope * getCoordinates() const
te::gm::Geometry * getGeometry() const
It returns the geometry.
te::common::Distance * getDistance() const
It returns the distance.
static const char * sm_dWithin
const std::string & getId() const
It returns the feature identification value.
static const std::string sm_Add
Definition: FunctionNames.h:63
PropertyName * getPropertyName() const
It returns the property name.
static const std::string sm_LessThan
Definition: FunctionNames.h:59
Distance buffer operator.
Spatial intersects operator.
Definition: ST_Intersects.h:46
static const std::string sm_ST_Equals
Definition: FunctionNames.h:85
static const std::string sm_ST_Overlaps
Definition: FunctionNames.h:98
ObjectId * getOid(size_t i) const
It returns a specified object identifier.
te::gm::Geometry * getGeometry() const
It returns the geometry.
static const char * sm_propertyIsGreaterThanOrEqualTo
static const char * sm_propertyIsGreaterThan
A class that models the name of any property of an object.
static const char * sm_crosses
static const std::string sm_ST_Touches
static const std::string sm_ST_Intersects
Definition: FunctionNames.h:88
static const char * sm_or
A convenient and more compact way of encoding the very common bounding box constraint based on an env...
Definition: BBOXOp.h:71
A spatial operator determines whether its geometric arguments satisfy the stated spatial relationship...
Definition: SpatialOp.h:52
PropertyName * getPropertyName() const
It returns the property name.
const std::string & getWildCard() const
It returns the wild character.
A visitor that converts a OGC Filter Expression to TerraLib Expression.
static const char * sm_intersects
A class for binary spatial operators.
~QueryEncoder()
Virtual destructor.
It models the inequality operator less than (<).
Definition: LessThan.h:46
static const char * sm_disjoint
The PropertyIsBetween element is defined as a compact way of encoding a range check.
static const char * sm_within
A comparison operator is used to form expressions that evaluate the mathematical comparison between t...
Definition: ComparisonOp.h:49
te::da::Expression * getExpression(const te::fe::Filter *f)
It converts the OGC Filter Expression to a TerraLib Expression.
AbstractOp * getOp() const
It returns main filter operation.
virtual ReturnType accept(VisitorType &guest) const =0
It call the visit method from the guest object.
static const std::string sm_EqualTo
Definition: FunctionNames.h:55
PropertyName * getProperty() const
It returns the property name.
std::size_t size() const
It returns the number of operands.
int getSRID() const
static const char * sm_propertyIsEqualTo
A logical operator that can be used to combine one conditional expressions.
Definition: UnaryLogicOp.h:46
The PropertyIsNull class encodes an operator that checks to see if the value of its content is NULL...
Boolean logic operator: AND.
This is an abstract class that models a query expression.
te::gml::Envelope * getEnvelope() const
It returns the envelope.
Definition: BBOXOp.cpp:62
Literal * getLiteral() const
It returns the literal value.
QueryEncoder()
Default constructor.
static const char * sm_div
static std::map< std::string, std::string > sm_fnameMap
A map that associates Filter Operator names to Query Functions names.
Definition: QueryEncoder.h:147
const std::string & getSingleChar() const
It returns the single wild character.
Spatial Distance Buffer operator.
static const std::string sm_GreaterThanOrEqualTo
Definition: FunctionNames.h:58
Expression * getUpperBoundary() const
It returns the upper boundary expression.
static const std::string sm_ST_Crosses
Definition: FunctionNames.h:77
A function is a named procedure that performs a distinct computation.
Definition: fe/Function.h:54
It is intended to encode a character string comparison operator with pattern matching.
This class can be used to represent binary operation expressions.
static const std::string sm_Mul
Definition: FunctionNames.h:65
This class models a literal value.
This class is used to encode the name of any property of an object.
size_t getNumberOfOids() const
It returns the size of the list of object identifiers.
PropertyName * getProperty() const
It returns the property name.
static const char * sm_beyond
This is an abstract class that models a Filter Encoding expression.
Definition: fe/Expression.h:50
Expression * getSecond() const
It returns the second operand.
static te::dt::DateTime d(2010, 8, 9, 15, 58, 39)
Expression * getFirst() const
It returns the first operand.
It is intended to encode a character string comparison operator with pattern matching.
Definition: Like.h:43
AbstractOp * getOp(std::size_t i) const
It returns a specified operand.
An object identifier is meant to represent a unique identifier for an object instance within the cont...
Definition: fe/ObjectId.h:58
te::gm::Polygon * p
static const std::string sm_And
Definition: FunctionNames.h:51
static void initialize()
Static method to initialize the QueryEncoder.
static const std::string sm_ST_Beyond
Definition: FunctionNames.h:71
Expression * getSecond() const
It returns the second operand.
A class that models a Function expression.
const std::string & getEscapeChar() const
It returns the escape character.
Tells if a value is NULL.
Definition: IsNull.h:46
A filter is any valid predicate expression.
Definition: fe/Filter.h:55
AbstractOp * getOp() const
It returns the operand.
static const std::string sm_Div
Definition: FunctionNames.h:66
Envelope defines an extent using a pair of positions defining opposite corners in arbitrary dimension...
Definition: gml/Envelope.h:52
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
static const std::string sm_LessThanOrEqualTo
Definition: FunctionNames.h:60
static const std::string sm_Sub
Definition: FunctionNames.h:64
static const char * sm_add
An abstract interface for operators.
Definition: AbstractOp.h:47
PropertyName * getProperty() const
It returns the property name.
Definition: BBOXOp.cpp:51
A class for binary comparison operators.
static const std::string sm_ST_Disjoint
Definition: FunctionNames.h:79
static const char * sm_and
te::gml::Envelope * getEnvelope() const
It returns the envelope.
This class can be used to represent literal values.
Definition: fe/Literal.h:56
static const char * sm_sub
A logical operator can be used to combine one or more conditional expressions.
Definition: LogicOp.h:52
static const std::string sm_ST_Within
static const char * sm_equals
A class that models a literal for Envelope values.
A base class for unary operators.
Definition: UnaryOp.h:43
void visit(const te::fe::AbstractOp &visited)
A logical operator can be used to combine two or more conditional expressions.
Definition: BinaryLogicOp.h:58
A class that represents the IN operator.
Definition: In.h:52
static const char * sm_overlaps
const std::string & getValue() const
It returns the literal value.
Definition: fe/Literal.cpp:36
static const char * sm_not
Expression * getFirst() const
It returns the first operand.
static const std::string sm_Not
Definition: FunctionNames.h:50
static const std::string sm_Or
Definition: FunctionNames.h:52
const char * getName() const
It returns the operator name.
static const std::string sm_ST_DWithin
Definition: FunctionNames.h:82
static const std::string sm_GreaterThan
Definition: FunctionNames.h:57
Expression * getLowerBoundary() const
It returns the lower boundary expression.
A base class for binary functions.
static const char * sm_propertyIsLessThanOrEqualTo
te::da::Expression * m_expression
Expression used during conversion.
Definition: QueryEncoder.h:146
A class that models a literal for Geometry values.
Definition: LiteralGeom.h:46
Expression * getExpression() const
It returns the between expression.
A given distance has a measurement and a unit-of-measure.
Definition: Distance.h:44
This class models a string Literal value.
Definition: LiteralString.h:46