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  /*!
270  \brief It adds the curve to the curve polygon.
271 
272  \param ring The ring to be added.
273 
274  \note TerraLib extended method.
275  */
276  void push_back(Curve* ring);
277 
278  /*!
279  \brief It deletes all the rings of the CurvePolygon and clear it.
280 
281  \note TerraLib extended method.
282  */
283  void clear();
284 
285  /*!
286  \brief It returns the polygon rings.
287 
288  \return A reference to the list of rings.
289 
290  \warning Don't use this method unless you know exactly what you're doing!
291 
292  \note TerraLib extended method.
293  */
294  std::vector<Curve*>& getRings() { return m_rings; }
295 
296  /*!
297  \brief It returns the polygon rings.
298 
299  \return A reference to the list of rings.
300 
301  \warning Don't use this method unless you know exactly what you're doing!
302 
303  \note TerraLib extended method.
304  */
305  const std::vector<Curve*>& getRings() const { return m_rings; }
306 
307  //@}
308 
309  /** @name Surface Specific Methods
310  * Specific methods for a Surface.
311  */
312  //@{
313 
314  /*!
315  \brief It returns the area of this surface, as measured in the spatial reference system of this surface.
316 
317  \return The area of this surface.
318  */
319  double getArea() const;
320 
321  /*!
322  \brief It returns the mathematical centroid for this surface as a point.
323 
324  \return The mathematical centroid for this surface.
325 
326  \note The caller of this method will take the ownership of the returned point.
327  \note The result is not guaranteed to be on this Surface.
328  */
329  Point* getCentroid() const;
330 
331  /*!
332  \brief It returns the mathematical centroid for this surface as a coordinate.
333 
334  \return The mathematical centroid for this surface.
335 
336  \note The caller of this method will take the ownership of the returned coordinate.
337  \note The result is not guaranteed to be on this Surface.
338  \note TerraLib extended method.
339  */
340  Coord2D* getCentroidCoord() const;
341 
342  /*!
343  \brief It returns a point guaranteed to be on this surface.
344 
345  \return A point guaranteed to be on this surface.
346 
347  \note The caller of this method will take the ownership of the returned point.
348  */
349  Point* getPointOnSurface() const;
350 
351  /*!
352  \brief It returns a coordinate guaranteed to be on this surface.
353 
354  \return A point guaranteed to be on this surface.
355 
356  \note The caller of this method will take the ownership of the returned coordinate.
357 
358  \note TerraLib extended method.
359  */
360  Coord2D* getCoordOnSurface() const;
361 
362  /*!
363  \brief It returns the length of the boundary for the surface.
364 
365  \return The length of the boundary for the surface.
366  */
367  double getPerimeter() const;
368 
369  //@}
370 
371  /** @name Re-Implmentation of methods from Geometry class
372  * Re-Implmentation of basic methods from Geometry class.
373  */
374  //@{
375 
376  /*!
377  \brief The name of the geometry subtype for curve polygons is: CurvePolygon.
378 
379  \return The name of the geometry subtype for curve polygons is: CurvePolygon.
380  */
381  virtual const std::string& getGeometryType() const throw();
382 
383  /*!
384  \brief It sets the Spatial Reference System ID of the geometry and all its parts if it is a GeometryCollection (or a Multi).
385 
386  \param srid The Spatial Reference System ID to be associated to the geometric object.
387 
388  \note This method just set the srid, it doesn't perform conversions over coordinate values.
389 
390  \note TerraLib extended method.
391  */
392  void setSRID(int srid) throw();
393 
394  /*!
395  \brief It converts the coordinate values of the geometry to the new spatial reference system.
396 
397  After calling this method the geometry will be associated to the new SRID.
398 
399  \param srid The new Spatial Reference System ID used to transform the coordinates of the geometry.
400 
401  \exception Exception It will throw an exception if it can not do the transformation.
402 
403  \note The geometry must be associated to a valid SRID before calling this method.
404 
405  \note If the geometry already has an associated MBR, this method will automatically update it (i. e. automatically recompute it).
406  */
407  void transform(int srid) throw(te::common::Exception);
408 
409  /*!
410  \brief It computes the minimum bounding rectangle for the curve polygon.
411 
412  \param cascade If true, it will update the MBR of its parts.
413 
414  \note You can use this method in order to update the MBR of the curve polygon.
415  .
416  \note TerraLib extended method.
417  */
418  void computeMBR(bool cascade) const throw();
419 
420  /*!
421  \brief it returns the number of points (vertexes) in the geometry.
422 
423  \return The number of points (vertexes) in the geometry.
424 
425  \note TerraLib extended method.
426  */
427  std::size_t getNPoints() const throw();
428 
429  //@}
430 
431  private:
432 
433  std::vector<Curve*> m_rings; //!< An array with the ring list.
434 
435  static const std::string sm_typeName; //! Geometry type name for CurvePolygon.
436  };
437 
438  } // end namespace gm
439 } // end namespace te
440 
441 #endif // __TERRALIB_GEOMETRY_INTERNAL_CURVEPOLYGON_H
442 
443 
444 
445 
std::size_t getNumRings() const
It returns the number of rings in this CurvePolygon.
Definition: CurvePolygon.h:153
std::vector< Curve * > & getRings()
It returns the polygon rings.
Definition: CurvePolygon.h:294
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:305
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