All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Utils.h
Go to the documentation of this file.
1 /* Copyright (C) 2008-2013 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 
41  /*!
42  \brief It returns the number of measurements or axes needed to describe a position in a coordinate system.
43 
44  It returns:
45  <ul>
46  <li>2 for a coordinate with x, y;</li>
47  <li>3 for a coordinate with x, y and z or x, y and m;</li>
48  <li>4 for a coordinate with x, y, z and m.</li>
49  </ul>
50 
51  \param t The geomeytric type.
52 
53  \return The number of measurements or axes needed to describe a position in a coordinate system.
54  */
56  {
57  if(t & 0x100) // may be z (0x300), m (0x700) or zm (0x800)
58  {
59  if(t & 0x800) // it must be zm
60  return 4;
61 
62  return 3; // it can be z (gType & 0x300) or m (gType & 0x700)
63  }
64 
65  return 2;
66  }
67 
68  /*!
69  \brief It creates a Geometry (a polygon) from the given envelope.
70 
71  \param e The envelope to extract the coordinates. Don't call with a NULL envelope.
72  \param srid The Spatial Reference System ID to be associated to the polygon.
73 
74  \return A polygon (in counter-clock-wise) with rectangle coordinates: [(MINX, MINY), (MAXX, MINY), (MAXX, MAXY), (MINX, MAXY), (MINX, MINY)].
75 
76  \note The caller of this method will take the ownership of the returned geometry.
77  */
78  TEGEOMEXPORT Geometry* GetGeomFromEnvelope(const Envelope* const e, int srid);
79 
80  /*!
81  \brief It returns if two geometries satisfy a given spatial relation.
82 
83  \param g1 The first geometry
84  \param g2 The second geometry
85  \param r A given spatial relation to be tested
86 
87  \return It returns true if the given two geometries satisfy the spatial relation. Otherwise, it returns false.
88 
89  \exception Exception It throws an exception if the spatial relation is not valid or if the test can not be evaluated.
90  */
91  TEGEOMEXPORT bool SatisfySpatialRelation(const Geometry* g1, const Geometry* g2, SpatialRelation relation);
92 
93  } // end namespace gm
94 } // end namespace te
95 
96 #endif // __TERRALIB_GEOMETRY_INTERNAL_GEOMUTILS_H
97 
int GetCoordDimension(GeomType t)
It returns the number of measurements or axes needed to describe a position in a coordinate system...
Definition: Utils.h:55
#define TEGEOMEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:114
TEGEOMEXPORT Geometry * GetGeomFromEnvelope(const Envelope *const e, int srid)
It creates a Geometry (a polygon) from the given envelope.
Definition: Utils.cpp:35
SpatialRelation
Spatial relations between geometric objects.
Definition: Enums.h:122
Enumerations related to Geometry module.
TEGEOMEXPORT bool SatisfySpatialRelation(const Geometry *g1, const Geometry *g2, SpatialRelation relation)
It returns if two geometries satisfy a given spatial relation.
Definition: Utils.cpp:53
GeomType
Each enumerated type is compatible with a Well-known Binary (WKB) type code.
Definition: Enums.h:41
Configuration flags for the Vector Geometry Model of TerraLib.