CurvePolygon.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
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/CurvePolygon.h
22 
23  \brief CurvePolygon is a planar surface defined by 1 exterior boundary and 0 or more interior boundaries.
24 */
25 
26 #ifndef __TERRALIB_GEOMETRY_INTERNAL_CURVEPOLYGON_H
27 #define __TERRALIB_GEOMETRY_INTERNAL_CURVEPOLYGON_H
28 
29 // TerraLib
30 #include "Surface.h"
31 
32 // STL
33 #include <cassert>
34 #include <vector>
35 
36 namespace te
37 {
38  namespace gm
39  {
40 // Forward declaration
41  class Curve;
42 
43  /*!
44  \class CurvePolygon
45 
46  \brief CurvePolygon is a planar surface defined by 1 exterior boundary and 0 or more interior boundaries.
47 
48  \ingroup geometry
49 
50  \sa Geometry,
51  AbstractPoint, Point, PointM, PointZ, PointZM, PointKd,
52  Curve, LineString, LinearRing, Line, CircularString, CompoundCurve,
53  Surface, Triangle, Polygon, PolyhedralSurface, TIN,
54  GeometryCollection, MultiSurface, MultiCurve,
55  MultiPoint, MultiLineString, MultiPolygon
56  */
58  {
59  public:
60 
62 
63  /** @name Initializer methods on geometric objects
64  * Methods for initializing a geometric object.
65  */
66  //@{
67 
68  /*!
69  \brief It initializes the curve polygon with the specified spatial reference system id and envelope.
70 
71  \param nRings The number of rings forming the curve polygon.
72  \param t The internal type of the curve polygon.
73  \param srid The Spatial Reference System ID associated to the curve polygon.
74  \param mbr The minimum bounding rectangle of this geometry (i.e., its envelope). It may be a NULL value.
75 
76  \note The curve polygon will take the ownership of the given mbr.
77 
78  \warning Set all nRing informed, otherwise you can not use methods like computeMBR().
79  */
80  CurvePolygon(std::size_t nRings, GeomType t, int srid = 0, Envelope* mbr = 0);
81 
82  /*!
83  \brief Copy constructor.
84 
85  \param rhs The other geometry.
86  */
87  CurvePolygon(const CurvePolygon& rhs);
88 
89  /*! \brief Virtual destructor. */
90  virtual ~CurvePolygon();
91 
92  /*!
93  \brief Assignment operator.
94 
95  \param rhs The other geometry.
96 
97  \return A reference for this.
98  */
99  virtual CurvePolygon& operator=(const CurvePolygon& rhs);
100 
101  //@}
102 
103  /** @name Re-Implementation from AbstractData
104  * Methods re-Implementated from AbstractData.
105  */
106  //@{
107 
108  /*!
109  \brief It clones the linestring.
110 
111  \return A copy of the given linestring.
112 
113  \note The caller of this method will take the ownership of the returned linestring.
114 
115  \note The cloned linestring will not have the
116  MBR computed. This will save time when you
117  are just cloning a geometry and don't intend
118  to waste time computing the bounding box.
119  If you have another suggestion, please, let me know.
120  */
121  virtual te::dt::AbstractData* clone() const;
122 
123  //@}
124 
125  /** @name CurvePolygon Specific Methods
126  * Specific methods for a CurvePolygon.
127  */
128  //@{
129 
130  /*!
131  \brief It returns the exterior ring of this CurvePolygon.
132 
133  \return The exterior ring of this CurvePolygon.
134 
135  \note Don't call this method for a empty polygon.
136  */
137  Curve* getExteriorRing() const;
138 
139  /*!
140  \brief It returns the number of interior rings in this CurvePolygon.
141 
142  \return The number of interior rings in this CurvePolygon.
143  */
144  std::size_t getNumInteriorRings() const;
145 
146  /*!
147  \brief It returns the number of rings in this CurvePolygon.
148 
149  \return The number of rings in this CurvePolygon.
150 
151  \note TerraLib extended method.
152  */
153  std::size_t getNumRings() const
154  {
155  return m_rings.size();
156  }
157 
158  /*!
159  \brief It sets the number of rings in this curve polygon.
160 
161  If the new size is less than the old it will drop the geometries.
162 
163  \param size The new number of rings for the curve polygon.
164 
165  \note TerraLib extended method.
166  */
167  void setNumRings(std::size_t size);
168 
169  /*!
170  \brief It returns the n-th interior ring for this curve polygon as a curve.
171 
172  \param i The ring index.
173 
174  \note The interior ring index start at 0.
175 
176  \note It doesn't check the index range.
177  */
178  Curve* getInteriorRingN(std::size_t i) const;
179 
180  /*!
181  \brief It returns the n-th ring for this curve polygon as a curve.
182 
183  \param i The ring index.
184 
185  \return The n-th ring.
186 
187  \note The ring index start at 0.
188 
189  \note It doesn't check the index range.
190 
191  \note TerraLib extended method.
192  */
193  Curve* getRingN(std::size_t i) const
194  {
195  assert(i < m_rings.size());
196  return m_rings[i];
197  }
198 
199  /*!
200  \brief It returns the n-th ring.
201 
202  \param i The coordinate index.
203 
204  \return The n-th ring.
205 
206  \note The ring index start at 0.
207  */
208  Curve* operator[](std::size_t i) const
209  {
210  assert(i < m_rings.size());
211  return m_rings[i];
212  }
213 
214  /*!
215  \brief It returns the n-th ring.
216 
217  \param i The coordinate index.
218 
219  \note The ring index start at 0.
220 
221  \return The n-th ring.
222  */
223  Curve* operator[](std::size_t i)
224  {
225  assert(i < m_rings.size());
226  return m_rings[i];
227  }
228 
229  /*!
230  \brief It sets the informed position ring to the new one.
231 
232  \param i The ring index.
233  \param r The new ring to be placed in the informed position.
234 
235  \note The ring index start at 0.
236 
237  \note If the informed position contains a ring, it will be released.
238 
239  \note It doesn't check the index range.
240 
241  \note TerraLib extended method.
242  */
243  void setRingN(std::size_t i, Curve* r);
244 
245  /*!
246  \brief It removes the n-th ring in this CurvePolygon.
247 
248  \param i The index of the ring we want to remove.
249 
250  \note The ring index start at 0.
251 
252  \note The memory pointed by ring will be released.
253 
254  \note It doesn't check the index range.
255 
256  \note TerraLib extended method.
257  */
258  void removeRingN(std::size_t i);
259 
260  /*!
261  \brief It adds the ring to the curve polygon.
262 
263  \param ring The ring to be added.
264 
265  \note TerraLib extended method.
266  */
267  void add(Curve* ring)
268  {
269  m_rings.push_back(ring);
270  }
271 
272  /*!
273  \brief It adds the curve to the curve polygon.
274 
275  \param ring The ring to be added.
276 
277  \note TerraLib extended method.
278  */
279  void push_back(Curve* ring)
280  {
281  m_rings.push_back(ring);
282  }
283 
284  /*!
285  \brief It deletes all the rings of the CurvePolygon and clear it.
286 
287  \note TerraLib extended method.
288  */
289  void clear();
290 
291  /*!
292  \brief It returns the polygon rings.
293 
294  \return A reference to the list of rings.
295 
296  \warning Don't use this method unless you know exactly what you're doing!
297 
298  \note TerraLib extended method.
299  */
300  std::vector<Curve*>& getRings() { return m_rings; }
301 
302  /*!
303  \brief It returns the polygon rings.
304 
305  \return A reference to the list of rings.
306 
307  \warning Don't use this method unless you know exactly what you're doing!
308 
309  \note TerraLib extended method.
310  */
311  const std::vector<Curve*>& getRings() const { return m_rings; }
312 
313  //@}
314 
315  /** @name Surface Specific Methods
316  * Specific methods for a Surface.
317  */
318  //@{
319 
320  /*!
321  \brief It returns the area of this surface, as measured in the spatial reference system of this surface.
322 
323  \return The area of this surface.
324  */
325  double getArea() const;
326 
327  /*!
328  \brief It returns the mathematical centroid for this surface as a point.
329 
330  \return The mathematical centroid for this surface.
331 
332  \note The caller of this method will take the ownership of the returned point.
333  \note The result is not guaranteed to be on this Surface.
334  */
335  Point* getCentroid() const;
336 
337  /*!
338  \brief It returns the mathematical centroid for this surface as a coordinate.
339 
340  \return The mathematical centroid for this surface.
341 
342  \note The caller of this method will take the ownership of the returned coordinate.
343  \note The result is not guaranteed to be on this Surface.
344  \note TerraLib extended method.
345  */
346  Coord2D* getCentroidCoord() const;
347 
348  /*!
349  \brief It returns a point guaranteed to be on this surface.
350 
351  \return A point guaranteed to be on this surface.
352 
353  \note The caller of this method will take the ownership of the returned point.
354  */
355  Point* getPointOnSurface() const;
356 
357  /*!
358  \brief It returns a coordinate guaranteed to be on this surface.
359 
360  \return A point guaranteed to be on this surface.
361 
362  \note The caller of this method will take the ownership of the returned coordinate.
363 
364  \note TerraLib extended method.
365  */
366  Coord2D* getCoordOnSurface() const;
367 
368  /*!
369  \brief It returns the length of the boundary for the surface.
370 
371  \return The length of the boundary for the surface.
372  */
373  double getPerimeter() const;
374 
375  //@}
376 
377  /** @name Re-Implmentation of methods from Geometry class
378  * Re-Implmentation of basic methods from Geometry class.
379  */
380  //@{
381 
382  /*!
383  \brief The name of the geometry subtype for curve polygons is: CurvePolygon.
384 
385  \return The name of the geometry subtype for curve polygons is: CurvePolygon.
386  */
387  virtual const std::string& getGeometryType() const throw();
388 
389  /*!
390  \brief It sets the Spatial Reference System ID of the geometry and all its parts if it is a GeometryCollection (or a Multi).
391 
392  \param srid The Spatial Reference System ID to be associated to the geometric object.
393 
394  \note This method just set the srid, it doesn't perform conversions over coordinate values.
395 
396  \note TerraLib extended method.
397  */
398  void setSRID(int srid) throw();
399 
400  /*!
401  \brief It converts the coordinate values of the geometry to the new spatial reference system.
402 
403  After calling this method the geometry will be associated to the new SRID.
404 
405  \param srid The new Spatial Reference System ID used to transform the coordinates of the geometry.
406 
407  \exception Exception It will throw an exception if it can not do the transformation.
408 
409  \note The geometry must be associated to a valid SRID before calling this method.
410 
411  \note If the geometry already has an associated MBR, this method will automatically update it (i. e. automatically recompute it).
412  */
413  void transform(int srid) throw(te::common::Exception);
414 
415  /*!
416  \brief It computes the minimum bounding rectangle for the curve polygon.
417 
418  \param cascade If true, it will update the MBR of its parts.
419 
420  \note You can use this method in order to update the MBR of the curve polygon.
421  .
422  \note TerraLib extended method.
423  */
424  void computeMBR(bool cascade) const throw();
425 
426  /*!
427  \brief it returns the number of points (vertexes) in the geometry.
428 
429  \return The number of points (vertexes) in the geometry.
430 
431  \note TerraLib extended method.
432  */
433  std::size_t getNPoints() const throw();
434 
435  //@}
436 
437  private:
438 
439  std::vector<Curve*> m_rings; //!< An array with the ring list.
440 
441  static const std::string sm_typeName; //! Geometry type name for CurvePolygon.
442  };
443 
444  } // end namespace gm
445 } // end namespace te
446 
447 #endif // __TERRALIB_GEOMETRY_INTERNAL_CURVEPOLYGON_H
448 
449 
450 
451 
std::size_t getNumRings() const
It returns the number of rings in this CurvePolygon.
Definition: CurvePolygon.h:153
void add(Curve *ring)
It adds the ring to the curve polygon.
Definition: CurvePolygon.h:267
void push_back(Curve *ring)
It adds the curve to the curve polygon.
Definition: CurvePolygon.h:279
std::vector< Curve * > & getRings()
It returns the polygon rings.
Definition: CurvePolygon.h:300
GeomType
Each enumerated type is compatible with a Well-known Binary (WKB) type code.
Definition: Enums.h:41
Curve * operator[](std::size_t i)
It returns the n-th ring.
Definition: CurvePolygon.h:223
Base exception class for plugin module.
Definition: Exception.h:42
Curve is an abstract class that represents 1-dimensional geometric objects stored as a sequence of co...
Definition: Curve.h:58
An utility struct for representing 2D coordinates.
Definition: Coord2D.h:40
#define TEGEOMEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:76
Curve
Definition: Enums.h:71
const std::vector< Curve * > & getRings() const
It returns the polygon rings.
Definition: CurvePolygon.h:311
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.
Surface is an abstract class that represents a 2-dimensional geometric objects.
CurvePolygon is a planar surface defined by 1 exterior boundary and 0 or more interior boundaries...
Definition: CurvePolygon.h:57
A base class for values that can be retrieved from the data access module.
Definition: AbstractData.h:57
#define TE_DEFINE_VISITABLE
Definition: BaseVisitable.h:75
Curve * operator[](std::size_t i) const
It returns the n-th ring.
Definition: CurvePolygon.h:208
Curve * getRingN(std::size_t i) const
It returns the n-th ring for this curve polygon as a curve.
Definition: CurvePolygon.h:193
Surface is an abstract class that represents a 2-dimensional geometric objects.
Definition: Surface.h:54