All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Utils.cpp
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.cpp
22 
23  \brief Utility functions for the Geometry Module.
24 */
25 
26 // TerraLib
27 #include "../common/Translator.h"
28 #include "Envelope.h"
29 #include "Exception.h"
30 #include "Geometry.h"
31 #include "LinearRing.h"
32 #include "Polygon.h"
33 #include "Utils.h"
34 
36 {
37 // create an outer ring with the same envelope as our envelope
38  LinearRing* r = new LinearRing(5, LineStringType, srid, new Envelope(*e));
39 
40  r->setPoint(0, e->m_llx, e->m_lly);
41  r->setPoint(1, e->m_urx, e->m_lly);
42  r->setPoint(2, e->m_urx, e->m_ury);
43  r->setPoint(3, e->m_llx, e->m_ury);
44  r->setPoint(4, e->m_llx, e->m_lly);
45 
46 // create the polygon
47  Polygon* p = new Polygon(1, PolygonType, srid, new Envelope(*e));
48  p->setRingN(0, r);
49 
50  return p;
51 }
52 
54  const Geometry* g2,
55  SpatialRelation relation)
56 {
57  switch(relation)
58  {
59  case CONTAINS:
60  return g1->contains(g2);
61 
62  case COVEREDBY:
63  return g1->coveredBy(g2);
64 
65  case COVERS:
66  return g1->covers(g2);
67 
68  case CROSSES:
69  return g1->crosses(g2);
70 
71  case DISJOINT:
72  return g1->disjoint(g2);
73 
74  case EQUALS:
75  return g1->equals(g2);
76 
77  case INTERSECTS:
78  return g1->intersects(g2);
79 
80  case OVERLAPS:
81  return g1->overlaps(g2);
82 
83  case TOUCHES:
84  return g1->touches(g2);
85 
86  case WITHIN:
87  return g1->within(g2);
88 
89  default:
90  throw Exception(TE_TR("Invalid spatial relation!"));
91  }
92 }
A LinearRing is a LineString that is both closed and simple.
virtual bool covers(const Geometry *const rhs) const
It returns true if this geometry object spatially covers the rhs geometry.
Definition: Geometry.cpp:359
virtual bool intersects(const Geometry *const rhs) const
It returns true if the geometry object spatially intersects rhs geometry.
Definition: Geometry.cpp:243
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
double m_urx
Upper right corner x-coordinate.
Definition: Envelope.h:346
SpatialRelation
Spatial relations between geometric objects.
Definition: Enums.h:122
virtual bool contains(const Geometry *const rhs) const
It returns true if this geometry object spatially contains rhs geometry.
Definition: Geometry.cpp:299
#define TE_TR(message)
It marks a string in order to get translated.
Definition: Translator.h:345
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
virtual bool crosses(const Geometry *const rhs) const
It returns true if the geometry object spatially crosses rhs geometry.
Definition: Geometry.cpp:271
A LinearRing is a LineString that is both closed and simple.
Definition: LinearRing.h:53
double m_llx
Lower left corner x-coordinate.
Definition: Envelope.h:344
An Envelope defines a 2D rectangular region.
void setPoint(std::size_t i, const double &x, const double &y)
It sets the value of the specified point.
Definition: LineString.cpp:352
An Envelope defines a 2D rectangular region.
Definition: Envelope.h:51
virtual bool disjoint(const Geometry *const rhs) const
It returns true if the geometry object is spatially disjoint from rhs geometry.
Definition: Geometry.cpp:229
Utility functions for the Geometry Module.
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
Definition: Geometry.h:73
virtual bool overlaps(const Geometry *const rhs) const
It returns true if this geometry object spatially overlaps rhs geometry.
Definition: Geometry.cpp:313
double m_lly
Lower left corner y-coordinate.
Definition: Envelope.h:345
An exception class for the Geometry module.
Polygon is a subclass of CurvePolygon whose rings are defined by linear rings.
virtual bool touches(const Geometry *const rhs) const
It returns true if the geometry object spatially touches rhs geometry.
Definition: Geometry.cpp:257
Polygon is a subclass of CurvePolygon whose rings are defined by linear rings.
Definition: Polygon.h:50
double m_ury
Upper right corner y-coordinate.
Definition: Envelope.h:347
virtual bool equals(const Geometry *const rhs, const bool exact=false) const
It returns true if the geometry object is spatially equal to rhs geometry.
Definition: Geometry.cpp:213
virtual bool coveredBy(const Geometry *const rhs) const
It returns true if this geometry object is spatially covered by rhs geometry.
Definition: Geometry.cpp:373
TEGEOMEXPORT Geometry * GetGeomFromEnvelope(const Envelope *const e, int srid)
It creates a Geometry (a polygon) from the given envelope.
Definition: Utils.cpp:35
void setRingN(std::size_t i, Curve *r)
It sets the informed position ring to the new one.
virtual bool within(const Geometry *const rhs) const
It returns true if the geometry object is spatially within rhs geometry.
Definition: Geometry.cpp:285