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