Geometry.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/Geometry.h
22 
23  \brief Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
24 */
25 
26 #ifndef __TERRALIB_GEOMETRY_INTERNAL_GEOMETRY_H
27 #define __TERRALIB_GEOMETRY_INTERNAL_GEOMETRY_H
28 
29 // TerraLib
30 #include "../common/BaseVisitable.h"
31 #include "../common/Enums.h"
32 #include "../datatype/AbstractData.h"
33 #include "Coord2D.h"
34 #include "Enums.h"
35 #include "Exception.h"
36 #include "Visitor.h"
37 
38 // STL
39 #include <exception>
40 #include <map>
41 #include <string>
42 
43 // Boost
44 #include <boost/shared_ptr.hpp>
45 
46 namespace te
47 {
48  namespace gm
49  {
50 // Forward declarations
51  class Envelope;
52 
53  /*!
54  \class Geometry
55 
56  \brief Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
57 
58  The geometry model follows OGC Simple Feature
59  Specification - SFS (Simple Feature Access - Part 1: Common Architecture)
60  and ISO SQL/MM Spatial.
61 
62  \ingroup geometry
63 
64  \sa AbstractPoint, Point, PointM, PointZ, PointZM, PointKd,
65  Curve, LineString, LinearRing, Line, CircularString, CompoundCurve,
66  Surface, CurvePolygon, Polygon, Triangle, PolyhedralSurface, TIN,
67  GeometryCollection, MultiCurve, MultiSurface,
68  MultiPoint, MultiLineString, MultiPolygon
69 
70  \note Methods marked as <b>extended</b> are not from OGC or ISO specifications, but they enhances the TerraLib API.
71 
72  \note Methods performed by another library are marked as <b>Performed by Library-Name</b>.
73  */
75  {
76  public:
77 
79 
80  /** @name Initializer methods on geometric objects
81  * Methods for initializing a geometric object.
82  */
83  //@{
84 
85  /*!
86  \brief It initializes the Geometry with the specified spatial reference system id and envelope.
87 
88  \param t The internal geometry type.
89  \param srid The Spatial Reference System ID associated to the geometry.
90  \param mbr The envelope (minimum bounding rectangle of this geometry).
91 
92  \note The geometry will take the ownership of the given mbr.
93  */
94  Geometry(GeomType t, int srid = 0, Envelope* mbr = 0) throw();
95 
96  /*!
97  \brief Copy constructor.
98 
99  \param rhs The other geometry.
100  */
101  Geometry(const Geometry& rhs) throw();
102 
103  /*! \brief Virtual destructor. */
104  virtual ~Geometry();
105 
106  /*!
107  \brief Assignment operator.
108 
109  \param rhs The right-hand-side geometry.
110 
111  \return A reference for this.
112  */
113  virtual Geometry& operator=(const Geometry& rhs) throw();
114 
115  //@}
116 
117  /** @name Basic Geometry Methods
118  * Basic methods on geometric objects.
119  */
120  //@{
121 
122  /*!
123  \brief It returns the geometric object dimension (0, 1 or 2).
124 
125  For a GeometryCollection it returns the largest topological
126  dimension of the contained objects. For Point and MultiPoint this will return 0.
127  For Curves and MultiCurves (LineString, LinearRing and MultiLineString) it will
128  return 1. For Surfaces (Polygon, Triangle, PolyhedralSurface, TIN) and
129  MultiSurfaces (MultiPolygon) it will return 2.
130 
131  \return The geometric object dimension (0, 1 or 2).
132  */
133  virtual Dimensionality getDimension() const throw() = 0;
134 
135  /*!
136  \brief It returns the number of measurements or axes needed to describe a position in a coordinate system.
137 
138  It returns:
139  <ul>
140  <li>2 for a coordinate with x, y;</li>
141  <li>3 for a coordinate with x, y and z or x, y and m;</li>
142  <li>4 for a coordinate with x, y, z and m.</li>
143  </ul>
144 
145  \return The number of measurements or axes needed to describe a position in a coordinate system.
146 
147  \note This is NOT the same as getDimension() method!
148  */
149  int getCoordinateDimension() const throw();
150 
151  /*!
152  \brief It returns the name of the geometry subclass.
153 
154  The name of the geometry subclass may be one of the following:
155  <ul>
156  <li>Point</li>
157  <li>LineString</li>
158  <li>Polygon</li>
159  <li>GeometryCollection</li>
160  <li>MultiPoint</li>
161  <li>MultiLineString</li>
162  <li>MultiPolygon</li>
163  <li>Tin</li>
164  </ul>
165 
166  \return The name of the geometry subclass type ide.
167  */
168  virtual const std::string& getGeometryType() const throw() = 0;
169 
170  /*!
171  \brief It returns the geometry subclass type identifier.
172 
173  \return The geometry subclass type identifier
174 
175  \note Please, see GeomType enumeration for possible return values.
176 
177  \note TerraLib extended method.
178  */
179  GeomType getGeomTypeId() const throw() { return m_gType; }
180 
181  /*!
182  \brief It returns the name of 2D geometry subclass.
183 
184  The name of the 2D geometry subclass may be one of the following:
185  <ul>
186  <li>Geometry </li>
187  <li>Point </li>
188  <li>LineString </li>
189  <li>Polygon </li>
190  <li>MultiPoint </li>
191  <li>MultiLineString </li>
192  <li>MultiPolygon </li>
193  <li>GeometryCollection </li>
194  <li>CircularString </li>
195  <li>CompoundCurve </li>
196  <li>CurvePolygon </li>
197  <li>MultiSurface </li>
198  </ul>
199 
200  \return The name of the geometry subclass type ide.
201  */
202  virtual const std::string get2DGeometryType() const throw();
203 
204  /*!
205  \brief It returns the 2D geometry subclass type identifier.
206 
207  <ul>
208  <li>GeometryType = 0</li>
209  <li>PointType = 1</li>
210  <li>LineStringType = 2</li>
211  <li>PolygonType = 3</li>
212  <li>MultiPointType = 4</li>
213  <li>MultiLineStringType = 5</li>
214  <li>MultiPolygonType = 6</li>
215  <li>GeometryCollectionType = 7</li>
216  <li>CircularStringType = 8</li>
217  <li>CompoundCurveType = 9</li>
218  <li>CurvePolygonType = 10</li>
219  <li>MultiSurfaceType = 12</li>
220  </ul>
221 
222  \return The 2D geometry subclass type identifier
223 
224  \note Please, see GeomType enumeration for possible return values.
225 
226  \note TerraLib extended method.
227  */
228  virtual GeomType get2DGeomTypeId() const throw();
229 
230  /*!
231  \brief It returns the Spatial Reference System ID associated to this geometric object.
232 
233  This value can be used to identify the associated Spatial Reference System.
234 
235  \return The Spatial Reference System ID associated to this geometric object.
236 
237  \note When not set this value will be -1.
238  */
239  int getSRID() const throw() { return m_srid; }
240 
241  /*!
242  \brief It sets the Spatial Reference System ID of the geometry and all its parts if it is a GeometryCollection (or a Multi).
243 
244  \param srid The Spatial Reference System ID to be associated to the geometric object.
245 
246  \note This method just set the srid, it doesn't perform conversions over coordinate values.
247 
248  \note TerraLib extended method.
249  */
250  virtual void setSRID(int srid) throw() = 0;
251 
252  /*!
253  \brief It converts the coordinate values of the geometry to the new spatial reference system.
254 
255  After calling this method the geometry will be associated to the new SRID.
256 
257  \param srid The new Spatial Reference System ID used to transform the coordinates of the geometry.
258 
259  \exception Exception It will throw an exception if it can not do the transformation.
260 
261  \note The geometry must be associated to a valid SRID before calling this method.
262 
263  \note If the geometry already has an associated MBR, this method will automatically update it (i. e. automatically recompute it).
264  */
265  virtual void transform(int srid) throw(te::common::Exception) = 0;
266 
267  /*!
268  \brief It returns the minimum bounding rectangle (MBR) for the geometry.
269 
270  As one can notice, the mbr is returned as a geometry, actually a polygon
271  defined by the corner points of the bounding box [(MINX, MINY), (MAXX, MINY), (MAXX, MAXY), (MINX, MAXY), (MINX, MINY)].
272 
273  \return The geometry envelope (or mbr).
274 
275  \note The caller of this method will take the ownership of the returned geometry.
276 
277  \note If the MBR was not computed previously, it will compute it. Successive
278  calls to this method will not compute the mbr anymore.
279  */
280  Geometry* getEnvelope() const throw();
281 
282  /*!
283  \brief It returns the minimum bounding rectangle for the geometry in an internal representation.
284 
285  The mbr can be constructed when reading a geometry from a database or
286  it can be computed internally. So, if the mbr is not already set
287  it will compute it just when this method is called. Successive
288  calls to this method will not compute the mbr anymore.
289 
290  \return The envelope of this geometry (i.e., the minimum bounding rectangle).
291 
292  \note It is supposed to be faster and more useful than getting the box as a polygon geometry.
293 
294  \note TerraLib extended method.
295  */
296  const Envelope* getMBR() const throw();
297 
298  /*!
299  \brief It computes the minimum bounding rectangle for the geometry.
300 
301  Subclasses must implement this method in order
302  to be able to compute the minimum bounding box of
303  a specific geometry.
304 
305  \param cascade If true it will update the MBR for its sub-geometries.
306 
307  \note You can use this method in order to update the MBR of the Geometry.
308 
309  \note TerraLib extended method.
310  */
311  virtual void computeMBR(bool cascade) const throw() = 0;
312 
313  /*!
314  \brief It returns an string with the Well-Known Text Representation for the geometry.
315 
316  \return The WKT for the Geometry.
317  */
318  std::string asText() const throw();
319 
320  /*!
321  \brief It serializes the geometric object to a Well-known Binary Representation (WKB).
322 
323  \param size The size in bytes of the returned WKB.
324 
325  \return The WKB representation for this object.
326 
327  \exception Exception It will throw an exception if the operation could not be performed.
328 
329  \note The WKB will be on machine byte order.
330 
331  \note The caller of this method will take the ownership of the returned wkb.
332  You must use "delete [] pointer" in order to free the memory pointed by returned pointer.
333  */
334  char* asBinary(std::size_t& size) const throw(Exception);
335 
336  /*!
337  \brief It returns the size required by a WKB representation for this geometric object.
338 
339  This is the preferred method for creating a WKB. First of all,
340  it gives you the possibility to use a pre-allocated buffer. So,
341  this method can be used in conjunction with the getWkb method.
342 
343  \return The size required by a WKB representation for the geometry object.
344 
345  \note TerraLib extended method.
346  */
347  std::size_t getWkbSize() const throw();
348 
349  /*!
350  \brief It serializes the geometry to a WKB representation into the specified buffer.
351 
352  The wkb parameter must have at least getWkbSize() in order to be used. Don't
353  pass a NULL pointer or a buffer smaller than the size needed. Note that
354  the WKB will be on the specified byte order.
355 
356  \param wkb The buffer where the Geometry will be serialized.
357  \param byteOrder The byte order used to store/serialize the geometry.
358 
359  \exception Exception It will throw an exception if the operation could not be performed.
360 
361  \note TerraLib extended method.
362  */
363  void getWkb(char* wkb, te::common::MachineByteOrder byteOrder) const throw(Exception);
364 
365  /*!
366  \brief It returns true if this geometric object is the empty Geometry.
367 
368  If true, then this geometric object represents the empty point set
369  for the coordinate space.
370 
371  \return True if this geometric object is the empty Geometry.
372 
373  \exception std::exception It will throw an exception if the operation could not be performed.
374 
375  \note Performed by GEOS.
376  */
377  virtual bool isEmpty() const throw(std::exception);
378 
379  /*!
380  \brief It returns true if this geometric object has no anomalous points, such as self intersection or self tangency.
381 
382  See the ISO and OGC documentation for an explanation about specific conditions
383  of each type of geometry to be considered not simple.
384 
385  \return True if this geometric object has no anomalous geometric points.
386 
387  \exception std::exception It will throw an exception if the operation could not be performed.
388 
389  \note Performed by GEOS.
390  */
391  virtual bool isSimple() const throw(std::exception);
392 
393  /*!
394  \brief It tells if the geometry is well formed.
395 
396  \exception std::exception It will throw an exception if the operation could not be performed.
397 
398  \note TerraLib extended method.
399 
400  \note Performed by GEOS.
401  */
402  virtual bool isValid() const throw(std::exception);
403 
404  /*!
405  \brief It returns true if this geometric object has z coordinate values.
406 
407  \return True if this geometric object has z coordinate values.
408  */
409  bool is3D() const throw();
410 
411  /*!
412  \brief It returns true if this geometric object has m coordinate values.
413 
414  \return True if this geometric object has m coordinate values.
415  */
416  bool isMeasured() const throw();
417 
418  /*!
419  \brief It returns true if this geometric object is a collection.
420 
421  \return True if this geometric object is a collection.
422  */
423  bool isCollection() const throw();
424 
425  /*!
426  \brief It returns the geometry boundary.
427 
428  \return The geometry that makes the boundary of this geometry. The caller of this method will
429  take the ownership of the returned geometry.
430 
431  \exception std::exception It will throw an exception if the operation could not be performed.
432 
433  \note The caller of this method will take the ownership of the returned Geometry.
434 
435  \note Performed by GEOS.
436  */
437  virtual Geometry* getBoundary() const throw(std::exception);
438 
439  /*!
440  \brief It will get the centroid of the input geometries.
441 
442  \exception std::exception It will throw an exception if the operation could not be performed.
443 
444  \return a Point containing the centroid coord.
445  */
446  te::gm::Coord2D getCentroid() const throw(std::exception);
447 
448  /*!
449  \brief it returns the number of points (vertexes) in the geometry.
450 
451  \return The number of points (vertexes) in the geometry.
452 
453  \note TerraLib extended method.
454  */
455  virtual std::size_t getNPoints() const throw() = 0;
456 
457  //@}
458 
459  /** @name Spatial Relations
460  * Methods for testing spatial relations between geometric objects.
461  * Please, see OGC specification for a in depth definition of each spatial operation.
462  */
463  //@{
464 
465  /*!
466  \brief It returns true if the geometry object is spatially equal to rhs geometry.
467 
468  \param rhs The another geometry to be compared.
469  \param exact If true checks if this geometric object has the same vertexes in the same order of rhs geometry.
470 
471  \return True if the geometry is spatially equal to the other geometry.
472 
473  \exception std::exception It will throw an exception if the operation could not be performed.
474 
475  \warning Don't call this method for a Heterogeneous GeometryCollection, otherwise an exception will be thrown.
476 
477  \note Performed by GEOS.
478  */
479  virtual bool equals(const Geometry* const rhs, const bool exact = false) const throw(std::exception);
480 
481  /*!
482  \brief It returns true if the geometry object is spatially disjoint from rhs geometry.
483 
484  \param rhs The other geometry to be compared.
485 
486  \return True if the geometry is spatially disjoint from the other geometry.
487 
488  \exception std::exception It will throw an exception if the operation could not be performed.
489 
490  \warning Don't call this method for a Heterogeneous GeometryCollection, otherwise, an exception will be thrown.
491 
492  \note Performed by GEOS.
493  */
494  virtual bool disjoint(const Geometry* const rhs) const throw(std::exception);
495 
496  /*!
497  \brief It returns true if the geometry object spatially intersects rhs geometry.
498 
499  \param rhs The other geometry to be compared.
500 
501  \return True if the geometry intersects the other geometry.
502 
503  \exception std::exception It will throw an exception if the operation could not be performed.
504 
505  \warning Don't call this method for a Heterogeneous GeometryCollection, otherwise, an exception will be thrown.
506 
507  \note Performed by GEOS.
508  */
509  virtual bool intersects(const Geometry* const rhs) const throw(std::exception);
510 
511  /*!
512  \brief It returns true if the geometry object spatially touches rhs geometry.
513 
514  \param rhs The other geometry to be compared.
515 
516  \return True if the geometry spatially touches the other geometry.
517 
518  \exception std::exception It will throw an exception if the operation could not be performed.
519 
520  \warning Don't call this method for a Heterogeneous GeometryCollection, otherwise, an exception will be thrown.
521 
522  \note Performed by GEOS.
523  */
524  virtual bool touches(const Geometry* const rhs) const throw(std::exception);
525 
526  /*!
527  \brief It returns true if the geometry object spatially crosses rhs geometry.
528 
529  \param rhs The other geometry to be compared.
530 
531  \return True if the geometry spatially crosses the other geometry.
532 
533  \exception std::exception It will throw an exception if the operation could not be performed.
534 
535  \warning Don't call this method for a Heterogeneous GeometryCollection, otherwise, an exception will be thrown.
536 
537  \note Performed by GEOS.
538  */
539  virtual bool crosses(const Geometry* const rhs) const throw(std::exception);
540 
541  /*!
542  \brief It returns true if the geometry object is spatially within rhs geometry.
543 
544  \param rhs The other geometry to be compared.
545 
546  \return True if the geometry is spatially within the other geometry.
547 
548  \exception std::exception It will throw an exception if the operation could not be performed.
549 
550  \warning Don't call this method for a Heterogeneous GeometryCollection, otherwise, an exception will be thrown.
551 
552  \note Performed by GEOS.
553  */
554  virtual bool within(const Geometry* const rhs) const throw(std::exception);
555 
556  /*!
557  \brief It returns true if this geometry object spatially contains rhs geometry.
558 
559  \param rhs The other geometry to be compared.
560 
561  \return True if the geometry spatially contains the other geometry.
562 
563  \exception std::exception It will throw an exception if the operation could not be performed.
564 
565  \warning Don't call this method for a Heterogeneous GeometryCollection, otherwise, an exception will be thrown.
566 
567  \note Performed by GEOS.
568  */
569  virtual bool contains(const Geometry* const rhs) const throw(std::exception);
570 
571  /*!
572  \brief It returns true if this geometry object spatially overlaps rhs geometry.
573 
574  \param rhs The other geometry to be compared.
575 
576  \return True if the geometry spatially overlaps the other geometry.
577 
578  \exception std::exception It will throw an exception if the operation could not be performed.
579 
580  \warning Don't call this method for a Heterogeneous GeometryCollection, otherwise, an exception will be thrown.
581 
582  \note Performed by GEOS.
583  */
584  virtual bool overlaps(const Geometry* const rhs) const throw(std::exception);
585 
586  /*!
587  \brief It returns true if this geometry object is spatially related to rhs geometry according to the pattern expressed by the intersection matrix.
588 
589  It does this by testing for intersections between the interior,
590  boundary and exterior of the two geometric objects as specified
591  by the values in the matrix.
592 
593  \param rhs The other geometry to be compared.
594  \param matrix The intersection matrix.
595 
596  \return True if the geometry is spatially related to the other geometry according to the pattern expressed by the intersection matrix.
597 
598  \exception std::exception It will throw an exception if the operation could not be performed.
599 
600  \warning Don't call this method for a Heterogeneous GeometryCollection, otherwise, an exception will be thrown.
601 
602  \note Performed by GEOS.
603  */
604  virtual bool relate(const Geometry* const rhs, const std::string& matrix) const throw(std::exception);
605 
606  /*!
607  \brief It returns the spatial relation between this geometry object and the rhs geometry.
608 
609  \param rhs The another geometry to be compared.
610 
611  \return A string where each byte is a intersection in the pattern intersection matrix of the relationship of the two objects.
612 
613  \exception std::exception It will throw an exception if the operation could not be performed.
614 
615  \warning Don't call this method for a Heterogeneous GeometryCollection, otherwise, an exception will be thrown.
616 
617  \note TerraLib extended method.
618 
619  \note This method will be handy when you don't know the spatial relation in advance.
620 
621  \note Performed by GEOS.
622  */
623  virtual std::string relate(const Geometry* const rhs) const throw(std::exception);
624 
625  /*!
626  \brief It returns true if this geometry object spatially covers the rhs geometry.
627 
628  \param rhs The other geometry to be compared.
629 
630  \return True if the geometry spatially covers the other geometry.
631 
632  \exception std::exception It will throw an exception if the operation could not be performed.
633 
634  \warning Don't call this method for a Heterogeneous GeometryCollection, otherwise, an exception will be thrown.
635 
636  \note TerraLib extended method.
637 
638  \note This is not the same as contains. See Max Egenhofer paper on 9-intersection matrix.
639 
640  \note Performed by GEOS.
641  */
642  virtual bool covers(const Geometry* const rhs) const throw(std::exception);
643 
644  /*!
645  \brief It returns true if this geometry object is spatially covered by rhs geometry.
646 
647  \param rhs The other geometry to be compared.
648 
649  \return True if the geometry is spatially covered by the other geometry.
650 
651  \exception std::exception It will throw an exception if the operation could not be performed.
652 
653  \warning Don't call this method for a Heterogeneous GeometryCollection, otherwise, an exception will be thrown.
654 
655  \note TerraLib extended method.
656 
657  \note This is not the same as within. See Max Egenhofer paper on 9-intersection matrix.
658 
659  \note Performed by GEOS.
660  */
661  virtual bool coveredBy(const Geometry* const rhs) const throw(std::exception);
662 
663  /*!
664  \brief It returns a derived GeometryCollection value according to the specified coordinate value.
665 
666  \param mValue The coordinate value.
667 
668  \return A GeometryCollection value.
669 
670  \exception Exception It will throw an exception if the operation could not be performed.
671 
672  \note The caller of this method will take the ownership of the returned geometry.
673 
674  \note This method only applies to Point and Line geometries, including homogeneu collections of points or lines.
675  For polygons this will return a NULL value.
676  */
677  virtual Geometry* locateAlong(const double& mValue) const throw(Exception) { return locateBetween(mValue, mValue); };
678 
679  /*!
680  \brief It returns a derived geometry collection value according to the range of coordinate values inclusively.
681 
682  \param mStart The initial coordinate value.
683  \param mEnd The final coordinate value.
684 
685  \return A GeometryCollection value.
686 
687  \exception Exception It will throw an exception if the operation could not be performed.
688 
689  \note This method only applies to Point and Line geometries, including homogeneous collections of points or lines.
690  For polygons this will return a NULL value.
691 
692  \note The caller of this method will take the ownership of the returned Geometry.
693  */
694  virtual Geometry* locateBetween(const double& mStart, const double& mEnd) const throw(Exception);
695 
696  //@}
697 
698  /** @name Spatial Analysis
699  * Methods that support spatial analysis.
700  */
701  //@{
702 
703  /*!
704  \brief It returns the shortest distance between any two points in the two geometry objects.
705 
706  \param rhs The other geometry.
707 
708  \return The shortest distance between any two points in the two geometries.
709 
710  \exception std::exception It will throw an exception if the operation could not be performed.
711 
712  \note Performed by GEOS.
713  */
714  virtual double distance(const Geometry* const rhs) const throw(std::exception);
715 
716  /*!
717  \brief This method calculates the buffer of a geometry.
718 
719  \param distance Distance value.
720 
721  \return A geometry representing all points less than or equal to the specified distance.
722 
723  \exception std::exception It will throw an exception if the operation could not be performed.
724 
725  \note The caller of this method will take the ownership of the returned geometry.
726 
727  \note Performed by GEOS.
728  */
729  virtual Geometry* buffer(const double& distance) const throw(std::exception);
730 
731  /*!
732  \brief This method calculates the buffer of a geometry.
733 
734  \param distance Distance value.
735  \param quadrantSegments A specified number of segments used to approximate the curves.
736 
737  \return A geometry representing all points less than or equal to the specified distance.
738 
739  \exception std::exception It will throw an exception if the operation could not be performed.
740 
741  \note The caller of this method will take the ownership of the returned geometry.
742 
743  \note TerraLib extended method.
744 
745  \note Performed by GEOS.
746  */
747  virtual Geometry* buffer(const double& distance, int quadrantSegments) const throw(std::exception);
748 
749  /*!
750  \brief This method calculates the buffer of a geometry.
751 
752  As in GEOS, the quadrantSegments argument allows controlling the
753  accuracy of the approximation by specifying the number of line
754  segments used to represent a quadrant of a circle.
755 
756  \param distance Distance value.
757  \param quadrantSegments A specified number of segments used to approximate the curves.
758  \param endCapStyle It specifies the shape used at the ends of linestrings.
759 
760  \return A geometry representing all points less than or equal to the specified distance.
761 
762  \exception std::exception It will throw an exception if the operation could not be performed.
763 
764  \note The caller of this method will take the ownership of the returned Geometry.
765 
766  \note TerraLib extended method.
767 
768  \note Performed by GEOS.
769  */
770  virtual Geometry* buffer(const double& distance,
771  int quadrantSegments,
772  BufferCapStyle endCapStyle) const throw(std::exception);
773 
774  /*!
775  \brief This method calculates the Convex Hull of a geometry.
776 
777  \return A geometry representing the convex hull.
778 
779  \exception std::exception It will throw an exception if the operation could not be performed.
780 
781  \note The caller of this method will take the ownership of the returned geometry.
782 
783  \note Performed by GEOS.
784  */
785  virtual Geometry* convexHull() const throw(std::exception);
786 
787  /*!
788  \brief It returns a geometric object that represents the point set intersection with another geometry
789 
790  \param rhs The other Geometry whose intersection with this Geometry will be calculated.
791 
792  \return A Geometry representing the intersection with this Geometry.
793 
794  \exception std::exception It will throw an exception if the operation could not be performed.
795 
796  \warning Don't call this method for a Heterogeneous GeometryCollection, otherwise, an exception will be thrown.
797 
798  \note The caller of this method will take the ownership of the returned Geometry.
799 
800  \note Performed by GEOS.
801  */
802  virtual Geometry* intersection(const Geometry* const rhs) const throw(std::exception);
803 
804  /*!
805  \brief It returns a geometric object that represents the point set union with another geometry
806 
807  \param rhs Another geometry whose union with this geometry will be calculated.
808 
809  \return A geometry representing the union with this geometry.
810 
811  \exception std::exception It will throw an exception if the operation could not be performed.
812 
813  \warning Don't call this method for a Heterogeneous GeometryCollection, otherwise, an exception will be thrown.
814 
815  \note The caller of this method will take the ownership of the returned Geometry.
816 
817  \note Performed by GEOS.
818  */
819  virtual Geometry* Union(const Geometry* const rhs) const throw(std::exception);
820 
821  /*!
822  \brief It returns a geometric object that represents the point set difference with another geometry
823 
824  \param rhs Another geometry whose difference with this geometry will be calculated.
825 
826  \return A geometry representing the difference between the geometries.
827 
828  \exception std::exception It will throw an exception if the operation could not be performed.
829 
830  \warning Don't call this method for a Heterogeneous GeometryCollection, otherwise, an exception will be thrown.
831 
832  \note The caller of this method will take the ownership of the returned Geometry.
833 
834  \note Performed by GEOS.
835  */
836  virtual Geometry* difference(const Geometry* const rhs) const throw(std::exception);
837 
838  /*!
839  \brief It returns a geometric object that represents the point set symetric difference with another geometry
840 
841  \param rhs The other geometry whose symetric difference with this geometry will be calculated.
842 
843  \return A geometry representing the symetric difference with this geometry.
844 
845  \exception std::exception It will throw an exception if the operation could not be performed.
846 
847  \warning Don't call this method for a Heterogeneous GeometryCollection, otherwise, an exception will be thrown.
848 
849  \note The caller of this method will take the ownership of the returned Geometry.
850 
851  \note Performed by GEOS.
852  */
853  virtual Geometry* symDifference(const Geometry* const rhs) const throw(std::exception);
854 
855  /*!
856  \brief It returns true if the geometries are within the specified distance.
857 
858  \param rhs The other geometry whose symetric difference with this geometry will be calculated.
859  \param distance The distance.
860 
861  \return True if the geometries are within the specified distance.
862 
863  \exception std::exception It will throw an exception if the operation could not be performed.
864 
865  \note TerraLib extended method.
866 
867  \note Performed by GEOS.
868  */
869  virtual bool dWithin(const Geometry* const rhs, const double& distance) const throw(std::exception);
870 
871  //@}
872 
873  /** @name Auxiliary Methods
874  * Auxiliary Methods.
875  */
876  //@{
877 
878  /*!
879  \brief It returns the TerraLib geometry type id given a type string (the type string must be in capital letters).
880 
881  \param gtype The geometry type name.
882 
883  \return The geometry type id equivalent to the string name.
884 
885  \note If the type is unknow it returns UnknownGeometryType.
886  */
887  static GeomType getGeomTypeId(const std::string& gtype);
888 
889  /*!
890  \brief It returns the TerraLib geometry type string given a type id.
891 
892  \param gId The geometry type id.
893 
894  \return The geometry type string equivalent to the id.
895 
896  \note If the type is unknow it returns UNKNOWGEOMETRYTYPE.
897  */
898  static std::string getGeomTypeString(const int& gId);
899 
900  /*!
901  \brief It tells if the given string is a geometry data type.
902 
903  \param stype The geometry type to be checked.
904 
905  \return True if the given string corresponds to a geometry type.
906  */
907  static bool isGeomType(const std::string& stype);
908 
909  /*!
910  \brief It loads the internal MAP of geometry type names to geometry type ids.
911 
912  \warning Ths method will be automatically called when geometry module is initialized!
913  */
914  static void loadGeomTypeId();
915 
916  //@}
917 
918  /** @name AbstractData Re-implementation
919  * Methods re-implemneted from AbstractData.
920  */
921  //@{
922 
923  /*!
924  \brief It returns the data type code associated to the data value.
925 
926  \return The data type code associated to the data value.
927  */
928  int getTypeCode() const;
929 
930  /*!
931  \brief It returns the data value in a WKT representation.
932 
933  \return The data value in a WKT representation.
934  */
935  std::string toString() const { return asText(); }
936 
937  //@}
938 
939  protected:
940 
941  GeomType m_gType; //!< Internal geometry type.
942  int m_srid; //!< The Spatial Reference System code associated to the Geometry.
943  mutable Envelope* m_mbr; //!< The geometry minimum bounding rectangle.
944 
945  static std::map<std::string, GeomType> sm_geomTypeMap; //!< A set of geometry type names (in UPPER CASE).
946  };
947 
948  //Typedef
949  typedef boost::shared_ptr<Geometry> GeometryShrPtr;
950  } // end namespace gm
951 } // end namespace te
952 
953 #endif // __TERRALIB_GEOMETRY_INTERNAL_GEOMETRY_H
954 
GeomType
Each enumerated type is compatible with a Well-known Binary (WKB) type code.
Definition: Enums.h:41
BufferCapStyle
Buffer end cap style.
Definition: Enums.h:162
The root of all hierarchies that can be visited.
Definition: BaseVisitable.h:53
Base exception class for plugin module.
Definition: Exception.h:42
int m_srid
The Spatial Reference System code associated to the Geometry.
Definition: Geometry.h:942
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
An Envelope defines a 2D rectangular region.
Definition: Envelope.h:51
Dimensionality
From Wikipedia: "in mathematics, the dimension of an object is an intrinsic property, independent of the space in which the object may happen to be embedded".
Definition: Enums.h:147
URI C++ Library.
General enumerations.
A base class for values that can be retrieved from the data access module.
Definition: AbstractData.h:57
MachineByteOrder
Endianness.
Definition: Enums.h:122
GeomType getGeomTypeId() const
It returns the geometry subclass type identifier.
Definition: Geometry.h:179
#define TE_DEFINE_VISITABLE
Definition: BaseVisitable.h:75
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
Definition: Exception.h:58
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
Definition: Geometry.h:74
Envelope * m_mbr
The geometry minimum bounding rectangle.
Definition: Geometry.h:943
An exception class for the Geometry module.
GeomType m_gType
Internal geometry type.
Definition: Geometry.h:941
TEGEOMEXPORT Coord2D * locateAlong(const LineString *line, double initial, double final, double target)
Make the line interpolation to find a target.
boost::shared_ptr< Geometry > GeometryShrPtr
Definition: Geometry.h:949
An utility struct for representing 2D coordinates.
static std::map< std::string, GeomType > sm_geomTypeMap
A set of geometry type names (in UPPER CASE).
Definition: Geometry.h:945
A visitor interface for the Geometry hierarchy.