All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Utils.h
Go to the documentation of this file.
1 /* Copyright (C) 2001-2009 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 "../geometry/Enums.h"
33 #include "Config.h"
34 #include "Font.h"
35 
36 // STL
37 #include <string>
38 #include <vector>
39 
40 namespace te
41 {
42 // Forward declaration
43  namespace rst { class BandProperty; }
44 
45  namespace se
46  {
47 // Forward declarations
48  class Description;
49  class Fill;
50  class Graphic;
51  class LineSymbolizer;
52  class Mark;
53  class PointSymbolizer;
54  class PolygonSymbolizer;
55  class Stroke;
56  class Style;
57  class Symbolizer;
58  class RasterSymbolizer;
59  class TextSymbolizer;
60 
61  /*!
62  \brief Creates a stroke.
63 
64  \param color The stroke color enconded hexadecimal i.e "#FF0000".
65  \param width The stroke width.
66 
67  \return The Symbology Enconding Stroke element.
68 
69  \note The caller of this method will take the ownership of the returned pointer.
70  */
71  TESEEXPORT Stroke* CreateStroke(const std::string& color, const std::string& width);
72 
73  /*!
74  \brief Creates a stroke.
75 
76  \param color The stroke color enconded hexadecimal i.e "#FF0000".
77  \param width The stroke width.
78  \param opacity The stroke opacity [0,1].
79 
80  \return The Symbology Enconding Stroke element.
81 
82  \note The caller of this method will take the ownership of the returned pointer.
83  */
84  TESEEXPORT Stroke* CreateStroke(const std::string& color, const std::string& width, const std::string& opacity);
85 
86  /*!
87  \brief Creates a stroke.
88 
89  \param color The stroke color enconded hexadecimal i.e "#FF0000".
90  \param width The stroke width.
91  \param opacity The stroke opacity [0,1].
92  \param dasharray The stroke dasharray.
93 
94  \return The Symbology Enconding Stroke element.
95 
96  \note The caller of this method will take the ownership of the returned pointer.
97  */
98  TESEEXPORT Stroke* CreateStroke(const std::string& color, const std::string& width,
99  const std::string& opacity, const std::string& dasharray);
100 
101  /*!
102  \brief Creates a stroke.
103 
104  \param color The stroke color enconded hexadecimal i.e "#FF0000".
105  \param width The stroke width.
106  \param opacity The stroke opacity [0,1].
107  \param dasharray The stroke dasharray.
108  \param linecap The stroke linecap {butt, square, round}.
109  \param linejoin The stroke linejoin {miter, bevel, round}.
110 
111  \return The Symbology Enconding Stroke element.
112 
113  \note The caller of this method will take the ownership of the returned pointer.
114  */
115  TESEEXPORT Stroke* CreateStroke(const std::string& color, const std::string& width,
116  const std::string& opacity, const std::string& dasharray,
117  const std::string& linecap, const std::string& linejoin);
118 
119  /*!
120  \brief Creates a stroke.
121 
122  \param graphic The stroke graphic fill.
123  \param width The stroke width.
124  \param opacity The stroke opacity [0,1].
125  \param dasharray The stroke dasharray.
126  \param linecap The stroke linecap {butt, square, round}.
127  \param linejoin The stroke linejoin {miter, bevel, round}.
128 
129  \return The Symbology Enconding Stroke element.
130 
131  \note The caller of this method will take the ownership of the returned pointer.
132  */
133  TESEEXPORT Stroke* CreateStroke(Graphic* graphicFill,
134  const std::string& width, const std::string& opacity,
135  const std::string& dasharray, const std::string& linecap, const std::string& linejoin);
136 
137  /*!
138  \brief Creates a fill.
139 
140  \param color The fill color enconded hexadecimal i.e "#FF0000".
141  \param opacity The fill opacity.
142 
143  \return The Symbology Enconding Fill element.
144 
145  \note The caller of this method will take the ownership of the returned pointer.
146  */
147  TESEEXPORT Fill* CreateFill(const std::string& color, const std::string& opacity);
148 
149  /*!
150  \brief Creates a fill.
151 
152  \param graphic The graphic fill.
153 
154  \return The Symbology Enconding Fill element.
155 
156  \note The caller of this method will take the ownership of the returned pointer.
157  */
158  TESEEXPORT Fill* CreateFill(Graphic* graphicFill);
159 
160  /*!
161  \brief Creates a mark.
162 
163  \param wellKnownName The mark well-known name.
164  \param stroke The mark stroke.
165  \param fill The mark fill.
166 
167  \return The Symbology Enconding Mark element.
168 
169  \note The caller of this method will take the ownership of the returned pointer.
170  */
171  TESEEXPORT Mark* CreateMark(const std::string& wellKnownName, Stroke* stroke, Fill* fill);
172 
173  /*!
174  \brief Creates a graphic.
175 
176  \param mark The graphic mark.
177  \param size The graphic size.
178  \param rotation The graphic rotation.
179  \param opacity The graphic opacity.
180 
181  \return The Symbology Enconding Graphic element.
182 
183  \note The caller of this method will take the ownership of the returned pointer.
184  */
185  TESEEXPORT Graphic* CreateGraphic(Mark* mark, const std::string& size, const std::string& rotation, const std::string& opacity);
186 
187  /*!
188  \brief Creates a polygon symbolizer.
189 
190  \param stroke The polygon symbolizer stroke.
191  \param fill The polygon symbolizer fill.
192 
193  \return The Symbology Enconding PolygonSymbolizer element.
194 
195  \note The caller of this method will take the ownership of the returned pointer.
196  */
197  TESEEXPORT PolygonSymbolizer* CreatePolygonSymbolizer(Stroke* stroke, Fill* fill);
198 
199  /*!
200  \brief Creates a line symbolizer.
201 
202  \param stroke The line symbolizer stroke.
203 
204  \return The Symbology Enconding LineSymbolizer element.
205 
206  \note The caller of this method will take the ownership of the returned pointer.
207  */
208  TESEEXPORT LineSymbolizer* CreateLineSymbolizer(Stroke* stroke);
209 
210  /*!
211  \brief Creates a point symbolizer.
212 
213  \param graphic The point symbolizer graphic.
214 
215  \return The Symbology Enconding PointSymbolizer element.
216 
217  \note The caller of this method will take the ownership of the returned pointer.
218  */
219  TESEEXPORT PointSymbolizer* CreatePointSymbolizer(Graphic* graphic);
220 
221  /*!
222  \brief Creates a font.
223 
224  \param family The font family.
225  \param size The font size.
226  \param style The font style.
227  \param weight The font weight.
228 
229  \return The Symbology Enconding Font element.
230 
231  \note The caller of this method will take the ownership of the returned pointer.
232  */
233  TESEEXPORT Font* CreateFont(const std::string& family, const std::string& size,
236 
237  /*!
238  \brief Creates a text symbolizer.
239 
240  \param label The property name that will be labelled.
241  \param fill The text symbolizer fill.
242  \param font The text symbolizer font.
243 
244  \return The Symbology Enconding TextSymbolizer element.
245 
246  \note The caller of this method will take the ownership of the returned pointer.
247  */
248  TESEEXPORT TextSymbolizer* CreateTextSymbolizer(const std::string& label, Fill* fill, Font* font);
249 
250  /*!
251  \brief Creates a description.
252 
253  \param title The title of description.
254  \param abst The abstratc of description.
255 
256  \return The Symbology Enconding Description element.
257 
258  \note The caller of this method will take the ownership of the returned pointer.
259  */
260  TESEEXPORT Description* CreateDescription(const std::string& title, const std::string& abst);
261 
262  /*!
263  \brief Try creates an appropriate symbolizer based on given geometry type.
264 
265  \param geomType The geometry type.
266 
267  \return A symbolizer based on given geometry type.
268 
269  \note Random colors will be generated.
270  \note The caller of this method will take the ownership of the returned pointer.
271  \note The method will return a NULL pointer if a default symbolizer could not be created.
272  */
273  TESEEXPORT Symbolizer* CreateSymbolizer(const te::gm::GeomType& geomType);
274 
275  /*!
276  \brief Try creates an appropriate symbolizer based on given geometry type and a default color.
277 
278  \param geomType The geometry type.
279  \param color The fill color enconded hexadecimal i.e "#FF0000".
280 
281  \return A symbolizer based on given geometry type.
282 
283  \note The caller of this method will take the ownership of the returned pointer.
284  \note The method will return a NULL pointer if a default symbolizer could not be created.
285  */
286  TESEEXPORT Symbolizer* CreateSymbolizer(const te::gm::GeomType& geomType, const std::string& color);
287 
288  /*!
289  \brief Try creates an appropriate feature type style based on given geometry type.
290 
291  \param geomType The geometry type.
292 
293  \return A feature type style based on given geometry type.
294 
295  \note The caller of this method will take the ownership of the returned pointer.
296  \note The method will return a NULL pointer if a default style could not be created.
297  */
298  TESEEXPORT Style* CreateFeatureTypeStyle(const te::gm::GeomType& geomType);
299 
300  /*!
301  \brief Try creates an appropriate coverage style based on given band properties.
302 
303  \param properties The band properties.
304 
305  \return A coverage style based on given geometry type.
306 
307  \note The caller of this method will take the ownership of the returned pointer.
308  \note The method will return a NULL pointer if a default style could not be created.
309 
310  \todo Review this method in order to extract the maximum information about the given band properties.
311  */
312  TESEEXPORT Style* CreateCoverageStyle(const std::vector<te::rst::BandProperty*>& properties);
313 
314  /*!
315  \brief Try creates an appropriate coverage style based on given number of bands.
316 
317  \param nBands The number of bands.
318 
319  \return A coverage style based on given geometry type.
320 
321  \note The caller of this method will take the ownership of the returned pointer.
322  \note The method will return a NULL pointer if a default style could not be created.
323  */
324  TESEEXPORT Style* CreateCoverageStyle(const std::size_t& nBands);
325 
326  /*!
327  \brief Try creates an appropriate raster symbolizer style based on given number of bands.
328 
329  \param nBands The number of bands.
330 
331  \return A raster symbolizer based on number of bands.
332 
333  \note The caller of this method will take the ownership of the returned pointer.
334  \note The method will return a NULL pointer if a default raster symbolizer could not be created.
335  */
336  TESEEXPORT RasterSymbolizer* CreateRasterSymbolizer(const std::size_t& nBands);
337 
338  /*!
339  \brief Try to get raster symbolizer from a style.
340 
341  \param s Style.
342 
343  \return A raster symbolizer.
344 
345  \note The method will return a NULL pointer if the symbolizer does not have a raster symbolizer.
346  */
347  TESEEXPORT RasterSymbolizer* GetRasterSymbolizer(Style* s);
348 
349  /*!
350  \brief Creates a random RGB color encoded using two hexadecimal digits per primary-color component prefixed with a hash (#) sign.
351 
352  \return A random color encoded using two hexadecimal digits per primary-color component prefixed with a hash (#) sign.
353  */
354  TESEEXPORT std::string GenerateRandomColor();
355 
356  } // end namespace se
357 } // end namespace te
358 
359 #endif // __TERRALIB_SE_INTERNAL_UTILS_H
TESEEXPORT Fill * CreateFill(const std::string &color, const std::string &opacity)
Creates a fill.
Definition: Utils.cpp:107
FontStyleType
It defines the style to use for a font.
Definition: Font.h:72
TESEEXPORT TextSymbolizer * CreateTextSymbolizer(const std::string &label, Fill *fill, Font *font)
Creates a text symbolizer.
Definition: Utils.cpp:199
TESEEXPORT PointSymbolizer * CreatePointSymbolizer(Graphic *graphic)
Creates a point symbolizer.
Definition: Utils.cpp:180
TESEEXPORT Graphic * CreateGraphic(Mark *mark, const std::string &size, const std::string &rotation, const std::string &opacity)
Creates a graphic.
Definition: Utils.cpp:140
TESEEXPORT LineSymbolizer * CreateLineSymbolizer(Stroke *stroke)
Creates a line symbolizer.
Definition: Utils.cpp:170
TESEEXPORT Mark * CreateMark(const std::string &wellKnownName, Stroke *stroke, Fill *fill)
Creates a mark.
Definition: Utils.cpp:128
Configuration flags for the Symbology Encoding support of TerraLib.
FontWeightType
It gives the amount of weight or boldness to use for a font.
Definition: Font.h:84
TESEEXPORT Style * CreateFeatureTypeStyle(const te::gm::GeomType &geomType)
Try creates an appropriate feature type style based on given geometry type.
Definition: Utils.cpp:282
TESEEXPORT Stroke * CreateStroke(const std::string &color, const std::string &width)
Creates a stroke.
Definition: Utils.cpp:52
TESEEXPORT Style * CreateCoverageStyle(const std::vector< te::rst::BandProperty * > &properties)
Try creates an appropriate coverage style based on given band properties.
Definition: Utils.cpp:297
TESEEXPORT Symbolizer * CreateSymbolizer(const te::gm::GeomType &geomType)
Try creates an appropriate symbolizer based on given geometry type.
Definition: Utils.cpp:218
GeomType
Each enumerated type is compatible with a Well-known Binary (WKB) type code.
Definition: Enums.h:41
TESEEXPORT Description * CreateDescription(const std::string &title, const std::string &abst)
Creates a description.
Definition: Utils.cpp:209
A Font specifies the text font to use in a text symbolizer.
TESEEXPORT RasterSymbolizer * GetRasterSymbolizer(Style *s)
Try to get raster symbolizer from a style.
Definition: Utils.cpp:369
TESEEXPORT PolygonSymbolizer * CreatePolygonSymbolizer(Stroke *stroke, Fill *fill)
Creates a polygon symbolizer.
Definition: Utils.cpp:157
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.
Definition: Utils.cpp:188
TESEEXPORT std::string GenerateRandomColor()
Creates a random RGB color encoded using two hexadecimal digits per primary-color component prefixed ...
Definition: Utils.cpp:392
#define TESEEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:224
TESEEXPORT RasterSymbolizer * CreateRasterSymbolizer(const std::size_t &nBands)
Try creates an appropriate raster symbolizer style based on given number of bands.
Definition: Utils.cpp:321