All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
PolyhedralSurface.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/PolyhedralSurface.cpp
22 
23  \brief PolyhedralSurface is a contiguous collection of polygons, which share common boundary segments.
24 */
25 
26 // TerraLib
27 #include "../common/STLUtils.h"
28 #include "../common/Translator.h"
29 #include "Envelope.h"
30 #include "Exception.h"
31 #include "MultiPolygon.h"
32 #include "Polygon.h"
33 #include "PolyhedralSurface.h"
34 
35 const std::string te::gm::PolyhedralSurface::sm_typeName("PolyhedralSurface");
36 
37 te::gm::PolyhedralSurface::PolyhedralSurface(std::size_t nPolygons, GeomType t, int srid, Envelope* mbr)
38  : Surface(t, srid, mbr),
39  m_polygons(nPolygons)
40 {
41 }
42 
44  : Surface(rhs)
45 {
47 }
48 
50 {
51  te::common::FreeContents(m_polygons);
52 }
53 
55 {
56  if(this != &rhs)
57  {
58  Surface::operator=(rhs);
59  te::common::FreeContents(m_polygons);
60  m_polygons.clear();
61  te::common::Clone(rhs.m_polygons, m_polygons);
62  }
63 
64  return *this;
65 }
66 
68 {
69  return new PolyhedralSurface(*this);
70 }
71 
73 {
74  if(size < m_polygons.size())
75  {
76  std::size_t oldSize = m_polygons.size();
77  for(std::size_t i = size; i < oldSize; ++i)
78  delete m_polygons[i];
79  }
80 
81  m_polygons.resize(size);
82 }
83 
85 {
86  assert(i < m_polygons.size());
87  return m_polygons[i];
88 }
89 
91 {
92  assert((i < m_polygons.size()) && (m_polygons[i] == 0));
93  delete m_polygons[i];
94  m_polygons[i] = p;
95 }
96 
98 {
99  return 0;
100 }
101 
103 {
104  return 0.0;
105 }
106 
107 const std::string& te::gm::PolyhedralSurface::getGeometryType() const throw()
108 {
109  return sm_typeName;
110 }
111 
113 {
114  std::size_t n = m_polygons.size();
115 
116  for(std::size_t i = 0; i < n; ++i)
117  m_polygons[i]->setSRID(srid);
118 
119  m_srid = srid;
120 }
121 
123 {
124 #ifdef TERRALIB_MOD_SRS_ENABLED
125  if (srid == m_srid)
126  return;
127 
128  std::size_t n = m_polygons.size();
129 
130  for(std::size_t i = 0; i < n; ++i)
131  m_polygons[i]->transform(srid);
132 
133  if(m_mbr)
134  computeMBR(false);
135 
136  m_srid = srid;
137 #else
138  throw Exception(TE_TR("transform method is not supported!"));
139 #endif // TERRALIB_MOD_SRS_ENABLED
140 }
141 
142 void te::gm::PolyhedralSurface::computeMBR(bool cascade) const throw()
143 {
144  if(m_mbr == 0)
145  m_mbr = new Envelope;
146  else
147  m_mbr->makeInvalid();
148 
149  std::size_t nPols = m_polygons.size();
150 
151  if(nPols == 0)
152  return;
153 
154  if(cascade)
155  m_polygons[0]->computeMBR(true);
156 
157  *m_mbr = *(m_polygons[0]->getMBR());
158 
159  for(std::size_t i = 1; i < nPols; ++i)
160  {
161  if(cascade)
162  m_polygons[i]->computeMBR(true);
163 
164  m_mbr->Union(*(m_polygons[i]->getMBR()));
165  }
166 }
167 
168 std::size_t te::gm::PolyhedralSurface::getNPoints() const throw()
169 {
170  std::size_t n = m_polygons.size();
171 
172  std::size_t sum = 0;
173 
174  for(std::size_t i = 0; i < n; ++i)
175  sum += m_polygons[i]->getNPoints();
176 
177  return sum;
178 }
179 
PolyhedralSurface is a contiguous collection of polygons, which share common boundary segments...
MultiPolygon is a MultiSurface whose elements are Polygons.
Definition: MultiPolygon.h:50
void makeInvalid()
It will invalidated the envelope.
Definition: Envelope.h:430
GeomType
Each enumerated type is compatible with a Well-known Binary (WKB) type code.
Definition: Enums.h:41
static const std::string sm_typeName
Geometry type name for PolyhedralSurface.
double getPerimeter() const
It returns the length of the boundary for the surface.
void setSRID(int srid)
It sets the Spatial Reference System ID of the Geometry and all its parts if it is a GeometryCollecti...
Polygon * getPatchN(std::size_t i) const
It returns a polygon in this surface, the order is arbitrary.
PolyhedralSurface(std::size_t nPolygons, GeomType t, int srid=0, Envelope *mbr=0)
It initializes the Geometry with the specified spatial reference system id and envelope.
void transform(int srid)
It will transform the coordinates of the Geometry to the new one.
#define TE_TR(message)
It marks a string in order to get translated.
Definition: Translator.h:345
PolyhedralSurface is a contiguous collection of polygons, which share common boundary segments...
virtual ~PolyhedralSurface()
Virtual destructor.
An Envelope defines a 2D rectangular region.
An Envelope defines a 2D rectangular region.
Definition: Envelope.h:51
std::size_t getNPoints() const
it returns the number of points (vertexes) in the geometry.
virtual const std::string & getGeometryType() const
The name of the geometry subtype for PolyhedralSurface is: PolyhedralSurface.
MultiPolygon is a MultiSurface whose elements are Polygons.
virtual Surface & operator=(const Surface &rhs)
Assignment operator.
Definition: Surface.cpp:59
A base class for values that can be retrieved from the data access module.
Definition: AbstractData.h:57
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
Definition: Exception.h:58
An exception class for the Geometry module.
void setNumPatches(std::size_t size)
It sets the number of including polygons.
Polygon is a subclass of CurvePolygon whose rings are defined by linear rings.
Polygon is a subclass of CurvePolygon whose rings are defined by linear rings.
Definition: Polygon.h:50
std::vector< Polygon * > m_polygons
An array with the polygon list.
MultiPolygon * getBoundingPolygons(const Polygon *p) const
It returns the collection of polygons in this surface that bounds the given polygon "p" for any polyg...
virtual te::dt::AbstractData * clone() const
It clones the linestring.
void setPatchN(std::size_t i, Polygon *p)
It sets the informed position polygon to the new one.
void computeMBR(bool cascade) const
It computes the minimum bounding rectangle for the Geometry.
void Clone(const std::vector< T * > &src, std::vector< T * > &dst)
This function can be applied to a vector of pointers.
Definition: STLUtils.h:237
void FreeContents(boost::unordered_map< K, V * > &m)
This function can be applied to a map of pointers. It will delete each pointer in the map...
Definition: BoostUtils.h:55
virtual PolyhedralSurface & operator=(const PolyhedralSurface &rhs)
Assignment operator.
Surface is an abstract class that represents a 2-dimensional geometric objects.
Definition: Surface.h:54