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