Filter2Query.cpp
Go to the documentation of this file.
1 #include "Dialect.h"
2 #include "MapToolsExamples.h"
3 
4 // TerraLib
5 #include <terralib/common.h>
6 #include <terralib/dataaccess.h>
7 #include <terralib/fe.h>
8 #include <terralib/maptools.h>
9 
10 // STL
11 #include <iostream>
12 
14 {
15  /* Creating an OGC Filter Expression */
16 
17  // (1): nome = 'MINAS GERAIS'
18  te::fe::PropertyName* state = new te::fe::PropertyName("state");
19  te::fe::Literal* stateName = new te::fe::Literal("MINAS GERAIS");
21 
22  // (2): populacao < '2.000'
23  te::fe::PropertyName* pop = new te::fe::PropertyName("population");
24  te::fe::Literal* popValue = new te::fe::Literal("2.000");
26 
27  // (3): Joins the expression (1) and (2) using a binary logic operator AND
28  te::fe::BinaryLogicOp* andOp = new te::fe::BinaryLogicOp(te::fe::Globals::sm_and, stateEqual, popLessThan);
29 
30  // (4): cidade = 'SERITINGA'
31  te::fe::PropertyName* city = new te::fe::PropertyName("city");
32  te::fe::Literal* cityName = new te::fe::Literal("SERITINGA");
34 
35  // (5): Joins the expression (3) and (4) using a binary logic operator OR
37 
38  // We have a Filter!
39  te::fe::Filter* filter = new te::fe::Filter;
40  filter->setOp(orOp); // (state = 'MINAS GERAIS' AND populacao < '2.000') OR (city = 'SERITINGA')
41 
42  // -----------------------------------------
43 
44  /* Let's convert! */
45 
46  // Gets an enconder...
47  te::map::QueryEncoder converter;
48  // ... and convert it to a TerraLib Expression!
49  te::da::Expression* exp = converter.getExpression(filter);
50 
51  // Let's see the result...
52  te::da::SQLDialect* dialect = createDialect(); // a hard-coded dialect
53 
54  std::string sql;
55  te::da::SQLVisitor sqlConverter(*dialect, sql);
56  exp->accept(sqlConverter);
57 
58  std::cout << "Conversion result is: " << sql << std::endl;
59 
60  delete filter;
61  delete exp;
62  delete dialect;
63 }
static const char * sm_propertyIsLessThan
te::da::SQLDialect * dialect
Definition: WFSDialect.h:1
void Filter()
static const char * sm_or
It represents the SQL query dialect accepted by a given data source.
Definition: SQLDialect.h:55
te::da::Expression * getExpression(const te::fe::Filter *f)
It converts the OGC Filter Expression to a TerraLib Expression.
virtual ReturnType accept(VisitorType &guest) const =0
It call the visit method from the guest object.
static const char * sm_propertyIsEqualTo
This is an abstract class that models a query expression.
void setOp(AbstractOp *o)
It sets the filter main operation (expression).
This class is used to encode the name of any property of an object.
A visitor that converts a OGC Filter Expression to TerraLib Expression.
Definition: QueryEncoder.h:53
This file contains include headers for TerraLib Filter Encoding module.
A filter is any valid predicate expression.
Definition: fe/Filter.h:55
void Filter2Query()
It converts a OGC Filter Expression to TerraLib Expression.
A class for binary comparison operators.
static const char * sm_and
This class can be used to represent literal values.
Definition: fe/Literal.h:56
A visitor for building an SQL statement from a given Query hierarchy.
This file contains include headers for the TerraLib Common Runtime module.
A logical operator can be used to combine two or more conditional expressions.
Definition: BinaryLogicOp.h:58
This file contains include headers for the Data Access module of TerraLib.
This file contains include headers for the Map Tools module of TerraLib.
te::da::SQLDialect * createDialect()
Definition: Dialect.h:4