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