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 terralib/geometry/Utils.h
22 
23  \brief Utility functions for the Geometry Module.
24 */
25 
26 #ifndef __TERRALIB_GEOMETRY_INTERNAL_GEOMUTILS_H
27 #define __TERRALIB_GEOMETRY_INTERNAL_GEOMUTILS_H
28 
29 // TerraLib
30 #include "Config.h"
31 #include "Enums.h"
32 
33 namespace te
34 {
35  namespace gm
36  {
37 // Forward declarations
38  class Envelope;
39  class Geometry;
40  class Point;
41  struct Coord2D;
42  class LineString;
43 
44  /*!
45  \brief It returns the number of measurements or axes needed to describe a position in a coordinate system.
46 
47  It returns:
48  <ul>
49  <li>2 for a coordinate with x, y;</li>
50  <li>3 for a coordinate with x, y and z or x, y and m;</li>
51  <li>4 for a coordinate with x, y, z and m.</li>
52  </ul>
53 
54  \param t The geomeytric type.
55 
56  \return The number of measurements or axes needed to describe a position in a coordinate system.
57  */
59  {
60  if(t & 0x100) // may be z (0x300), m (0x700) or zm (0x800)
61  {
62  if(t & 0x800) // it must be zm
63  return 4;
64 
65  return 3; // it can be z (gType & 0x300) or m (gType & 0x700)
66  }
67 
68  return 2;
69  }
70 
71  /*!
72  \brief It creates a Geometry (a polygon) from the given envelope.
73 
74  \param e The envelope to extract the coordinates. Don't call with a NULL envelope.
75  \param srid The Spatial Reference System ID to be associated to the polygon.
76 
77  \return A polygon (in counter-clock-wise) with rectangle coordinates: [(MINX, MINY), (MAXX, MINY), (MAXX, MAXY), (MINX, MAXY), (MINX, MINY)].
78 
79  \note The caller of this method will take the ownership of the returned geometry.
80  */
81  TEGEOMEXPORT Geometry* GetGeomFromEnvelope(const Envelope* const e, int srid);
82 
83  /*!
84  \brief It returns if two geometries satisfy a given spatial relation.
85 
86  \param g1 The first geometry
87  \param g2 The second geometry
88  \param r A given spatial relation to be tested
89 
90  \return It returns true if the given two geometries satisfy the spatial relation. Otherwise, it returns false.
91 
92  \exception Exception It throws an exception if the spatial relation is not valid or if the test can not be evaluated.
93  */
94  TEGEOMEXPORT bool SatisfySpatialRelation(const Geometry* g1, const Geometry* g2, SpatialRelation relation);
95 
96  /*!
97  \brief Finds the correspondent smallest box that allows a box to be cut in blocks of a given size
98 
99  \param env Reference envelope
100  \param bWidth Block width
101  \param bHeight Block height
102 
103  \return It returns a adjusted envelope
104  */
105  TEGEOMEXPORT Envelope AdjustToCut(const Envelope & env, double bWidth, double bHeight);
106 
107  /* \brief It checks if one object intersects another object. */
108  template<class T1, class T2> bool Intersects(const T1& o1, const T2& o2);
109 
110  /* \brief Specialized function that checks if point intersects envelope. */
111  template<> TEGEOMEXPORT bool Intersects(const te::gm::Point& point, const te::gm::Envelope& e);
112 
113  /*!
114  \brief Make the line interpolation to find a target
115 
116  \param line LineString to make the interpolation
117  \param initial Initial value
118  \param final Final value
119  \param target Target value
120 
121  \return It returns a target Coord2D in the line.
122  */
123  TEGEOMEXPORT Coord2D* locateAlong(const LineString* line, double initial, double final, double target);
124 
125  } // end namespace gm
126 } // end namespace te
127 
128 #endif // __TERRALIB_GEOMETRY_INTERNAL_GEOMUTILS_H
129 
GeomType
Each enumerated type is compatible with a Well-known Binary (WKB) type code.
Definition: Enums.h:41
TEGEOMEXPORT bool SatisfySpatialRelation(const Geometry *g1, const Geometry *g2, SpatialRelation relation)
It returns if two geometries satisfy a given spatial relation.
Definition: Utils.cpp:56
SpatialRelation
Spatial relations between geometric objects.
Definition: Enums.h:122
int GetCoordDimension(GeomType t)
It returns the number of measurements or axes needed to describe a position in a coordinate system...
Definition: Utils.h:58
#define TEGEOMEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:79
Enumerations related to Geometry module.
A point with x and y coordinate values.
Definition: Point.h:50
An Envelope defines a 2D rectangular region.
Definition: Envelope.h:51
TEGEOMEXPORT Coord2D * locateAlong(const LineString *line, double initial, double final, double target)
Make the line interpolation to find a target.
Definition: Utils.cpp:169
bool Intersects(const T1 &o1, const T2 &o2)
Definition: Utils.cpp:143
TEGEOMEXPORT Envelope AdjustToCut(const Envelope &env, double bWidth, double bHeight)
Finds the correspondent smallest box that allows a box to be cut in blocks of a given size...
Definition: Utils.cpp:97
Configuration flags for the Vector Geometry Model of TerraLib.
TEGEOMEXPORT Geometry * GetGeomFromEnvelope(const Envelope *const e, int srid)
It creates a Geometry (a polygon) from the given envelope.
Definition: Utils.cpp:38