GEOS  3.7.2
Geometry.h
1 /**********************************************************************
2  *
3  * GEOS - Geometry Engine Open Source
4  * http://geos.osgeo.org
5  *
6  * Copyright (C) 2009 2011 Sandro Santilli <strk@kbt.io>
7  * Copyright (C) 2005 2006 Refractions Research Inc.
8  * Copyright (C) 2001-2002 Vivid Solutions Inc.
9  *
10  * This is free software; you can redistribute and/or modify it under
11  * the terms of the GNU Lesser General Public Licence as published
12  * by the Free Software Foundation.
13  * See the COPYING file for more information.
14  *
15  **********************************************************************
16  *
17  * Last port: geom/Geometry.java rev. 1.112
18  *
19  **********************************************************************/
20 
21 #ifndef GEOS_GEOM_GEOMETRY_H
22 #define GEOS_GEOM_GEOMETRY_H
23 
24 #ifndef USE_UNSTABLE_GEOS_CPP_API
25 #ifndef _MSC_VER
26 # warning "The GEOS C++ API is unstable, please use the C API instead"
27 # warning "HINT: #include geos_c.h"
28 #else
29 #pragma message("The GEOS C++ API is unstable, please use the C API instead")
30 #pragma message("HINT: #include geos_c.h")
31 #endif
32 #endif
33 
34 #include <geos/export.h>
35 #include <geos/platform.h>
36 #include <geos/inline.h>
37 #include <geos/geom/Envelope.h>
38 #include <geos/geom/Dimension.h> // for Dimension::DimensionType
39 #include <geos/geom/GeometryComponentFilter.h> // for inheritance
40 
41 #include <string>
42 #include <iostream>
43 #include <vector>
44 #include <memory>
45 
46 #ifdef _MSC_VER
47 #pragma warning(push)
48 #pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
49 #pragma warning(disable: 4355) // warning C4355: 'this' : used in base member initializer list
50 #endif
51 
52 // Forward declarations
53 namespace geos {
54  namespace geom {
55  class Coordinate;
56  class CoordinateFilter;
57  class CoordinateSequence;
58  class CoordinateSequenceFilter;
59  class GeometryComponentFilter;
60  class GeometryFactory;
61  class GeometryFilter;
62  class IntersectionMatrix;
63  class PrecisionModel;
64  class Point;
65  }
66  namespace io { // geos.io
67  class Unload;
68  } // namespace geos.io
69 }
70 
71 namespace geos {
72 namespace geom { // geos::geom
73 
92 };
93 
177 class GEOS_DLL Geometry {
178 
179 public:
180 
181  friend class GeometryFactory;
182 
184  using ConstVect = std::vector<const Geometry *>;
185 
187  using NonConstVect = std::vector<Geometry *>;
188 
190  using Ptr = std::unique_ptr<Geometry> ;
191 
193  virtual Geometry* clone() const=0;
194 
196  virtual ~Geometry();
197 
198 
206  const GeometryFactory* getFactory() const { return _factory; }
207 
221  void setUserData(void* newUserData) { _userData=newUserData; }
222 
229  void* getUserData() const { return _userData; }
230 
231  /*
232  * \brief
233  * Returns the ID of the Spatial Reference System used by the
234  * <code>Geometry</code>.
235  *
236  * GEOS supports Spatial Reference System information in the simple way
237  * defined in the SFS. A Spatial Reference System ID (SRID) is present
238  * in each <code>Geometry</code> object. <code>Geometry</code>
239  * provides basic accessor operations for this field, but no others.
240  * The SRID is represented as an integer.
241  *
242  * @return the ID of the coordinate space in which the
243  * <code>Geometry</code> is defined.
244  *
245  */
246  virtual int getSRID() const { return SRID; }
247 
248  /*
249  * Sets the ID of the Spatial Reference System used by the
250  * <code>Geometry</code>.
251  */
252  virtual void setSRID(int newSRID) { SRID=newSRID; }
253 
258  const PrecisionModel* getPrecisionModel() const;
259 
264  virtual const Coordinate* getCoordinate() const=0; //Abstract
265 
271  virtual CoordinateSequence* getCoordinates() const=0; //Abstract
272 
274  virtual std::size_t getNumPoints() const=0; //Abstract
275 
277  virtual bool isSimple() const;
278 
280  virtual std::string getGeometryType() const=0; //Abstract
281 
283  virtual GeometryTypeId getGeometryTypeId() const=0; //Abstract
284 
287  virtual std::size_t getNumGeometries() const { return 1; }
288 
291  virtual const Geometry* getGeometryN(std::size_t /*n*/) const { return this; }
292 
302  virtual bool isValid() const;
303 
305  virtual bool isEmpty() const=0; //Abstract
306 
308  virtual bool isRectangle() const { return false; }
309 
311  virtual Dimension::DimensionType getDimension() const=0; //Abstract
312 
314  virtual int getCoordinateDimension() const=0; //Abstract
315 
332  virtual Geometry* getBoundary() const=0; //Abstract
333 
335  virtual int getBoundaryDimension() const=0; //Abstract
336 
338  virtual Geometry* getEnvelope() const;
339 
344  virtual const Envelope* getEnvelopeInternal() const;
345 
362  virtual bool disjoint(const Geometry *other) const;
363 
368  virtual bool touches(const Geometry *other) const;
369 
371  virtual bool intersects(const Geometry *g) const;
372 
395  virtual bool crosses(const Geometry *g) const;
396 
401  virtual bool within(const Geometry *g) const;
402 
404  virtual bool contains(const Geometry *g) const;
405 
411  virtual bool overlaps(const Geometry *g) const;
412 
427  virtual bool relate(const Geometry *g,
428  const std::string& intersectionPattern) const;
429 
430  bool relate(const Geometry& g, const std::string& intersectionPattern) const
431  {
432  return relate(&g, intersectionPattern);
433  }
434 
436  virtual IntersectionMatrix* relate(const Geometry *g) const;
437  IntersectionMatrix* relate(const Geometry &g) const {
438  return relate(&g);
439  }
440 
446  virtual bool equals(const Geometry *g) const;
447 
486  bool covers(const Geometry* g) const;
487 
518  bool coveredBy(const Geometry* g) const {
519  return g->covers(this);
520  }
521 
522 
524  virtual std::string toString() const;
525 
526  virtual std::string toText() const;
527 
529  //
532  virtual Geometry* buffer(double distance) const;
533 
538  //
541  virtual Geometry* buffer(double distance,int quadrantSegments) const;
542 
579  virtual Geometry* buffer(double distance, int quadrantSegments,
580  int endCapStyle) const;
581 
585  virtual Geometry* convexHull() const;
586 
593  virtual Geometry* reverse() const=0;
594 
604  virtual Geometry* intersection(const Geometry *other) const;
605 
615  Geometry* Union(const Geometry *other) const;
616  // throw(IllegalArgumentException *, TopologyException *);
617 
635  Ptr Union() const;
636  // throw(IllegalArgumentException *, TopologyException *);
637 
648  virtual Geometry* difference(const Geometry *other) const;
649 
659  virtual Geometry* symDifference(const Geometry *other) const;
660 
665  virtual bool equalsExact(const Geometry *other, double tolerance=0)
666  const=0; //Abstract
667 
668  virtual void apply_rw(const CoordinateFilter *filter)=0; //Abstract
669  virtual void apply_ro(CoordinateFilter *filter) const=0; //Abstract
670  virtual void apply_rw(GeometryFilter *filter);
671  virtual void apply_ro(GeometryFilter *filter) const;
672  virtual void apply_rw(GeometryComponentFilter *filter);
673  virtual void apply_ro(GeometryComponentFilter *filter) const;
674 
683  virtual void apply_rw(CoordinateSequenceFilter& filter)=0;
684 
691  virtual void apply_ro(CoordinateSequenceFilter& filter) const=0;
692 
702  template <class T>
703  void applyComponentFilter(T& f) const
704  {
705  for(std::size_t i=0, n=getNumGeometries(); i<n; ++i)
706  f.filter(getGeometryN(i));
707  }
708 
710  virtual void normalize()=0; //Abstract
711 
712  virtual int compareTo(const Geometry *geom) const;
713 
718  virtual double distance(const Geometry *g) const;
719 
721  virtual double getArea() const;
722 
724  virtual double getLength() const;
725 
737  virtual bool isWithinDistance(const Geometry *geom,
738  double cDistance) const;
739 
749  virtual Point* getCentroid() const;
750 
752  //
755  virtual bool getCentroid(Coordinate& ret) const;
756 
767  virtual Point* getInteriorPoint() const;
768 
769  /*
770  * \brief
771  * Notifies this Geometry that its Coordinates have been changed
772  * by an external party (using a CoordinateFilter, for example).
773  */
774  virtual void geometryChanged();
775 
781  void geometryChangedAction();
782 
783 protected:
784 
786  mutable std::unique_ptr<Envelope> envelope;
787 
789  static bool hasNonEmptyElements(const std::vector<Geometry *>* geometries);
790 
792  static bool hasNullElements(const CoordinateSequence* list);
793 
795  static bool hasNullElements(const std::vector<Geometry *>* lrs);
796 
797 // static void reversePointOrder(CoordinateSequence* coordinates);
798 // static Coordinate& minCoordinate(CoordinateSequence* coordinates);
799 // static void scroll(CoordinateSequence* coordinates,Coordinate* firstCoordinate);
800 // static int indexOf(Coordinate* coordinate,CoordinateSequence* coordinates);
801 //
806  virtual bool isEquivalentClass(const Geometry *other) const;
807 
808  static void checkNotGeometryCollection(const Geometry *g);
809  // throw(IllegalArgumentException *);
810 
811  //virtual void checkEqualSRID(Geometry *other);
812 
813  //virtual void checkEqualPrecisionModel(Geometry *other);
814 
815  virtual Envelope::Ptr computeEnvelopeInternal() const=0; //Abstract
816 
817  virtual int compareToSameClass(const Geometry *geom) const=0; //Abstract
818 
819  int compare(std::vector<Coordinate> a, std::vector<Coordinate> b) const;
820 
821  int compare(std::vector<Geometry *> a, std::vector<Geometry *> b) const;
822 
823  bool equal(const Coordinate& a, const Coordinate& b,
824  double tolerance) const;
825  int SRID;
826 
828  //Geometry* toInternalGeometry(const Geometry *g) const;
829 
831  //Geometry* fromInternalGeometry(const Geometry *g) const;
832 
834  //virtual bool isRectangle() const { return false; } -- moved to public
835 
836  Geometry(const Geometry &geom);
837 
847  Geometry(const GeometryFactory *factory);
848 
849 private:
850 
851  int getClassSortIndex() const;
852 
853  class GEOS_DLL GeometryChangedFilter : public GeometryComponentFilter
854  {
855  public:
856  void filter_rw(Geometry* geom) override;
857  };
858 
859  static GeometryChangedFilter geometryChangedFilter;
860 
862  //
865  const GeometryFactory* _factory;
866 
867  void* _userData;
868 };
869 
874 GEOS_DLL std::ostream& operator<< (std::ostream& os, const Geometry& geom);
875 
876 struct GEOS_DLL GeometryGreaterThen {
877  bool operator()(const Geometry *first, const Geometry *second);
878 };
879 
880 
882 std::string geosversion();
883 
889 std::string jtsport();
890 
891 // We use this instead of std::pair<unique_ptr<Geometry>> because C++11
892 // forbids that construct:
893 // http://lwg.github.com/issues/lwg-closed.html#2068
894 struct GeomPtrPair {
895  typedef std::unique_ptr<Geometry> GeomPtr;
896  GeomPtr first;
897  GeomPtr second;
898 };
899 
900 } // namespace geos::geom
901 } // namespace geos
902 
903 #ifdef _MSC_VER
904 #pragma warning(pop)
905 #endif
906 
907 #endif // ndef GEOS_GEOM_GEOMETRY_H
geos::geom::Geometry::ConstVect
std::vector< const Geometry * > ConstVect
A vector of const Geometry pointers.
Definition: Geometry.h:184
geos::geom::Geometry::envelope
std::unique_ptr< Envelope > envelope
The bounding box of this Geometry.
Definition: Geometry.h:786
geos
Basic namespace for all GEOS functionalities.
Definition: IndexedNestedRingTester.h:25
geos::geom::GeometryComponentFilter
Definition: GeometryComponentFilter.h:43
geos::geom::GEOS_POLYGON
@ GEOS_POLYGON
a polygon
Definition: Geometry.h:83
geos::geom::GEOS_LINESTRING
@ GEOS_LINESTRING
a linestring
Definition: Geometry.h:79
geos::geom::Geometry::Ptr
std::unique_ptr< Geometry > Ptr
An unique_ptr of Geometry.
Definition: Geometry.h:190
geos::geom::Geometry::getNumGeometries
virtual std::size_t getNumGeometries() const
Definition: Geometry.h:287
geos::geom::Geometry::getGeometryN
virtual const Geometry * getGeometryN(std::size_t) const
Definition: Geometry.h:291
geos::geom::GEOS_MULTIPOLYGON
@ GEOS_MULTIPOLYGON
a collection of polygons
Definition: Geometry.h:89
geos::geom::GEOS_LINEARRING
@ GEOS_LINEARRING
a linear ring (linestring with 1st point == last point)
Definition: Geometry.h:81
geos::geom::Geometry::isRectangle
virtual bool isRectangle() const
Polygon overrides to check for actual rectangle.
Definition: Geometry.h:308
geos::geom::Dimension::DimensionType
DimensionType
Definition: Dimension.h:67
geos::geom::GEOS_POINT
@ GEOS_POINT
a point
Definition: Geometry.h:77
geos::geom::Coordinate
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:84
geos::geom::Geometry
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition: Geometry.h:177
geos::geom::Geometry::applyComponentFilter
void applyComponentFilter(T &f) const
Apply a fiter to each component of this geometry. The filter is expected to provide a ....
Definition: Geometry.h:703
geos::geom::Geometry::coveredBy
bool coveredBy(const Geometry *g) const
Tests whether this geometry is covered by the specified geometry.
Definition: Geometry.h:518
geos::geom::GEOS_GEOMETRYCOLLECTION
@ GEOS_GEOMETRYCOLLECTION
a collection of heterogeneus geometries
Definition: Geometry.h:91
geos::geom::CoordinateSequence
The internal representation of a list of coordinates inside a Geometry.
Definition: CoordinateSequence.h:59
geos::geom::CoordinateSequenceFilter
Definition: CoordinateSequenceFilter.h:58
geos::geom::GEOS_MULTILINESTRING
@ GEOS_MULTILINESTRING
a collection of linestrings
Definition: Geometry.h:87
geos::geom::Geometry::NonConstVect
std::vector< Geometry * > NonConstVect
A vector of non-const Geometry pointers.
Definition: Geometry.h:187
geos::geom::Geometry::getFactory
const GeometryFactory * getFactory() const
Gets the factory which contains the context in which this geometry was created.
Definition: Geometry.h:206
geos::geom::operator<<
GEOS_DLL std::ostream & operator<<(std::ostream &os, const Coordinate &c)
Output function.
geos::geom::Envelope
An Envelope defines a rectangulare region of the 2D coordinate plane.
Definition: Envelope.h:91
geos::geom::GeometryTypeId
GeometryTypeId
Geometry types.
Definition: Geometry.h:75
geos::geom::CoordinateFilter
Definition: CoordinateFilter.h:67
geos::geom::GeometryFactory
Supplies a set of utility methods for building Geometry objects from CoordinateSequence or other Geom...
Definition: GeometryFactory.h:67
geos::geom::Geometry::getUserData
void * getUserData() const
Gets the user data object for this geometry, if any.
Definition: Geometry.h:229
geos::geom::Geometry::setUserData
void setUserData(void *newUserData)
A simple scheme for applications to add their own custom data to a Geometry. An example use might be ...
Definition: Geometry.h:221
geos::geom::GeometryFilter
Geometry classes support the concept of applying a Geometry filter to the Geometry.
Definition: GeometryFilter.h:48
geos::geom::Geometry::covers
bool covers(const Geometry *g) const
Returns true if this geometry covers the specified geometry.
geos::geom::GEOS_MULTIPOINT
@ GEOS_MULTIPOINT
a collection of points
Definition: Geometry.h:85
geos::geom::geosversion
std::string geosversion()
Return current GEOS version.
geos::geom::Point
Definition: Point.h:67
geos::geom::jtsport
std::string jtsport()
Return the version of JTS this GEOS release has been ported from.