GEOS: Geometry.h Source File

GEOS 3.5.0

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List

Geometry.h
1 /**********************************************************************
2 *
3 * GEOS - Geometry Engine Open Source
4 * http://geos.osgeo.org
5 *
6 * Copyright (C) 2009 2011 Sandro Santilli <strk@keybit.net>
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 #include <geos/export.h>
25 #include <geos/platform.h>
26 #include <geos/inline.h>
27 #include <geos/geom/Envelope.h>
28 #include <geos/geom/Dimension.h> // for Dimension::DimensionType
29 #include <geos/geom/GeometryComponentFilter.h> // for inheritance
30
31 #include <string>
32 #include <iostream>
33 #include <vector>
34 #include <memory>
35
36 #ifdef _MSC_VER
37 #pragma warning(push)
38 #pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
39 #pragma warning(disable: 4355) // warning C4355: 'this' : used in base member initializer list
40 #endif
41
42 // Forward declarations
43 namespace geos {
44 namespace geom {
45 class Coordinate;
46 class CoordinateFilter;
47 class CoordinateSequence;
48 class CoordinateSequenceFilter;
49 class GeometryComponentFilter;
50 class GeometryFactory;
51 class GeometryFilter;
52 class IntersectionMatrix;
53 class PrecisionModel;
54 class Point;
55 }
56 namespace io { // geos.io
57 class Unload;
58 } // namespace geos.io
59 }
60
61 namespace geos {
62 namespace geom { // geos::geom
63
65 enum GeometryTypeId {
67 GEOS_POINT,
69 GEOS_LINESTRING,
71 GEOS_LINEARRING,
73 GEOS_POLYGON,
75 GEOS_MULTIPOINT,
77 GEOS_MULTILINESTRING,
79 GEOS_MULTIPOLYGON,
81 GEOS_GEOMETRYCOLLECTION
82 };
83
167 class GEOS_DLL Geometry {
168
169 public:
170
171 friend class GeometryFactory;
172
174 typedef std::vector<const Geometry *> ConstVect;
175
177 typedef std::vector<Geometry *> NonConstVect;
178
180 typedef std::auto_ptr<Geometry> AutoPtr;
181
183 virtual Geometry* clone() const=0;
184
186 virtual ~Geometry();
187
188
196 const GeometryFactory* getFactory() const { return factory; }
197
211 void setUserData(void* newUserData) { userData=newUserData; }
212
219 void* getUserData() { return userData; }
220
221 /*
222 * \brief
223 * Returns the ID of the Spatial Reference System used by the
224 * <code>Geometry</code>.
225 *
226 * GEOS supports Spatial Reference System information in the simple way
227 * defined in the SFS. A Spatial Reference System ID (SRID) is present
228 * in each <code>Geometry</code> object. <code>Geometry</code>
229 * provides basic accessor operations for this field, but no others.
230 * The SRID is represented as an integer.
231 *
232 * @return the ID of the coordinate space in which the
233 * <code>Geometry</code> is defined.
234 *
235 */
236 virtual int getSRID() const { return SRID; }
237
238 /*
239 * Sets the ID of the Spatial Reference System used by the
240 * <code>Geometry</code>.
241 */
242 virtual void setSRID(int newSRID) { SRID=newSRID; }
243
248 const PrecisionModel* getPrecisionModel() const;
249
254 virtual const Coordinate* getCoordinate() const=0; //Abstract
255
261 virtual CoordinateSequence* getCoordinates() const=0; //Abstract
262
264 virtual std::size_t getNumPoints() const=0; //Abstract
265
267 virtual bool isSimple() const;
268
270 virtual std::string getGeometryType() const=0; //Abstract
271
273 virtual GeometryTypeId getGeometryTypeId() const=0; //Abstract
274
277 virtual std::size_t getNumGeometries() const { return 1; }
278
281 virtual const Geometry* getGeometryN(std::size_t /*n*/) const { return this; }
282
292 virtual bool isValid() const;
293
295 virtual bool isEmpty() const=0; //Abstract
296
298 virtual bool isRectangle() const { return false; }
299
301 virtual Dimension::DimensionType getDimension() const=0; //Abstract
302
304 virtual int getCoordinateDimension() const=0; //Abstract
305
322 virtual Geometry* getBoundary() const=0; //Abstract
323
325 virtual int getBoundaryDimension() const=0; //Abstract
326
328 virtual Geometry* getEnvelope() const;
329
334 virtual const Envelope* getEnvelopeInternal() const;
335
352 virtual bool disjoint(const Geometry *other) const;
353
358 virtual bool touches(const Geometry *other) const;
359
361 virtual bool intersects(const Geometry *g) const;
362
385 virtual bool crosses(const Geometry *g) const;
386
391 virtual bool within(const Geometry *g) const;
392
394 virtual bool contains(const Geometry *g) const;
395
401 virtual bool overlaps(const Geometry *g) const;
402
417 virtual bool relate(const Geometry *g,
418 const std::string& intersectionPattern) const;
419
420 bool relate(const Geometry& g, const std::string& intersectionPattern) const
421 {
422 return relate(&g, intersectionPattern);
423 }
424
426 virtual IntersectionMatrix* relate(const Geometry *g) const;
427 IntersectionMatrix* relate(const Geometry &g) const {
428 return relate(&g);
429 }
430
436 virtual bool equals(const Geometry *g) const;
437
476 bool covers(const Geometry* g) const;
477
508 bool coveredBy(const Geometry* g) const {
509 return g->covers(this);
510 }
511
512
514 virtual std::string toString() const;
515
516 virtual std::string toText() const;
517
519 //
522 virtual Geometry* buffer(double distance) const;
523
528 //
531 virtual Geometry* buffer(double distance,int quadrantSegments) const;
532
569 virtual Geometry* buffer(double distance, int quadrantSegments,
570 int endCapStyle) const;
571
575 virtual Geometry* convexHull() const;
576
586 virtual Geometry* intersection(const Geometry *other) const;
587
597 Geometry* Union(const Geometry *other) const;
598 // throw(IllegalArgumentException *, TopologyException *);
599
617 AutoPtr Union() const;
618 // throw(IllegalArgumentException *, TopologyException *);
619
630 virtual Geometry* difference(const Geometry *other) const;
631
641 virtual Geometry* symDifference(const Geometry *other) const;
642
647 virtual bool equalsExact(const Geometry *other, double tolerance=0)
648 const=0; //Abstract
649
650 virtual void apply_rw(const CoordinateFilter *filter)=0; //Abstract
651 virtual void apply_ro(CoordinateFilter *filter) const=0; //Abstract
652 virtual void apply_rw(GeometryFilter *filter);
653 virtual void apply_ro(GeometryFilter *filter) const;
654 virtual void apply_rw(GeometryComponentFilter *filter);
655 virtual void apply_ro(GeometryComponentFilter *filter) const;
656
665 virtual void apply_rw(CoordinateSequenceFilter& filter)=0;
666
673 virtual void apply_ro(CoordinateSequenceFilter& filter) const=0;
674
684 template <class T>
685 void applyComponentFilter(T& f) const
686 {
687 for(std::size_t i=0, n=getNumGeometries(); i<n; ++i)
688 f.filter(getGeometryN(i));
689 }
690
692 virtual void normalize()=0; //Abstract
693
694 virtual int compareTo(const Geometry *geom) const;
695
700 virtual double distance(const Geometry *g) const;
701
703 virtual double getArea() const;
704
706 virtual double getLength() const;
707
719 virtual bool isWithinDistance(const Geometry *geom,
720 double cDistance) const;
721
731 virtual Point* getCentroid() const;
732
734 //
737 virtual bool getCentroid(Coordinate& ret) const;
738
749 virtual Point* getInteriorPoint() const;
750
751 /*
752 * \brief
753 * Notifies this Geometry that its Coordinates have been changed
754 * by an external party (using a CoordinateFilter, for example).
755 */
756 virtual void geometryChanged();
757
763 void geometryChangedAction();
764
765 protected:
766
768 mutable std::auto_ptr<Envelope> envelope;
769
771 static bool hasNonEmptyElements(const std::vector<Geometry *>* geometries);
772
774 static bool hasNullElements(const CoordinateSequence* list);
775
777 static bool hasNullElements(const std::vector<Geometry *>* lrs);
778
779 // static void reversePointOrder(CoordinateSequence* coordinates);
780 // static Coordinate& minCoordinate(CoordinateSequence* coordinates);
781 // static void scroll(CoordinateSequence* coordinates,Coordinate* firstCoordinate);
782 // static int indexOf(Coordinate* coordinate,CoordinateSequence* coordinates);
783 //
788 virtual bool isEquivalentClass(const Geometry *other) const;
789
790 static void checkNotGeometryCollection(const Geometry *g);
791 // throw(IllegalArgumentException *);
792
793 //virtual void checkEqualSRID(Geometry *other);
794
795 //virtual void checkEqualPrecisionModel(Geometry *other);
796
797 virtual Envelope::AutoPtr computeEnvelopeInternal() const=0; //Abstract
798
799 virtual int compareToSameClass(const Geometry *geom) const=0; //Abstract
800
801 int compare(std::vector<Coordinate> a, std::vector<Coordinate> b) const;
802
803 int compare(std::vector<Geometry *> a, std::vector<Geometry *> b) const;
804
805 bool equal(const Coordinate& a, const Coordinate& b,
806 double tolerance) const;
807 int SRID;
808
810 //Geometry* toInternalGeometry(const Geometry *g) const;
811
813 //Geometry* fromInternalGeometry(const Geometry *g) const;
814
816 //virtual bool isRectangle() const { return false; } -- moved to public
817
818 Geometry(const Geometry &geom);
819
829 Geometry(const GeometryFactory *factory);
830
831 private:
832
833 int getClassSortIndex() const;
834
835 class GEOS_DLL GeometryChangedFilter : public GeometryComponentFilter
836 {
837 public:
838 void filter_rw(Geometry* geom);
839 };
840
841 static GeometryChangedFilter geometryChangedFilter;
842
844 //
847 const GeometryFactory *factory;
848
849 void* userData;
850 };
851
856 GEOS_DLL std::ostream& operator<< (std::ostream& os, const Geometry& geom);
857
858 struct GEOS_DLL GeometryGreaterThen {
859 bool operator()(const Geometry *first, const Geometry *second);
860 };
861
862
864 std::string geosversion();
865
871 std::string jtsport();
872
873 // We use this instead of std::pair<auto_ptr<Geometry>> because C++11
874 // forbids that construct:
875 // http://lwg.github.com/issues/lwg-closed.html#2068
876 struct GeomPtrPair {
877 typedef std::auto_ptr<Geometry> GeomPtr;
878 GeomPtr first;
879 GeomPtr second;
880 };
881
882 } // namespace geos::geom
883 } // namespace geos
884
885 #ifdef _MSC_VER
886 #pragma warning(pop)
887 #endif
888
889 #endif // ndef GEOS_GEOM_GEOMETRY_H
geos::geom::GeometryFilter
Geometry classes support the concept of applying a Geometry filter to the Geometry.
Definition: GeometryFilter.h:48
geos::geom::Envelope
An Envelope defines a rectangulare region of the 2D coordinate plane.
Definition: Envelope.h:53
geos::geom::GEOS_LINESTRING
a linestring
Definition: Geometry.h:69
geos::geom::GEOS_GEOMETRYCOLLECTION
a collection of heterogeneus geometries
Definition: Geometry.h:81
geos::geom::GEOS_MULTILINESTRING
a collection of linestrings
Definition: Geometry.h:77
geos::geom::Coordinate
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:60
geos::geom::Geometry::getGeometryN
virtual const Geometry * getGeometryN(std::size_t) const
Definition: Geometry.h:281
geos::geom::Geometry::getUserData
void * getUserData()
Gets the user data object for this geometry, if any.
Definition: Geometry.h:219
geos::geom::operator<<
GEOS_DLL std::ostream & operator<<(std::ostream &os, const Coordinate &c)
Output function.
geos::geom::IntersectionMatrix
Implementation of Dimensionally Extended Nine-Intersection Model (DE-9IM) matrix. ...
Definition: IntersectionMatrix.h:51
geos::geom::Geometry::isRectangle
virtual bool isRectangle() const
Polygon overrides to check for actual rectangle.
Definition: Geometry.h:298
geos::geom::CoordinateSequenceFilter
Definition: CoordinateSequenceFilter.h:58
geos::geom::PrecisionModel
Specifies the precision model of the Coordinate in a Geometry.
Definition: PrecisionModel.h:87
geos::geom::Geometry::getNumGeometries
virtual std::size_t getNumGeometries() const
Definition: Geometry.h:277
geos::geom::geosversion
std::string geosversion()
Return current GEOS version.
geos::geom::GeometryTypeId
GeometryTypeId
Geometry types.
Definition: Geometry.h:65
geos::geom::Geometry::covers
bool covers(const Geometry *g) const
Returns true if this geometry covers the specified geometry.
geos::geom::Geometry
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition: Geometry.h:167
geos::geom::CoordinateFilter
Definition: CoordinateFilter.h:43
geos::geom::GEOS_MULTIPOINT
a collection of points
Definition: Geometry.h:75
geos::geom::Geometry::envelope
std::auto_ptr< Envelope > envelope
The bounding box of this Geometry.
Definition: Geometry.h:768
geos::geom::jtsport
std::string jtsport()
Return the version of JTS this GEOS release has been ported from.
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:211
geos::geom::Geometry::AutoPtr
std::auto_ptr< Geometry > AutoPtr
An auto_ptr of Geometry.
Definition: Geometry.h:180
geos::geom::Geometry::getFactory
const GeometryFactory * getFactory() const
Gets the factory which contains the context in which this geometry was created.
Definition: Geometry.h:196
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::NonConstVect
std::vector< Geometry * > NonConstVect
A vector of non-const Geometry pointers.
Definition: Geometry.h:177
geos
Basic namespace for all GEOS functionalities.
Definition: IndexedNestedRingTester.h:25
geos::geom::GEOS_POLYGON
a polygon
Definition: Geometry.h:73
geos::geom::GEOS_LINEARRING
a linear ring (linestring with 1st point == last point)
Definition: Geometry.h:71
geos::geom::GEOS_POINT
a point
Definition: Geometry.h:67
geos::geom::CoordinateSequence
The internal representation of a list of coordinates inside a Geometry.
Definition: CoordinateSequence.h:59
geos::geom::Point
Definition: Point.h:67
geos::geom::GEOS_MULTIPOLYGON
a collection of polygons
Definition: Geometry.h:79
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:685
geos::geom::Geometry::ConstVect
std::vector< const Geometry * > ConstVect
A vector of const Geometry pointers.
Definition: Geometry.h:174
geos::geom::Dimension::DimensionType
DimensionType
Definition: Dimension.h:31
geos::geom::Geometry::coveredBy
bool coveredBy(const Geometry *g) const
Tests whether this geometry is covered by the specified geometry.
Definition: Geometry.h:508
geos::geom::GeometryComponentFilter
Definition: GeometryComponentFilter.h:43