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