SerializationExamples.cpp
Go to the documentation of this file.
2 
3 // TerraLib
4 #include <terralib/fe.h>
5 #include <terralib/se.h>
11 #include <terralib/xml/Reader.h>
14 
15 // STL
16 #include <cassert>
17 #include <sstream>
18 
19 void EncodeStyle(const std::string& path)
20 {
21  /* Creating an OGC Symbology Enconding Style */
22 
23  // Creates a PolygonSymbolizer
24  te::se::Stroke* strokePolygon = te::se::CreateStroke("#000000", "2", "0.5", "2 3 2 3", "square", "miter");
25  te::se::Fill* fillPolygon = te::se::CreateFill("#FF8C00", "1.0");
26  te::se::PolygonSymbolizer* ps = te::se::CreatePolygonSymbolizer(strokePolygon, fillPolygon);
27  ps->setGeometry(new te::fe::PropertyName("area"));
28  ps->setDescription(te::se::CreateDescription("A simple polygon symbolizer example", "This symbolizer was created to show the power of TerraLib serialization module."));
29 
30  // Creates a PolygonSymbolizer with GraphicFill
31  te::se::Mark* markGraphicFill = te::se::CreateMark("circle", te::se::CreateStroke("#000000", "1"), te::se::CreateFill("#FFFF00", "1.0"));
32  te::se::Graphic* graphicFill = te::se::CreateGraphic(markGraphicFill, "8", "45", "1.0");
33  te::se::Fill* fillWithGraphicFill = te::se::CreateFill(graphicFill);
34  te::se::PolygonSymbolizer* psGraphicFill = te::se::CreatePolygonSymbolizer(0, fillWithGraphicFill);
35 
36  // Creates a LineSymbolizer
37  te::se::Stroke* strokeLine = te::se::CreateStroke("#FF0000", "1");
39  ls->setGeometry(new te::fe::PropertyName("centerline"));
40  ls->setDescription(te::se::CreateDescription("A simple line symbolizer example", "This symbolizer was created to show the power of TerraLib serialization module."));
41 
42  // Creates a PointSymbolizer
43  te::se::Mark* mark = te::se::CreateMark("star", te::se::CreateStroke("#000000", "1"), te::se::CreateFill("#FFFF00", "1.0"));
44  te::se::Graphic* graphic = te::se::CreateGraphic(mark, "8", "45", "1.0");
46  pts->setGeometry(new te::fe::PropertyName("location"));
47  pts->setDescription(te::se::CreateDescription("A simple point symbolizer example", "This symbolizer was created to show the power of TerraLib serialization module."));
48 
49  // Creates a TextSymbolizer
51  ts->setGeometry(new te::fe::PropertyName("location"));
52  ts->setDescription(te::se::CreateDescription("A simple text symbolizer example", "This symbolizer was created to show the power of TerraLib serialization module."));
53 
54  // Creates a RasterSymbolizer
56  scR->setSourceChannelName("0");
58  scG->setSourceChannelName("1");
60  scB->setSourceChannelName("2");
61 
64  cs->setRedChannel(scR);
65  cs->setGreenChannel(scG);
66  cs->setBlueChannel(scB);
67 
68  te::se::Categorize* categorize = new te::se::Categorize;
70  categorize->setFallbackValue("0");
71  categorize->setLookupValue(new te::se::ParameterValue("Rasterdata"));
72  categorize->addValue(new te::se::ParameterValue("#00FF00"));
73  categorize->addThreshold(new te::se::ParameterValue("-417"));
74  categorize->addValue(new te::se::ParameterValue("#00FA00"));
75  categorize->addThreshold(new te::se::ParameterValue("-333"));
76  categorize->addValue(new te::se::ParameterValue("#14F500"));
77  categorize->addThreshold(new te::se::ParameterValue("-250"));
78  categorize->addValue(new te::se::ParameterValue("#28F502"));
79  categorize->addThreshold(new te::se::ParameterValue("-167"));
80  categorize->addValue(new te::se::ParameterValue("#3CF505"));
81 
82  te::se::ColorMap* colorMap = new te::se::ColorMap;
83  colorMap->setCategorize(categorize);
84 
86  rs->setOpacity(new te::se::ParameterValue("1.0"));
87  rs->setGain(new te::se::ParameterValue("1.0"));
88  rs->setOffset(new te::se::ParameterValue("0.0"));
89  rs->setChannelSelection(cs);
90  rs->setColorMap(colorMap);
91  rs->setDescription(te::se::CreateDescription("A simple raster symbolizer example", "This symbolizer was created to show the power of TerraLib serialization module."));
92 
93  // Creates a Rule
94  te::se::Rule* rule = new te::se::Rule;
95  rule->setName(new std::string("Rule 1"));
96  rule->setMinScaleDenominator(250e3);
97  rule->setMaxScaleDenominator(5e6);
98  rule->push_back(ps);
99  rule->push_back(psGraphicFill);
100  rule->push_back(ls);
101  rule->push_back(pts);
102  rule->push_back(ts);
103  rule->push_back(rs);
104  rule->setDescription(te::se::CreateDescription("A simple rule example", "This rule was created to show the power of TerraLib serialization module."));
105 
106  /* Creating an OGC Filter Expression to Rule */
107 
108  // (1): nome = 'MINAS GERAIS'
109  te::fe::PropertyName* state = new te::fe::PropertyName("state");
110  te::fe::Literal* stateName = new te::fe::Literal("MINAS GERAIS");
112 
113  // (2): populacao < '2.000'
114  te::fe::PropertyName* pop = new te::fe::PropertyName("population");
115  te::fe::Literal* popValue = new te::fe::Literal("2.000");
117 
118  // (3): Joins the expression (1) and (2) using a binary logic operator AND
119  te::fe::BinaryLogicOp* andOp = new te::fe::BinaryLogicOp(te::fe::Globals::sm_and, stateEqual, popLessThan);
120 
121  // (4): cidade = 'SERITINGA'
122  te::fe::PropertyName* city = new te::fe::PropertyName("city");
123  te::fe::Literal* cityName = new te::fe::Literal("SERITINGA");
125 
126  // (5): Joins the expression (3) and (4) using a binary logic operator OR
128 
129  // We have a Filter!
130  te::fe::Filter* filter = new te::fe::Filter;
131  filter->setOp(orOp); // (state = 'MINAS GERAIS' AND populacao < '2.000') OR (city = 'SERITINGA')
132 
133  rule->setFilter(filter);
134 
135  // We have a Style!
137  style->push_back(rule);
138  style->setName(new std::string("Style 1"));
139  style->setDescription(te::se::CreateDescription("A simple style example", "This style was created to show the power of TerraLib serialization module."));
140 
141  std::unique_ptr<te::xml::AbstractWriter> writer(te::xml::AbstractWriterFactory::make());
142 
143  writer->setURI(path);
144 
145  writer->writeStartDocument("UTF-8", "no");
146 
147  writer->setRootNamespaceURI("http://www.opengis.net/se");
148 
149  te::se::serialize::Style::getInstance().write(style, *writer.get());
150 
151  writer->writeToFile();
152 
153  delete style;
154 }
155 
156 te::se::Style* DecodeStyle(const std::string& path)
157 {
158  te::xml::Reader* reader = te::xml::ReaderFactory::make("XERCES");
159  reader->read(path);
160  reader->next();
161 
162  te::se::Style* style = te::se::serialize::Style::getInstance().read(*reader);
163 
164  return style;
165 }
166 
A TextSymbolizer is used to render text labels according to various graphical parameters.
static const char * sm_propertyIsLessThan
void setRedChannel(SelectedChannel *c)
A selected channel to be display.
Auxiliary classes and functions to serialize style informations from a XML document.
The transformation of continuous values to distinct values (Categorize function). ...
Definition: Categorize.h:90
The Style defines the styling that is to be applied to a geographic dataset (vector geometries or cov...
Definition: Style.h:65
A Mark specifies a geometric shape and applies coloring to it.
Definition: Mark.h:84
This class models a XML reader object.
Definition: xml/Reader.h:55
A PolygonSymbolizer is used to draw a polygon (or other area-type geometries), including filling its ...
This class models a XML reader object.
void setGeometry(te::fe::PropertyName *geometry)
void Filter()
static const char * sm_or
void setDescription(Description *d)
Definition: Rule.cpp:69
void setName(std::string *name)
Definition: Rule.cpp:58
void setGain(ParameterValue *p)
void setDescription(Description *d)
Definition: Style.cpp:64
static te::xml::AbstractWriter * make()
It creates a new XML writer using the dafault implementation.
void setLookupValue(ParameterValue *v)
Definition: Categorize.cpp:81
A PointSymbolizer specifies the rendering of a graphic Symbolizer at a point.
This file contains include headers for TerraLib Symbology Encoding module.
void setCategorize(Categorize *c)
Definition: ColorMap.cpp:67
void push_back(const std::string &semanticTypeIdentifier)
Definition: Style.cpp:75
void setFilter(te::fe::Filter *f)
Definition: Rule.cpp:91
static te::xml::Reader * make()
It creates a new XML reader using the dafault implementation.
TESEEXPORT LineSymbolizer * CreateLineSymbolizer(Stroke *stroke)
Creates a line symbolizer.
TESEEXPORT TextSymbolizer * CreateTextSymbolizer(const std::string &label, Fill *fill, Font *font)
Creates a text symbolizer.
A Graphic is a graphic symbol with an inherent shape, color(s), and possibly size.
Definition: Graphic.h:66
TESEEXPORT PolygonSymbolizer * CreatePolygonSymbolizer(Stroke *stroke, Fill *fill)
Creates a polygon symbolizer.
void push_back(Symbolizer *s)
Definition: Rule.cpp:138
static const char * sm_propertyIsEqualTo
The "ParameterValueType" uses WFS-Filter expressions to give values for SE graphic parameters...
void setMaxScaleDenominator(const double &maxScaleDenominator)
Definition: Rule.cpp:128
void setOp(AbstractOp *o)
It sets the filter main operation (expression).
void setGeometry(te::fe::PropertyName *geometry)
The Geometry element of a PolygonSymbolizer defines the linear geometry to be used for styling...
static Style & getInstance()
It returns a reference to the singleton instance.
The FeatureTypeStyle defines the styling that is to be applied to a dataset that can be viewed as a f...
Data serialization for the XLink module.
This class is used to encode the name of any property of an object.
void setColorCompositionType(ColorCompositionType cct)
void setChannelSelection(ChannelSelection *c)
void setDescription(Description *d)
Definition: Symbolizer.cpp:77
TESEEXPORT Graphic * CreateGraphic(Mark *mark, const std::string &size, const std::string &rotation, const std::string &opacity)
Creates a graphic.
The RasterSymbolizer describes how to render raster/matrix-coverage data (e.g., satellite photos...
This file contains include headers for TerraLib Filter Encoding module.
A Fill specifies the pattern for filling an area geometry.
Definition: Fill.h:59
void setGeometry(te::fe::PropertyName *geometry)
The Geometry element of a LineSymbolizer defines the linear geometry to be used for styling...
void setOpacity(ParameterValue *p)
This class models a XML writer object.
te::se::Style * DecodeStyle(const std::string &path)
It decodes a given OGC Symbology Encoding Style file.
A filter is any valid predicate expression.
Definition: fe/Filter.h:55
TESEEXPORT Mark * CreateMark(const std::string &wellKnownName, Stroke *stroke, Fill *fill)
Creates a mark.
virtual void read(const std::string &fileURI)=0
It prepare the given file to be read.
Support for the Filter serialization.
TESEEXPORT Stroke * CreateStroke(const std::string &color, const std::string &width)
Creates a stroke.
void setGeometry(te::fe::PropertyName *g)
A class for binary comparison operators.
static const char * sm_and
void EncodeStyle(const std::string &path)
It creates an OGC Symbology Encoding Style and encode it to XML format.
This class can be used to represent literal values.
Definition: fe/Literal.h:56
void setName(std::string *name)
Definition: Style.cpp:53
A Rule is used to attach property/scale conditions to and group the individual symbols used for rende...
Definition: Rule.h:76
void setOffset(ParameterValue *p)
This is the abstract factory for XML readers.
A Stroke specifies the appearance of a linear geometry.
Definition: Stroke.h:67
void setColorMap(ColorMap *c)
void setSourceChannelName(const std::string &name)
TESEEXPORT Font * CreateFont(const std::string &family, const std::string &size, const te::se::Font::FontStyleType &style=te::se::Font::StyleNormal, const te::se::Font::FontWeightType &weight=te::se::Font::WeightNormal)
Creates a font.
void setMinScaleDenominator(const double &minScaleDenominator)
Definition: Rule.cpp:118
A LineSymbolizer is used to style a stroke along a linear geometry type, such as a string of line seg...
A logical operator can be used to combine two or more conditional expressions.
Definition: BinaryLogicOp.h:58
TESEEXPORT Description * CreateDescription(const std::string &title, const std::string &abst)
Creates a description.
This is the abstract factory for XML writers.
void setBlueChannel(SelectedChannel *c)
virtual bool next()=0
It gets the next event to be read.
void setThresholdsBelongTo(ThresholdsBelongToType t)
Definition: Categorize.cpp:104
void addThreshold(ParameterValue *v)
Definition: Categorize.cpp:94
A ColorMap defines either the colors of a pallette-type raster source or the mapping of numeric pixel...
Definition: ColorMap.h:61
void addValue(ParameterValue *v)
Definition: Categorize.cpp:99
void setFallbackValue(const std::string &v)
Definition: se/Function.cpp:33
TESEEXPORT PointSymbolizer * CreatePointSymbolizer(Graphic *graphic)
Creates a point symbolizer.
TESEEXPORT Fill * CreateFill(const std::string &color, const std::string &opacity)
Creates a fill.
void setGreenChannel(SelectedChannel *c)
ChannelSelection specifies the false-color channel selection for a multi-spectral raster source (such...