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/maptools/Utils.h
22 
23  \brief Utility functions for MapTools module.
24 
25  \ingroup map
26 */
27 
28 #ifndef __TERRALIB_MAPTOOLS_INTERNAL_UTILS_H
29 #define __TERRALIB_MAPTOOLS_INTERNAL_UTILS_H
30 
31 // TerraLib
32 #include "../color/RGBAColor.h"
33 #include "../dataaccess/datasource/DataSource.h"
34 #include "../geometry/Enums.h"
35 #include "../geometry/Envelope.h"
36 #include "../raster/Raster.h"
37 #include "AbstractLayer.h"
38 #include "Config.h"
39 
40 // STL
41 #include <list>
42 #include <string>
43 #include <vector>
44 
45 namespace te
46 {
47 // Forward declarations
48  namespace common
49  {
50  class TaskProgress;
51  }
52 
53  namespace da
54  {
55  class DataSet;
56  class DataSetType;
57  }
58 
59  namespace rst
60  {
61  class RasterProperty;
62  }
63 
64  namespace se
65  {
66  class CoverageStyle;
67  class FeatureTypeStyle;
68  class Fill;
69  class ParameterValue;
70  class RasterSymbolizer;
71  class Stroke;
72  }
73 
74  namespace map
75  {
76 // Forward declaration
77  class DataSetLayer;
78 
79  /*!
80  \brief Gets the RGBA color from Stroke element.
81 
82  \param stroke The Symbology Enconding Stroke element.
83  \param color A pre-created color that will be filled with the values extracted from Stroke.
84 
85  \note The given color will be altered based on "stroke" and "stroke-opacity" attributes, if availables.
86  */
87  TEMAPEXPORT void GetColor(const te::se::Stroke* stroke, te::color::RGBAColor& color);
88 
89  /*!
90  \brief Gets the RGBA color from Fill element.
91 
92  \param fill The Symbology Enconding Fill element.
93  \param color A pre-created color that will be filled with the values extracted from Fill.
94 
95  \note The given color will be altered based on "fill" and "fill-opacity" attributes, if availables.
96  */
97  TEMAPEXPORT void GetColor(const te::se::Fill* fill, te::color::RGBAColor& color);
98 
99  /*!
100  \brief Gets the RGBA color from parameter values.
101 
102  \param color The Symbology Enconding Parameter Value element that represents the color.
103  \param opacity The Symbology Enconding Parameter Value element that represents the opacity.
104  \param color A pre-created color that will be filled with the values extracted from color and opacity.
105 
106  \note The given color will be altered based on "color" and "opacity" parameters, if availables.
107  \note Warning: It consider that the paramater value is enconded using a Literal OGC Filter expression.
108  */
110 
111  /*!
112  \brief Gets the parameter value as RGBA color.
113 
114  \param param The Symbology Enconding Parameter Value element.
115 
116  \return The RGBA color.
117 
118  \note Warning: It consider that the paramater value is enconded using a Literal OGC Filter expression.
119  */
121 
122  /*!
123  \brief Gets the parameter value as integer.
124 
125  \param param The Symbology Enconding Parameter Value element.
126 
127  \return The integer value.
128 
129  \note Warning: It consider that the paramater value is enconded using a Literal OGC Filter expression.
130  */
131  TEMAPEXPORT int GetInt(const te::se::ParameterValue* param);
132 
133  /*!
134  \brief Gets the parameter value as double.
135 
136  \param param The Symbology Enconding Parameter Value element.
137 
138  \return The double value.
139 
140  \note Warning: It consider that the paramater value is enconded using a Literal OGC Filter expression.
141  */
142  TEMAPEXPORT double GetDouble(const te::se::ParameterValue* param);
143 
144  /*!
145  \brief Gets the parameter value as string.
146 
147  \param param The Symbology Enconding Parameter Value element.
148 
149  \return The string value.
150 
151  \note Warning: It consider that the paramater value is enconded using a Literal OGC Filter expression.
152  */
153  TEMAPEXPORT std::string GetString(const te::se::ParameterValue* param);
154 
155  /*!
156  \brief It calculates the extent of selected objects of the given layers in the given SRID.
157 
158  \param layers The layer list that will be consulted.
159  \param srid The result extent SRID.
160  \param onlyVisibles A flag that indicates if the method should consider only the visible layers.
161 
162  \return The extent of selected objects of the given layers in the given SRID.
163 
164  \note This method considers the children of layers.
165  */
166  TEMAPEXPORT te::gm::Envelope GetSelectedExtent(const std::list<te::map::AbstractLayerPtr> layers, int srid, bool onlyVisibles);
167 
168  /*!
169  \brief It calculates the extent of selected objects of the given layer in the given SRID.
170 
171  \param layer The layer that will be consulted.
172  \param srid The result extent SRID.
173  \param onlyVisibles A flag that indicates if the method should consider only the visible layers.
174 
175  \return The extent of the selected objects of the given layer in the given SRID.
176 
177  \note This method considers the children of layers.
178  */
179  TEMAPEXPORT te::gm::Envelope GetSelectedExtent(const te::map::AbstractLayerPtr layer, int srid, bool onlyVisibles);
180 
181  /*!
182  \brief Converts a dasharray pattern coded by a string to a vector of double.
183 
184  \param dasharray The dasharray pattern coded by a string.
185  \param style The vector of double that will be filled with the values extracted from dasharray string.
186 
187  \note The dasharray should be specified as an even number of positive values separated by blank space. i.e "10 5 3 4"
188  Here, the values "10" and "3" (in uom) are dashes and the values "5" and "4" are spaces (in uom).
189  The given vector style will be filled with the values: style[0] = 10; style[1] = 5; style[2] = 3; style[3] = 4.
190  */
191  TEMAPEXPORT void GetDashStyle(const std::string& dasharray, std::vector<double>& style);
192 
193  /*!
194  \brief It gets the raster property referenced by the given data set layer.
195 
196  \param layer The data set layer that will be used to retrieve the raster property.
197 
198  \return The raster property referenced by the data set layer.
199 
200  \note The caller will take the ownership of the returned pointer.
201 
202  \exception Exception It will throw an exception if the raster property could not be retrieved.
203  */
205 
206  /*!
207  \brief It gets the raster referenced by the given data set layer.
208 
209  \param layer The data set layer that will be used to retrieve the raster.
210 
211  \return The raster referenced by the data set layer.
212 
213  \note The caller will take the ownership of the returned pointer.
214 
215  \exception Exception It will throw an exception if the raster could not be retrieved.
216  */
217  TEMAPEXPORT te::rst::Raster* GetRaster(DataSetLayer* layer);
218 
219  /*!
220  \brief It gets the visible layers of the given layer list.
221 
222  \param layers The layer list that will be consulted.
223  \param visibleLayers A layer list that will be filled with the visible layers.
224  */
225  TEMAPEXPORT void GetVisibleLayers(const std::list<te::map::AbstractLayerPtr>& layers, std::list<te::map::AbstractLayerPtr>& visibleLayers);
226 
227  /*!
228  \brief It gets the visible layers of the given layer.
229 
230  \param layer The layer that will be consulted.
231  \param visibleLayers A layer list that will be filled with the visible layers.
232  */
233  TEMAPEXPORT void GetVisibleLayers(const te::map::AbstractLayerPtr& layer, std::list<te::map::AbstractLayerPtr>& visibleLayers);
234 
235  /*!
236  \brief It calculates the extent of the given layers in the given SRID.
237 
238  \param layers The layer list that will be consulted.
239  \param srid The result extent SRID.
240  \param onlyVisibles A flag that indicates if the method should consider only the visible layers.
241 
242  \return The extent of the given layers in the given SRID.
243 
244  \note This method considers the children of layers.
245  */
246  TEMAPEXPORT te::gm::Envelope GetExtent(const std::list<te::map::AbstractLayerPtr>& layers, int srid, bool onlyVisibles);
247 
248  /*!
249  \brief It calculates the extent of the given layer in the given SRID.
250 
251  \param layer The layer that will be consulted.
252  \param srid The result extent SRID.
253  \param onlyVisibles A flag that indicates if the method should consider only the visible layers.
254 
255  \return The extent of the given layer in the given SRID.
256 
257  \note This method considers the children of layer.
258  */
259  TEMAPEXPORT te::gm::Envelope GetExtent(const te::map::AbstractLayerPtr& layer, int srid, bool onlyVisibles);
260 
261  /*!
262  \brief It creates a new In-Memory dataset with the items from the given dataset.
263 
264  \param dataset The dataset which will provide the items. Do not pass NULL!
265 
266  \return A new In-Memory dataset.
267 
268  \note The new dataset will not have a transactor associated to it.
269 
270  \note To copy all items the caller is responsible for informing the
271  dataset in the right position. i.e. at before begin.
272 
273  \note The caller will take the ownership of the returned pointer.
274  */
276 
277  /*!
278  \brief It draws the data set geometries in the given canvas using the informed SRID and style.
279 
280  The informed bounding box (bbox) is used to constraint the data set to be drawn.
281  Here, we assume that the given bbox was pre-processed. i.e. the bbox was clipped and contains the same projection of data set geometries.
282 
283  \param type The data set type that describes the data set that will be drawn.
284  \param ds A datasource that will be used to retrieve the data set objects.
285  \param canvas The canvas were the data set geometries will be drawn.
286  \param bbox The interest area to render the geometries.
287  \param bboxSRID The SRID of interest area.
288  \param srid The SRID to be used to draw the data set geometries.
289  \param style The style that will be used.
290  */
292  const te::gm::Envelope& bbox, int bboxSRID,
293  int srid, te::se::FeatureTypeStyle* style);
294 
295  /*!
296  \brief It draws the data set geometries in the given canvas using the informed SRS.
297 
298  \param dataset The data set that will be drawn.
299  \param gpos The geometry property position that will be drawn.
300  \param canvas The canvas were the data set geometries will be drawn.
301  \param fromSRID The SRID of data set geometries.
302  \param srid The SRID to be used to draw the data set geometries.
303  \param task An optional task that can be used cancel the draw process.
304  */
305  TEMAPEXPORT void DrawGeometries(te::da::DataSet* dataset, const std::size_t& gpos,
306  Canvas* canvas, int fromSRID, int toSRID, te::common::TaskProgress* task = 0);
307 
308  TEMAPEXPORT void DrawRaster(te::da::DataSetType* type, te::da::DataSourcePtr ds, Canvas* canvas,
309  const te::gm::Envelope& bbox, int bboxSRID, const te::gm::Envelope& visibleArea, int srid, te::se::CoverageStyle* style);
310 
311  TEMAPEXPORT void DrawRaster(te::rst::Raster* raster, Canvas* canvas, const te::gm::Envelope& bbox, int bboxSRID,
312  const te::gm::Envelope& visibleArea, int srid, te::se::CoverageStyle* style);
313 
314  TEMAPEXPORT te::rst::Raster* GetExtentRaster(te::rst::Raster* raster, int w, int h, const te::gm::Envelope& bbox, int bboxSRID,
315  const te::gm::Envelope& visibleArea, int srid);
316 
317  /*!
318  \brief It gets the geometry type of the given layer.
319 
320  \param layer The layer that will be consulted.
321  */
323 
324  } // end namespace map
325 } // end namespace te
326 
327 #endif // __TERRALIB_MAPTOOLS_INTERNAL_UTILS_H
TEMAPEXPORT void GetColor(const te::se::Stroke *stroke, te::color::RGBAColor &color)
Gets the RGBA color from Stroke element.
Definition: Utils.cpp:83
A Fill specifies the pattern for filling an area geometry.
Definition: Fill.h:59
TEMAPEXPORT int GetInt(const te::se::ParameterValue *param)
Gets the parameter value as integer.
Definition: Utils.cpp:122
The FeatureTypeStyle defines the styling that is to be applied to a dataset that can be viewed as a f...
TEMAPEXPORT void DrawGeometries(te::da::DataSetType *type, te::da::DataSourcePtr ds, Canvas *canvas, const te::gm::Envelope &bbox, int bboxSRID, int srid, te::se::FeatureTypeStyle *style)
It draws the data set geometries in the given canvas using the informed SRID and style.
Definition: Utils.cpp:365
#define TEMAPEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:98
A Stroke specifies the appearance of a linear geometry.
Definition: Stroke.h:67
TEMAPEXPORT te::rst::RasterProperty * GetRasterProperty(DataSetLayer *layer)
It gets the raster property referenced by the given data set layer.
Definition: Utils.cpp:235
TEMAPEXPORT double GetDouble(const te::se::ParameterValue *param)
Gets the parameter value as double.
Definition: Utils.cpp:127
The CoverageStyle defines the styling that is to be applied to a subset of Coverage data...
Definition: CoverageStyle.h:45
TEMAPEXPORT te::gm::Envelope GetExtent(const std::list< te::map::AbstractLayerPtr > &layers, int srid, bool onlyVisibles)
It calculates the extent of the given layers in the given SRID.
Definition: Utils.cpp:326
TEMAPEXPORT te::da::DataSet * DataSet2Memory(te::da::DataSet *dataset)
It creates a new In-Memory dataset with the items from the given dataset.
Definition: Utils.cpp:355
TEMAPEXPORT void GetDashStyle(const std::string &dasharray, std::vector< double > &style)
Converts a dasharray pattern coded by a string to a vector of double.
Definition: Utils.cpp:227
TEMAPEXPORT te::rst::Raster * GetExtentRaster(te::rst::Raster *raster, int w, int h, const te::gm::Envelope &bbox, int bboxSRID, const te::gm::Envelope &visibleArea, int srid)
Definition: Utils.cpp:721
TEMAPEXPORT te::rst::Raster * GetRaster(DataSetLayer *layer)
It gets the raster referenced by the given data set layer.
Definition: Utils.cpp:264
A helper class for 32-bit RGBA (Red-Green-Blue-Alpha channel) color.
Definition: RGBAColor.h:57
GeomType
Each enumerated type is compatible with a Well-known Binary (WKB) type code.
Definition: Enums.h:41
TEMAPEXPORT te::gm::Envelope GetSelectedExtent(const std::list< te::map::AbstractLayerPtr > layers, int srid, bool onlyVisibles)
It calculates the extent of selected objects of the given layers in the given SRID.
Definition: Utils.cpp:151
boost::shared_ptr< DataSource > DataSourcePtr
Definition: DataSource.h:1395
TEMAPEXPORT std::string GetString(const te::se::ParameterValue *param)
Gets the parameter value as string.
Definition: Utils.cpp:132
TEMAPEXPORT void GetVisibleLayers(const std::list< te::map::AbstractLayerPtr > &layers, std::list< te::map::AbstractLayerPtr > &visibleLayers)
It gets the visible layers of the given layer list.
Definition: Utils.cpp:320
A class that models the description of a dataset.
Definition: DataSetType.h:72
Raster property.
An abstract class for raster data strucutures.
Definition: Raster.h:70
This class can be used to inform the progress of a task.
Definition: TaskProgress.h:53
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
This is the base class for Layers.
TEMAPEXPORT te::gm::GeomType GetGeomType(const te::map::AbstractLayerPtr &layer)
It gets the geometry type of the given layer.
Definition: Utils.cpp:789
TEMAPEXPORT void DrawRaster(te::da::DataSetType *type, te::da::DataSourcePtr ds, Canvas *canvas, const te::gm::Envelope &bbox, int bboxSRID, const te::gm::Envelope &visibleArea, int srid, te::se::CoverageStyle *style)
Definition: Utils.cpp:532
An Envelope defines a 2D rectangular region.
Definition: Envelope.h:51
The &quot;ParameterValueType&quot; uses WFS-Filter expressions to give values for SE graphic parameters...
A dataset is the unit of information manipulated by the data access module of TerraLib.
Definition: DataSet.h:111