All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 Utils.h
22 
23  \brief Utility class with functions to manipulate the canvas and conversion between projections.
24 
25  \ingroup layout
26 */
27 
28 #ifndef __TERRALIB_LAYOUT_INTERNAL_UTILS_H
29 #define __TERRALIB_LAYOUT_INTERNAL_UTILS_H
30 
31 // TerraLib
32 #include "../../geometry/Envelope.h"
33 #include "../../geometry/LinearRing.h"
34 #include "../../color/RGBAColor.h"
35 #include "../../maptools/Canvas.h"
36 #include "../../maptools/WorldDeviceTransformer.h"
37 #include "WorldTransformer.h"
38 #include "../../common/UnitOfMeasure.h"
39 #include "../../maptools/Enums.h"
40 #include "../../geometry/Point.h"
41 #include "../../geometry/Polygon.h"
42 #include "Config.h"
43 
44 // STL
45 #include <string>
46 #include <iostream>
47 #include <fstream>
48 
49 const double TeCDR = 0.01745329251994329576; //!< Conversion factor: degrees to radians
50 const double TeCRD = 57.29577951308232087679; //!< Conversion factor: radians to degrees
51 
52 namespace te
53 {
54  namespace layout
55  {
56  /*!
57  \brief Utility class with functions to manipulate the canvas and conversion between projections.
58 
59  \ingroup layout
60  */
62  {
63  public:
64 
65  /*!
66  \brief Constructor
67  */
68  Utils();
69 
70  /*!
71  \brief Destructor
72  */
73  virtual ~Utils();
74 
75  /*!
76  \brief Draw a rectangle in world coordinates (mm).
77 
78  \param box in mm
79  */
80  virtual void drawRectW(te::gm::Envelope box);
81 
82  /*!
83  \brief Draw a line in world coordinates (mm).
84 
85  \param LinearRing pointer with coordinates in millimeters
86  */
87  virtual void drawLineW(te::gm::LinearRing* line);
88 
89  /*!
90  \brief Returns a pointer RGBA colors that representing an image.
91 
92  \param box in mm
93  \return The Pointer RGBA colors
94  */
95  virtual te::color::RGBAColor** getImageW(te::gm::Envelope boxmm);
96 
97  /*!
98  \brief Millimeter to pixel
99 
100  \param millimeter value
101  \return pixel value
102  */
103  virtual int mm2pixel(double mm);
104 
105  /*!
106  \brief Creates a LinearRing (line) pointer from a box in world coordinates (mm)
107 
108  \param box in mm
109  \return new line
110  */
111  virtual te::gm::LinearRing* createSimpleLine(te::gm::Envelope box);
112 
113  /*!
114  \brief Creates a line with n points in x axis. Method used to create the grid lines on a map. Horizontal line.
115 
116 
117  \param box in mm
118  \param axisCoord axis y value
119  \param gap distance between the points on the x axis
120  \return
121  */
122  virtual te::gm::LinearRing* addCoordsInX(te::gm::Envelope box, double axisCoord, double gap);
123 
124  /*!
125  \brief Creates a line with n points in y axis. Method used to create the grid lines on a map. Vertical line.
126 
127  \param box in mm
128  \param axisCoord axis x value
129  \param gap distance between the points on the y axis
130  \return
131  */
132  virtual te::gm::LinearRing* addCoordsInY(te::gm::Envelope box, double axisCoord, double gap);
133 
134  /*!
135  \brief Sets the viewport and window of the canvas. The viewport is only changed if the resize parameter is true.
136 
137  \param box window coordinate (mm)
138  */
139  virtual void configCanvas(te::gm::Envelope box, bool resize = true, bool applyZoom = true);
140 
141  /*!
142  \brief Converts the box world (mm) to screen coordinates (pixel).
143 
144  \param box in mm
145  \return box in pixel
146  */
147  virtual te::gm::Envelope viewportBox(te::gm::Envelope box);
148 
149  /*!
150  \brief A method that calculates the height and width of a text.
151 
152  \param w returns the width
153  \param h returns the height
154  \param text
155  */
156  virtual void textBoundingBox(double &w, double &h, std::string txt);
157 
158  /*!
159  \brief Returns a WorldTransformer object to transformations between geo coordinates and millimeter coordinates.
160 
161  \param box in geo coordinates
162  \return box in mm
163  */
164  te::layout::WorldTransformer getTransformGeo(te::gm::Envelope boxgeo, te::gm::Envelope boxmm);
165 
166  /*!
167  \brief Converts decimal geo coordinates to degrees.
168 
169  \param value in decimal
170  \param bDegrees true if should appear in the return string, false otherwise
171  \param bMinutes true if should appear in the return string, false otherwise
172  \param bSeconds true if should appear in the return string, false otherwise
173  \return string value in degree
174  */
175  virtual std::string convertDecimalToDegree(const double& value, bool bDegrees, bool bMinutes, bool bSeconds);
176 
177  /*!
178  \brief Converts degree geo coordinates to decimal.
179 
180  \return double value in decimal
181  */
182  virtual double convertDegreeToDecimal();
183 
184  /*!
185  \brief Number to string.
186 
187  \param value
188  \param precision decimal places
189  \return number as string
190  */
191  virtual std::string convertNumberToString(const double& value, int precision);
192 
193  /*!
194  \brief Rounds double to int.
195 
196  \param value
197  \return number rounded
198  */
199  virtual int roundNumber(const double& value);
200 
201  /*!
202  \brief Returns string wkt with UTM projection in the specified zone.
203 
204  \param zone UTM
205  \return string wkt
206  */
207  std::string proj4DescToPlanar(int zone);
208 
209  /*!
210  \brief Returns string wkt with non-planar projection.
211 
212  \return wkt
213  */
214  std::string proj4DescToGeodesic();
215 
216  /*!
217  \brief Calculates the area from a box in coordinated latlong
218 
219  \param latLongBox box in latlong
220  \return UTM zone
221  */
222  int calculatePlanarZone(te::gm::Envelope latLongBox);
223 
224  /*!
225  \brief Returns a UnitOfMeasurePtr pointer.
226 
227  \param srid projection number
228  \return A UnitOfMeasurePtr pointer
229  */
230  te::common::UnitOfMeasurePtr unitMeasure(int srid);
231 
232  /*!
233  \brief Map latlong to UTM zone.
234 
235  \param box in latlong
236  \param zone returns UTM zone
237  */
238  virtual void remapToPlanar(te::gm::Envelope* latLongBox, int zone);
239 
240  /*!
241  \brief Map latlong LinearRing (line) to UTM zone.
242 
243  \param line line in latlong
244  \param zone returns UTM zone
245  */
246  virtual void remapToPlanar(te::gm::LinearRing* line, int zone);
247 
248  /*!
249  \brief Map latlong Point (point) to UTM zone.
250 
251  \param zone returns UTM zone
252  */
253  virtual void remapToPlanar(te::gm::Point* point, int zone);
254 
255  /*!
256  \brief Convert LinearRing from one coordinate system to mm
257 
258  \param Object with logic for transforming
259  \param line LinearRing pointer in one coordinate system
260  */
261  virtual void convertToMillimeter(WorldTransformer transf, te::gm::LinearRing* line);
262 
263  /*!
264  \brief Convert Polygon from one coordinate system to mm
265 
266  \param Object with logic for transforming
267  \param line LinearRing pointer in one coordinate system
268  */
269  virtual void convertToMillimeter(WorldTransformer transf, te::gm::Polygon* poly);
270 
271  /*!
272  \brief Opens the file and loads the image into memory and converts to char*.
273 
274  \param fileName full path to image
275  \return size length of file
276  */
277  virtual char* imageToChar(std::string fileName, std::ifstream::pos_type &size);
278 
279  /*!
280  \brief Returns the file extension.
281 
282  \param fileName full path to image
283  \return file extension
284  */
285  virtual std::string getFileExtension(std::string fileName);
286 
287  /*!
288  \brief
289 
290  \param
291  */
292  virtual void setApplyZoom(bool apply);
293 
294  /*!
295  \brief
296 
297  \param
298  \return
299  */
300  virtual bool getApplyZoom();
301 
302  /*!
303  \brief Clears the canvas content and fills with the background color. Sets all width with 1.
304  */
305  virtual void resetCanvas();
306 
307  protected:
308 
309  /*!
310  \brief Sets the viewport and window of the canvas. The viewport is only changed if the resize parameter is true.
311 
312  \param viewport viewport box(pixel)
313  \param world world box(mm)
314  \param resize true if to resize, false otherwise
315  */
316  virtual void changeCanvas(te::gm::Envelope viewport, te::gm::Envelope world, bool resize = true);
317 
318  /*!
319  \brief Transforms the box (mm) to screen coordinates (pixel).
320 
321  \param transf logic for transforming from device coordinate to world coordinate and vice-versa.
322  \return box in screen coordinates (pixel)
323  */
324  virtual te::gm::Envelope transformToViewport(te::map::WorldDeviceTransformer transf, te::gm::Envelope box);
325 
326  /*!
327  \brief Converts the box world (mm) to screen coordinates (pixel).
328 
329  \param box in mm
330  */
331  virtual te::gm::Envelope viewportBoxFromMM(te::gm::Envelope box);
332 
333  protected:
334 
335  bool m_applyZoom; //!<
336  };
337  }
338 }
339 
340 #endif
#define TELAYOUTEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:99
This class implements the logic for transforming from device coordinate to world coordinate and vice-...
A LinearRing is a LineString that is both closed and simple.
Definition: LinearRing.h:53
A point with x and y coordinate values.
Definition: Point.h:50
An Envelope defines a 2D rectangular region.
Definition: Envelope.h:51
bool m_applyZoom
Definition: Utils.h:335
This class implements the logic for transforming from System 1 coordinate to other type of coordinate...
boost::shared_ptr< UnitOfMeasure > UnitOfMeasurePtr
Polygon is a subclass of CurvePolygon whose rings are defined by linear rings.
Definition: Polygon.h:50
A helper class for 32-bit RGBA (Red-Green-Blue-Alpha channel) color.
Definition: RGBAColor.h:57
Configuration flags for the Terrralib Layout module.
Utility class with functions to manipulate the canvas and conversion between projections.
Definition: Utils.h:61
const double TeCDR
Conversion factor: degrees to radians.
Definition: Utils.h:49
const double TeCRD
Conversion factor: radians to degrees.
Definition: Utils.h:50