Utils.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/se/Utils.h
22 
23  \brief Utility functions for Symbology Enconding module.
24 
25  \ingroup se
26 */
27 
28 #ifndef __TERRALIB_SE_INTERNAL_UTILS_H
29 #define __TERRALIB_SE_INTERNAL_UTILS_H
30 
31 // TerraLib
32 #include "../color/RGBAColor.h"
33 #include "../geometry/Enums.h"
34 #include "Config.h"
35 #include "Font.h"
36 
37 // STL
38 #include <string>
39 #include <vector>
40 
41 namespace te
42 {
43 // Forward declaration
44  namespace rst { class BandProperty; }
45 
46  namespace se
47  {
48 // Forward declarations
49  class Description;
50  class Fill;
51  class Graphic;
52  class LineSymbolizer;
53  class Mark;
54  class ParameterValue;
55  class PointSymbolizer;
56  class PolygonSymbolizer;
57  class Stroke;
58  class Style;
59  class Symbolizer;
60  class RasterSymbolizer;
61  class TextSymbolizer;
62 
63  /*!
64  \brief Creates a stroke.
65 
66  \param color The stroke color enconded hexadecimal i.e "#FF0000".
67  \param width The stroke width.
68 
69  \return The Symbology Enconding Stroke element.
70 
71  \note The caller of this method will take the ownership of the returned pointer.
72  */
73  TESEEXPORT Stroke* CreateStroke(const std::string& color, const std::string& width);
74 
75  /*!
76  \brief Creates a stroke.
77 
78  \param color The stroke color enconded hexadecimal i.e "#FF0000".
79  \param width The stroke width.
80  \param opacity The stroke opacity [0,1].
81 
82  \return The Symbology Enconding Stroke element.
83 
84  \note The caller of this method will take the ownership of the returned pointer.
85  */
86  TESEEXPORT Stroke* CreateStroke(const std::string& color, const std::string& width, const std::string& opacity);
87 
88  /*!
89  \brief Creates a stroke.
90 
91  \param color The stroke color enconded hexadecimal i.e "#FF0000".
92  \param width The stroke width.
93  \param opacity The stroke opacity [0,1].
94  \param dasharray The stroke dasharray.
95 
96  \return The Symbology Enconding Stroke element.
97 
98  \note The caller of this method will take the ownership of the returned pointer.
99  */
100  TESEEXPORT Stroke* CreateStroke(const std::string& color, const std::string& width,
101  const std::string& opacity, const std::string& dasharray);
102 
103  /*!
104  \brief Creates a stroke.
105 
106  \param color The stroke color enconded hexadecimal i.e "#FF0000".
107  \param width The stroke width.
108  \param opacity The stroke opacity [0,1].
109  \param dasharray The stroke dasharray.
110  \param linecap The stroke linecap {butt, square, round}.
111  \param linejoin The stroke linejoin {miter, bevel, round}.
112 
113  \return The Symbology Enconding Stroke element.
114 
115  \note The caller of this method will take the ownership of the returned pointer.
116  */
117  TESEEXPORT Stroke* CreateStroke(const std::string& color, const std::string& width,
118  const std::string& opacity, const std::string& dasharray,
119  const std::string& linecap, const std::string& linejoin);
120 
121  /*!
122  \brief Creates a stroke.
123 
124  \param graphic The stroke graphic fill.
125  \param width The stroke width.
126  \param opacity The stroke opacity [0,1].
127  \param dasharray The stroke dasharray.
128  \param linecap The stroke linecap {butt, square, round}.
129  \param linejoin The stroke linejoin {miter, bevel, round}.
130 
131  \return The Symbology Enconding Stroke element.
132 
133  \note The caller of this method will take the ownership of the returned pointer.
134  */
135  TESEEXPORT Stroke* CreateStroke(Graphic* graphicFill,
136  const std::string& width, const std::string& opacity,
137  const std::string& dasharray, const std::string& linecap, const std::string& linejoin);
138 
139  /*!
140  \brief Creates a fill.
141 
142  \param color The fill color enconded hexadecimal i.e "#FF0000".
143  \param opacity The fill opacity.
144 
145  \return The Symbology Enconding Fill element.
146 
147  \note The caller of this method will take the ownership of the returned pointer.
148  */
149  TESEEXPORT Fill* CreateFill(const std::string& color, const std::string& opacity);
150 
151  /*!
152  \brief Creates a fill.
153 
154  \param graphic The graphic fill.
155 
156  \return The Symbology Enconding Fill element.
157 
158  \note The caller of this method will take the ownership of the returned pointer.
159  */
160  TESEEXPORT Fill* CreateFill(Graphic* graphicFill);
161 
162  /*!
163  \brief Creates a mark.
164 
165  \param wellKnownName The mark well-known name.
166  \param stroke The mark stroke.
167  \param fill The mark fill.
168 
169  \return The Symbology Enconding Mark element.
170 
171  \note The caller of this method will take the ownership of the returned pointer.
172  */
173  TESEEXPORT Mark* CreateMark(const std::string& wellKnownName, Stroke* stroke, Fill* fill);
174 
175  /*!
176  \brief Creates a graphic.
177 
178  \param mark The graphic mark.
179  \param size The graphic size.
180  \param rotation The graphic rotation.
181  \param opacity The graphic opacity.
182 
183  \return The Symbology Enconding Graphic element.
184 
185  \note The caller of this method will take the ownership of the returned pointer.
186  */
187  TESEEXPORT Graphic* CreateGraphic(Mark* mark, const std::string& size, const std::string& rotation, const std::string& opacity);
188 
189  /*!
190  \brief Creates a polygon symbolizer.
191 
192  \param stroke The polygon symbolizer stroke.
193  \param fill The polygon symbolizer fill.
194 
195  \return The Symbology Enconding PolygonSymbolizer element.
196 
197  \note The caller of this method will take the ownership of the returned pointer.
198  */
199  TESEEXPORT PolygonSymbolizer* CreatePolygonSymbolizer(Stroke* stroke, Fill* fill);
200 
201  /*!
202  \brief Creates a line symbolizer.
203 
204  \param stroke The line symbolizer stroke.
205 
206  \return The Symbology Enconding LineSymbolizer element.
207 
208  \note The caller of this method will take the ownership of the returned pointer.
209  */
210  TESEEXPORT LineSymbolizer* CreateLineSymbolizer(Stroke* stroke);
211 
212  /*!
213  \brief Creates a point symbolizer.
214 
215  \param graphic The point symbolizer graphic.
216 
217  \return The Symbology Enconding PointSymbolizer element.
218 
219  \note The caller of this method will take the ownership of the returned pointer.
220  */
221  TESEEXPORT PointSymbolizer* CreatePointSymbolizer(Graphic* graphic);
222 
223  /*!
224  \brief Creates a font.
225 
226  \param family The font family.
227  \param size The font size.
228  \param style The font style.
229  \param weight The font weight.
230 
231  \return The Symbology Enconding Font element.
232 
233  \note The caller of this method will take the ownership of the returned pointer.
234  */
235  TESEEXPORT Font* CreateFont(const std::string& family, const std::string& size,
238 
239  /*!
240  \brief Creates a text symbolizer.
241 
242  \param label The property name that will be labelled.
243  \param fill The text symbolizer fill.
244  \param font The text symbolizer font.
245 
246  \return The Symbology Enconding TextSymbolizer element.
247 
248  \note The caller of this method will take the ownership of the returned pointer.
249  */
250  TESEEXPORT TextSymbolizer* CreateTextSymbolizer(const std::string& label, Fill* fill, Font* font);
251 
252  /*!
253  \brief Creates a description.
254 
255  \param title The title of description.
256  \param abst The abstratc of description.
257 
258  \return The Symbology Enconding Description element.
259 
260  \note The caller of this method will take the ownership of the returned pointer.
261  */
262  TESEEXPORT Description* CreateDescription(const std::string& title, const std::string& abst);
263 
264  /*!
265  \brief Try creates an appropriate symbolizer based on given geometry type.
266 
267  \param geomType The geometry type.
268 
269  \return A symbolizer based on given geometry type.
270 
271  \note Random colors will be generated.
272  \note The caller of this method will take the ownership of the returned pointer.
273  \note The method will return a NULL pointer if a default symbolizer could not be created.
274  */
275  TESEEXPORT Symbolizer* CreateSymbolizer(const te::gm::GeomType& geomType);
276 
277  /*!
278  \brief Try creates an appropriate symbolizer based on given geometry type and a default color.
279 
280  \param geomType The geometry type.
281  \param color The fill color enconded hexadecimal i.e "#FF0000".
282 
283  \return A symbolizer based on given geometry type.
284 
285  \note The caller of this method will take the ownership of the returned pointer.
286  \note The method will return a NULL pointer if a default symbolizer could not be created.
287  */
288  TESEEXPORT Symbolizer* CreateSymbolizer(const te::gm::GeomType& geomType, const std::string& color);
289 
290  /*!
291  \brief Try creates an appropriate feature type style based on given geometry type.
292 
293  \param geomType The geometry type.
294 
295  \return A feature type style based on given geometry type.
296 
297  \note The caller of this method will take the ownership of the returned pointer.
298  \note The method will return a NULL pointer if a default style could not be created.
299  */
300  TESEEXPORT Style* CreateFeatureTypeStyle(const te::gm::GeomType& geomType);
301 
302  /*!
303  \brief Try creates an appropriate coverage style based on given band properties.
304 
305  \param properties The band properties.
306 
307  \return A coverage style based on given geometry type.
308 
309  \note The caller of this method will take the ownership of the returned pointer.
310  \note The method will return a NULL pointer if a default style could not be created.
311 
312  \todo Review this method in order to extract the maximum information about the given band properties.
313  */
314  TESEEXPORT Style* CreateCoverageStyle(const std::vector<te::rst::BandProperty*>& properties);
315 
316  /*!
317  \brief Try creates an appropriate coverage style based on given number of bands.
318 
319  \param nBands The number of bands.
320 
321  \return A coverage style based on given geometry type.
322 
323  \note The caller of this method will take the ownership of the returned pointer.
324  \note The method will return a NULL pointer if a default style could not be created.
325  */
326  TESEEXPORT Style* CreateCoverageStyle(const std::size_t& nBands);
327 
328  /*!
329  \brief Try creates an appropriate raster symbolizer style based on given number of bands.
330 
331  \param nBands The number of bands.
332 
333  \return A raster symbolizer based on number of bands.
334 
335  \note The caller of this method will take the ownership of the returned pointer.
336  \note The method will return a NULL pointer if a default raster symbolizer could not be created.
337  */
338  TESEEXPORT RasterSymbolizer* CreateRasterSymbolizer(const std::size_t& nBands);
339 
340  /*!
341  \brief Try to get raster symbolizer from a style.
342 
343  \param s Style.
344 
345  \return A raster symbolizer.
346 
347  \note The method will return a NULL pointer if the symbolizer does not have a raster symbolizer.
348  */
349  TESEEXPORT RasterSymbolizer* GetRasterSymbolizer(Style* s);
350 
351  /*!
352  \brief Creates a random RGB color encoded using two hexadecimal digits per primary-color component prefixed with a hash (#) sign.
353 
354  \return A random color encoded using two hexadecimal digits per primary-color component prefixed with a hash (#) sign.
355  */
356  TESEEXPORT std::string GenerateRandomColor();
357 
358 
359  /*!
360  \brief It gets the RGBA color from the Stroke element.
361 
362  \param stroke The Symbology Enconding Stroke element.
363  \param color A pre-created color that will be filled with the values extracted from Stroke.
364 
365  \note The given color will be altered based on "stroke" and "stroke-opacity" attributes, if availables.
366  */
367  TESEEXPORT void GetColor(const te::se::Stroke* stroke, te::color::RGBAColor& color);
368 
369  /*!
370  \brief It gets the RGBA color from the Fill element.
371 
372  \param fill The Symbology Enconding Fill element.
373  \param color A pre-created color that will be filled with the values extracted from Fill.
374 
375  \note The given color will be altered based on "fill" and "fill-opacity" attributes, if availables.
376  */
377  TESEEXPORT void GetColor(const te::se::Fill* fill, te::color::RGBAColor& color);
378 
379  /*!
380  \brief It gets the RGBA color from the parameter values.
381 
382  \param color The Symbology Enconding Parameter Value element that represents the color.
383  \param opacity The Symbology Enconding Parameter Value element that represents the opacity.
384  \param color A pre-created color that will be filled with the values extracted from color and opacity.
385 
386  \note The given color will be altered based on "color" and "opacity" parameters, if availables.
387  \note Warning: It considers that the paramater value is enconded using a Literal OGC Filter expression.
388  */
390 
391  /*!
392  \brief It gets the parameter value as a RGBA color.
393 
394  \param param The Symbology Enconding Parameter Value element.
395 
396  \return The RGBA color.
397 
398  \note Warning: It considers that the paramater value is enconded using a Literal OGC Filter expression.
399  */
401 
402  /*!
403  \brief It gets the parameter value as an integer.
404 
405  \param param The Symbology Enconding Parameter Value element.
406 
407  \return The integer value.
408 
409  \note Warning: It considers that the paramater value is enconded using a Literal OGC Filter expression.
410  */
411  TESEEXPORT int GetInt(const te::se::ParameterValue* param);
412 
413  /*!
414  \brief It gets the parameter value as a double.
415 
416  \param param The Symbology Encoding Parameter Value element.
417 
418  \return The double value.
419 
420  \note Warning: It considers that the paramater value is enconded using a Literal OGC Filter expression.
421  */
422  TESEEXPORT double GetDouble(const te::se::ParameterValue* param);
423 
424  /*!
425  \brief It gets the parameter value as a string.
426 
427  \param param The Symbology Encoding Parameter Value element.
428 
429  \return The string value.
430 
431  \note Warning: It considers that the paramater value is encoded using a Literal OGC Filter expression.
432  */
433  TESEEXPORT std::string GetString(const te::se::ParameterValue* param);
434 
435 
436  } // end namespace se
437 } // end namespace te
438 
439 #endif // __TERRALIB_SE_INTERNAL_UTILS_H
A Font specifies the text font to use in a text symbolizer.
TESEEXPORT std::string GenerateRandomColor()
Creates a random RGB color encoded using two hexadecimal digits per primary-color component prefixed ...
TESEEXPORT double GetDouble(const te::se::ParameterValue *param)
It gets the parameter value as a double.
GeomType
Each enumerated type is compatible with a Well-known Binary (WKB) type code.
Definition: Enums.h:41
TESEEXPORT Mark * CreateMark(const std::string &wellKnownName, Stroke *stroke, Fill *fill)
Creates a mark.
TESEEXPORT void GetColor(const te::se::Stroke *stroke, te::color::RGBAColor &color)
It gets the RGBA color from the Stroke element.
TESEEXPORT LineSymbolizer * CreateLineSymbolizer(Stroke *stroke)
Creates a line symbolizer.
TESEEXPORT RasterSymbolizer * CreateRasterSymbolizer(const std::size_t &nBands)
Try creates an appropriate raster symbolizer style based on given number of bands.
TESEEXPORT std::string GetString(const te::se::ParameterValue *param)
It gets the parameter value as a string.
TESEEXPORT RasterSymbolizer * GetRasterSymbolizer(Style *s)
Try to get raster symbolizer from a style.
TESEEXPORT Stroke * CreateStroke(const std::string &color, const std::string &width)
Creates a stroke.
TESEEXPORT Style * CreateFeatureTypeStyle(const te::gm::GeomType &geomType)
Try creates an appropriate feature type style based on given geometry type.
TESEEXPORT Symbolizer * CreateSymbolizer(const te::gm::GeomType &geomType)
Try creates an appropriate symbolizer based on given geometry type.
The "ParameterValueType" uses WFS-Filter expressions to give values for SE graphic parameters...
TESEEXPORT PointSymbolizer * CreatePointSymbolizer(Graphic *graphic)
Creates a point symbolizer.
TESEEXPORT TextSymbolizer * CreateTextSymbolizer(const std::string &label, Fill *fill, Font *font)
Creates a text symbolizer.
TESEEXPORT Fill * CreateFill(const std::string &color, const std::string &opacity)
Creates a fill.
URI C++ Library.
A Fill specifies the pattern for filling an area geometry.
Definition: Fill.h:59
FontStyleType
It defines the style to use for a font.
Definition: Font.h:72
#define TESEEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:187
Configuration flags for the Symbology Encoding support of TerraLib.
TESEEXPORT Description * CreateDescription(const std::string &title, const std::string &abst)
Creates a description.
A Stroke specifies the appearance of a linear geometry.
Definition: Stroke.h:67
TESEEXPORT PolygonSymbolizer * CreatePolygonSymbolizer(Stroke *stroke, Fill *fill)
Creates a polygon symbolizer.
A helper class for 32-bit RGBA (Red-Green-Blue-Alpha channel) color.
Definition: RGBAColor.h:57
FontWeightType
It gives the amount of weight or boldness to use for a font.
Definition: Font.h:84
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.
TESEEXPORT Graphic * CreateGraphic(Mark *mark, const std::string &size, const std::string &rotation, const std::string &opacity)
Creates a graphic.
TESEEXPORT Style * CreateCoverageStyle(const std::vector< te::rst::BandProperty * > &properties)
Try creates an appropriate coverage style based on given band properties.
TESEEXPORT int GetInt(const te::se::ParameterValue *param)
It gets the parameter value as an integer.