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 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 "terralib_config.h"
28 #include "../common/STLUtils.h"
29 #include "../common/Translator.h"
30 #include "Envelope.h"
31 #include "Exception.h"
32 #include "MultiPolygon.h"
33 #include "Polygon.h"
34 #include "PolyhedralSurface.h"
35 
36 const std::string te::gm::PolyhedralSurface::sm_typeName("PolyhedralSurface");
37 
38 te::gm::PolyhedralSurface::PolyhedralSurface(std::size_t nPolygons, GeomType t, int srid, Envelope* mbr)
39  : Surface(t, srid, mbr),
40  m_polygons(nPolygons)
41 {
42 }
43 
45  : Surface(rhs)
46 {
48 }
49 
51 {
52  te::common::FreeContents(m_polygons);
53 }
54 
56 {
57  if(this != &rhs)
58  {
59  Surface::operator=(rhs);
60  te::common::FreeContents(m_polygons);
61  m_polygons.clear();
62  te::common::Clone(rhs.m_polygons, m_polygons);
63  }
64 
65  return *this;
66 }
67 
69 {
70  return new PolyhedralSurface(*this);
71 }
72 
74 {
75  if(size < m_polygons.size())
76  {
77  std::size_t oldSize = m_polygons.size();
78  for(std::size_t i = size; i < oldSize; ++i)
79  delete m_polygons[i];
80  }
81 
82  m_polygons.resize(size);
83 }
84 
86 {
87  assert(i < m_polygons.size());
88  return m_polygons[i];
89 }
90 
92 {
93  assert((i < m_polygons.size()) && (m_polygons[i] == 0));
94  delete m_polygons[i];
95  m_polygons[i] = p;
96 }
97 
99 {
100  return 0;
101 }
102 
104 {
105  return 0.0;
106 }
107 
108 const std::string& te::gm::PolyhedralSurface::getGeometryType() const throw()
109 {
110  return sm_typeName;
111 }
112 
114 {
115  std::size_t n = m_polygons.size();
116 
117  for(std::size_t i = 0; i < n; ++i)
118  m_polygons[i]->setSRID(srid);
119 
120  m_srid = srid;
121 }
122 
124 {
125 #ifdef TERRALIB_MOD_SRS_ENABLED
126  if (srid == m_srid)
127  return;
128 
129  std::size_t n = m_polygons.size();
130 
131  for(std::size_t i = 0; i < n; ++i)
132  m_polygons[i]->transform(srid);
133 
134  if(m_mbr)
135  computeMBR(false);
136 
137  m_srid = srid;
138 #else
139  throw Exception(TE_TR("transform method is not supported!"));
140 #endif // TERRALIB_MOD_SRS_ENABLED
141 }
142 
143 void te::gm::PolyhedralSurface::computeMBR(bool cascade) const throw()
144 {
145  if(m_mbr == 0)
146  m_mbr = new Envelope;
147  else
148  m_mbr->makeInvalid();
149 
150  std::size_t nPols = m_polygons.size();
151 
152  if(nPols == 0)
153  return;
154 
155  if(cascade)
156  m_polygons[0]->computeMBR(true);
157 
158  *m_mbr = *(m_polygons[0]->getMBR());
159 
160  for(std::size_t i = 1; i < nPols; ++i)
161  {
162  if(cascade)
163  m_polygons[i]->computeMBR(true);
164 
165  m_mbr->Union(*(m_polygons[i]->getMBR()));
166  }
167 }
168 
169 std::size_t te::gm::PolyhedralSurface::getNPoints() const throw()
170 {
171  std::size_t n = m_polygons.size();
172 
173  std::size_t sum = 0;
174 
175  for(std::size_t i = 0; i < n; ++i)
176  sum += m_polygons[i]->getNPoints();
177 
178  return sum;
179 }
180 
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:347
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