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/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  }
69 
70  namespace map
71  {
72 // Forward declaration
73  class DataSetLayer;
74  class RasterContrast;
75 
76  /*!
77  \brief It calculates the extent of selected objects of the given layers in the given SRID.
78 
79  \param layers The layer list that will be consulted.
80  \param srid The result extent SRID.
81  \param onlyVisibles A flag that indicates if the method should consider only the visible layers.
82 
83  \return The extent of selected objects of the given layers in the given SRID.
84 
85  \note This method considers the children of layers.
86  */
87  TEMAPEXPORT te::gm::Envelope GetSelectedExtent(const std::list<te::map::AbstractLayerPtr> layers, int srid, bool onlyVisibles);
88 
89  /*!
90  \brief It calculates the extent of selected objects of the given layer in the given SRID.
91 
92  \param layer The layer that will be consulted.
93  \param srid The result extent SRID.
94  \param onlyVisibles A flag that indicates if the method should consider only the visible layers.
95 
96  \return The extent of the selected objects of the given layer in the given SRID.
97 
98  \note This method considers the children of layers.
99  */
100  TEMAPEXPORT te::gm::Envelope GetSelectedExtent(const te::map::AbstractLayerPtr layer, int srid, bool onlyVisibles);
101 
102  /*!
103  \brief Converts a dasharray pattern coded by a string to a vector of double.
104 
105  \param dasharray The dasharray pattern coded by a string.
106  \param style The vector of double that will be filled with the values extracted from dasharray string.
107 
108  \note The dasharray should be specified as an even number of positive values separated by blank space. i.e "10 5 3 4"
109  Here, the values "10" and "3" (in uom) are dashes and the values "5" and "4" are spaces (in uom).
110  The given vector style will be filled with the values: style[0] = 10; style[1] = 5; style[2] = 3; style[3] = 4.
111  */
112  TEMAPEXPORT void GetDashStyle(const std::string& dasharray, std::vector<double>& style);
113 
114  /*!
115  \brief It gets the raster property referenced by the given data set layer.
116 
117  \param layer The data set layer that will be used to retrieve the raster property.
118 
119  \return The raster property referenced by the data set layer.
120 
121  \note The caller will take the ownership of the returned pointer.
122 
123  \exception Exception It will throw an exception if the raster property could not be retrieved.
124  */
126 
127  /*!
128  \brief It gets the raster referenced by the given data set layer.
129 
130  \param layer The data set layer that will be used to retrieve the raster.
131 
132  \return The raster referenced by the data set layer.
133 
134  \note The caller will take the ownership of the returned pointer.
135 
136  \exception Exception It will throw an exception if the raster could not be retrieved.
137  */
138  TEMAPEXPORT te::rst::Raster* GetRaster(AbstractLayer* layer);
139 
140  /*!
141  \brief It gets the visible layers of the given layer list.
142 
143  \param layers The layer list that will be consulted.
144  \param visibleLayers A layer list that will be filled with the visible layers.
145  */
146  TEMAPEXPORT void GetVisibleLayers(const std::list<te::map::AbstractLayerPtr>& layers, std::list<te::map::AbstractLayerPtr>& visibleLayers);
147 
148  TEMAPEXPORT void GetVisibleLayers(const std::list<te::map::AbstractLayer*>& layers, std::list<te::map::AbstractLayer*>& visibleLayers);
149 
150  /*!
151  \brief It gets the visible layers of the given layer.
152 
153  \param layer The layer that will be consulted.
154  \param visibleLayers A layer list that will be filled with the visible layers.
155  */
156  TEMAPEXPORT void GetVisibleLayers(const te::map::AbstractLayerPtr& layer, std::list<te::map::AbstractLayerPtr>& visibleLayers);
157 
158  /*!
159  \brief It calculates the extent of the given layers in the given SRID.
160 
161  \param layers The layer list that will be consulted.
162  \param srid The result extent SRID.
163  \param onlyVisibles A flag that indicates if the method should consider only the visible layers.
164 
165  \return The extent of the given layers in the given SRID.
166 
167  \note This method considers the children of layers.
168  */
169  TEMAPEXPORT te::gm::Envelope GetExtent(const std::list<te::map::AbstractLayerPtr>& layers, int srid, bool onlyVisibles);
170 
171  /*!
172  \brief It calculates the extent of the given layer in the given SRID.
173 
174  \param layer The layer that will be consulted.
175  \param srid The result extent SRID.
176  \param onlyVisibles A flag that indicates if the method should consider only the visible layers.
177 
178  \return The extent of the given layer in the given SRID.
179 
180  \note This method considers the children of layer.
181  */
182  TEMAPEXPORT te::gm::Envelope GetExtent(const te::map::AbstractLayerPtr& layer, int srid, bool onlyVisibles);
183 
184  /*!
185  \brief It creates a new In-Memory dataset with the items from the given dataset.
186 
187  \param dataset The dataset which will provide the items. Do not pass NULL!
188 
189  \return A new In-Memory dataset.
190 
191  \note The new dataset will not have a transactor associated to it.
192 
193  \note To copy all items the caller is responsible for informing the
194  dataset in the right position. i.e. at before begin.
195 
196  \note The caller will take the ownership of the returned pointer.
197  */
199 
200  /*!
201  \brief It draws the data set geometries in the given canvas using the informed SRID and style.
202 
203  The informed bounding box (bbox) is used to constraint the data set to be drawn.
204  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.
205 
206  \param type The data set type that describes the data set that will be drawn.
207  \param ds A datasource that will be used to retrieve the data set objects.
208  \param canvas The canvas were the data set geometries will be drawn.
209  \param bbox The interest area to render the geometries.
210  \param bboxSRID The SRID of interest area.
211  \param srid The SRID to be used to draw the data set geometries.
212  \param style The style that will be used.
213  */
215  const te::gm::Envelope& bbox, int bboxSRID,
216  int srid, te::se::FeatureTypeStyle* style);
217 
218  /*!
219  \brief It draws the data set geometries in the given canvas using the informed SRS.
220 
221  \param dataset The data set that will be drawn.
222  \param gpos The geometry property position that will be drawn.
223  \param canvas The canvas were the data set geometries will be drawn.
224  \param fromSRID The SRID of data set geometries.
225  \param srid The SRID to be used to draw the data set geometries.
226  \param task An optional task that can be used cancel the draw process.
227  */
228  TEMAPEXPORT void DrawGeometries(te::da::DataSet* dataset, const std::size_t& gpos,
229  Canvas* canvas, int fromSRID, int toSRID, te::common::TaskProgress* task = 0);
230 
231  TEMAPEXPORT void DrawRaster(te::da::DataSetType* type, te::da::DataSourcePtr ds, Canvas* canvas,
232  const te::gm::Envelope& bbox, int bboxSRID, const te::gm::Envelope& visibleArea, int srid, te::se::CoverageStyle* style,
233  te::map::RasterContrast* rc, const double& scale, bool* cancel);
234 
235  TEMAPEXPORT void DrawRaster(te::rst::Raster* raster, Canvas* canvas, const te::gm::Envelope& bbox, int bboxSRID,
236  const te::gm::Envelope& visibleArea, int srid, te::se::CoverageStyle* style, te::map::RasterContrast* rc,
237  const double& scale, bool* cancel);
238 
239  TEMAPEXPORT te::rst::Raster* GetExtentRaster(te::rst::Raster* raster, int w, int h, const te::gm::Envelope& bbox, int bboxSRID,
240  const te::gm::Envelope& visibleArea, int srid);
241 
242  /*!
243  \brief It gets the geometry type of the given layer.
244 
245  \param layer The layer that will be consulted.
246  */
248 
249 
250  /*!
251  \brief It gets the requested envelope on a UTM planar projection
252 
253  \param worldBox WordBox to be transformed to planar
254  \param srid The WorldBox SRID to transform from
255  */
257 
258  /*!
259  \brief Returns proj4 string with UTM projection in the specified zone (Only working for south).
260  \param UTM Zone
261  \return proj4 string
262  */
263  TEMAPEXPORT std::string GetUTMProj4FromZone(int zone);
264 
265  /*!
266  \brief Calculates the UTM zone from a Geographic envelope.
267 
268  \param latLongBox Geographic envelope
269  \return UTM zone
270  */
272 
273  } // end namespace map
274 } // end namespace te
275 
276 #endif // __TERRALIB_MAPTOOLS_INTERNAL_UTILS_H
TEMAPEXPORT te::gm::Envelope GetSelectedExtent(const te::map::AbstractLayerPtr layer, int srid, bool onlyVisibles)
It calculates the extent of selected objects of the given layer in the given SRID.
TEMAPEXPORT te::gm::GeomType GetGeomType(const te::map::AbstractLayerPtr &layer)
It gets the geometry type of the given layer.
GeomType
Each enumerated type is compatible with a Well-known Binary (WKB) type code.
Definition: Enums.h:41
boost::shared_ptr< DataSource > DataSourcePtr
Definition: DataSource.h:1440
TEMAPEXPORT te::gm::Envelope GetExtent(const te::map::AbstractLayerPtr &layer, int srid, bool onlyVisibles)
It calculates the extent of the given layer in the given SRID.
A class that models the description of a dataset.
Definition: DataSetType.h:72
The CoverageStyle defines the styling that is to be applied to a subset of Coverage data...
Definition: CoverageStyle.h:45
This is the base class for Layers.
TEMAPEXPORT void DrawGeometries(te::da::DataSet *dataset, const std::size_t &gpos, Canvas *canvas, int fromSRID, int toSRID, te::common::TaskProgress *task=0)
It draws the data set geometries in the given canvas using the informed SRS.
TEMAPEXPORT te::da::DataSet * DataSet2Memory(te::da::DataSet *dataset)
It creates a new In-Memory dataset with the items from the given dataset.
This class can be used to inform the progress of a task.
Definition: TaskProgress.h:53
TEMAPEXPORT void GetDashStyle(const std::string &dasharray, std::vector< double > &style)
Converts a dasharray pattern coded by a string to a vector of double.
TEMAPEXPORT te::rst::Raster * GetRaster(AbstractLayer *layer)
It gets the raster referenced by the given data set layer.
Raster property.
TEMAPEXPORT void DrawRaster(te::rst::Raster *raster, Canvas *canvas, const te::gm::Envelope &bbox, int bboxSRID, const te::gm::Envelope &visibleArea, int srid, te::se::CoverageStyle *style, te::map::RasterContrast *rc, const double &scale, bool *cancel)
TEMAPEXPORT std::string GetUTMProj4FromZone(int zone)
Returns proj4 string with UTM projection in the specified zone (Only working for south).
An Envelope defines a 2D rectangular region.
Definition: Envelope.h:51
The FeatureTypeStyle defines the styling that is to be applied to a dataset that can be viewed as a f...
An abstract class for raster data strucutures.
Definition: Raster.h:71
URI C++ Library.
TEMAPEXPORT te::gm::Envelope GetWorldBoxInPlanar(const te::gm::Envelope &worldBox, int srid)
It gets the requested envelope on a UTM planar projection.
#define TEMAPEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:60
TEMAPEXPORT int CalculatePlanarZone(te::gm::Envelope latLongBox)
Calculates the UTM zone from a Geographic envelope.
This class contains the parameters needed to apply dynamic contrast over a raster.
A dataset is the unit of information manipulated by the data access module of TerraLib.
Definition: DataSet.h:112
TEMAPEXPORT void GetVisibleLayers(const te::map::AbstractLayerPtr &layer, std::list< te::map::AbstractLayerPtr > &visibleLayers)
It gets the visible layers of the given layer.
TEMAPEXPORT te::rst::RasterProperty * GetRasterProperty(AbstractLayer *layer)
It gets the raster property referenced by the given data set layer.
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)
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr