GEOS: Geometry.h Source File

GEOS 3.3.8

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

- File List

Geometry.h
1 /**********************************************************************
2 * $Id: Geometry.h 3634 2012-05-21 14:12:06Z strk $
3 *
4 * GEOS - Geometry Engine Open Source
5 * http://geos.refractions.net
6 *
7 * Copyright (C) 2009 2011 Sandro Santilli <strk@keybit.net>
8 * Copyright (C) 2005 2006 Refractions Research Inc.
9 * Copyright (C) 2001-2002 Vivid Solutions Inc.
10 *
11 * This is free software; you can redistribute and/or modify it under
12 * the terms of the GNU Lesser General Public Licence as published
13 * by the Free Software Foundation.
14 * See the COPYING file for more information.
15 *
16 **********************************************************************
17 *
18 * Last port: geom/Geometry.java rev. 1.112
19 *
20 **********************************************************************/
21
22 #ifndef GEOS_GEOM_GEOMETRY_H
23 #define GEOS_GEOM_GEOMETRY_H
24
25 #include <geos/export.h>
26 #include <geos/platform.h>
27 #include <geos/inline.h>
28 #include <geos/geom/Envelope.h>
29 #include <geos/geom/Dimension.h> // for Dimension::DimensionType
30 #include <geos/geom/GeometryComponentFilter.h> // for inheritance
31
32 #include <string>
33 #include <iostream>
34 #include <vector>
35 #include <memory>
36
37 #ifdef _MSC_VER
38 #pragma warning(push)
39 #pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
40 #pragma warning(disable: 4355) // warning C4355: 'this' : used in base member initializer list
41 #endif
42
43 // Forward declarations
44 namespace geos {
45 namespace geom {
46 class Coordinate;
47 class CoordinateFilter;
48 class CoordinateSequence;
49 class CoordinateSequenceFilter;
50 class GeometryComponentFilter;
51 class GeometryFactory;
52 class GeometryFilter;
53 class IntersectionMatrix;
54 class PrecisionModel;
55 class Point;
56 }
57 namespace io { // geos.io
58 class Unload;
59 } // namespace geos.io
60 }
61
62 namespace geos {
63 namespace geom { // geos::geom
64
66 enum GeometryTypeId {
68 GEOS_POINT,
70 GEOS_LINESTRING,
72 GEOS_LINEARRING,
74 GEOS_POLYGON,
76 GEOS_MULTIPOINT,
78 GEOS_MULTILINESTRING,
80 GEOS_MULTIPOLYGON,
82 GEOS_GEOMETRYCOLLECTION
83 };
84
168 class GEOS_DLL Geometry {
169
170 public:
171
172 friend class GeometryFactory;
173
175 typedef std::vector<const Geometry *> ConstVect;
176
178 typedef std::vector<Geometry *> NonConstVect;
179
181 typedef std::auto_ptr<Geometry> AutoPtr;
182
184 virtual Geometry* clone() const=0;
185
187 virtual ~Geometry();
188
189
197 const GeometryFactory* getFactory() const { return factory; }
198
212 void setUserData(void* newUserData) { userData=newUserData; }
213
220 void* getUserData() { return userData; }
221
222 /*
223 * \brief
224 * Returns the ID of the Spatial Reference System used by the
225 * <code>Geometry</code>.
226 *
227 * GEOS supports Spatial Reference System information in the simple way
228 * defined in the SFS. A Spatial Reference System ID (SRID) is present
229 * in each <code>Geometry</code> object. <code>Geometry</code>
230 * provides basic accessor operations for this field, but no others.
231 * The SRID is represented as an integer.
232 *
233 * @return the ID of the coordinate space in which the
234 * <code>Geometry</code> is defined.
235 *
236 */
237 virtual int getSRID() const { return SRID; }
238
239 /*
240 * Sets the ID of the Spatial Reference System used by the
241 * <code>Geometry</code>.
242 */
243 virtual void setSRID(int newSRID) { SRID=newSRID; }
244
249 const PrecisionModel* getPrecisionModel() const;
250
255 virtual const Coordinate* getCoordinate() const=0; //Abstract
256
262 virtual CoordinateSequence* getCoordinates() const=0; //Abstract
263
265 virtual std::size_t getNumPoints() const=0; //Abstract
266
268 virtual bool isSimple() const;
269
271 virtual std::string getGeometryType() const=0; //Abstract
272
274 virtual GeometryTypeId getGeometryTypeId() const=0; //Abstract
275
278 virtual std::size_t getNumGeometries() const { return 1; }
279
282 virtual const Geometry* getGeometryN(std::size_t /*n*/) const { return this; }
283
293 virtual bool isValid() const;
294
296 virtual bool isEmpty() const=0; //Abstract
297
299 virtual bool isRectangle() const { return false; }
300
302 virtual Dimension::DimensionType getDimension() const=0; //Abstract
303
305 virtual int getCoordinateDimension() const=0; //Abstract
306
323 virtual Geometry* getBoundary() const=0; //Abstract
324
326 virtual int getBoundaryDimension() const=0; //Abstract
327
329 virtual Geometry* getEnvelope() const;
330
335 virtual const Envelope* getEnvelopeInternal() const;
336
353 virtual bool disjoint(const Geometry *other) const;
354
359 virtual bool touches(const Geometry *other) const;
360
362 virtual bool intersects(const Geometry *g) const;
363
386 virtual bool crosses(const Geometry *g) const;
387
392 virtual bool within(const Geometry *g) const;
393
395 virtual bool contains(const Geometry *g) const;
396
402 virtual bool overlaps(const Geometry *g) const;
403
418 virtual bool relate(const Geometry *g,
419 const std::string& intersectionPattern) const;
420
421 bool relate(const Geometry& g, const std::string& intersectionPattern) const
422 {
423 return relate(&g, intersectionPattern);
424 }
425
427 virtual IntersectionMatrix* relate(const Geometry *g) const;
428 IntersectionMatrix* relate(const Geometry &g) const {
429 return relate(&g);
430 }
431
437 virtual bool equals(const Geometry *g) const;
438
477 bool covers(const Geometry* g) const;
478
509 bool coveredBy(const Geometry* g) const {
510 return g->covers(this);
511 }
512
513
515 virtual std::string toString() const;
516
517 virtual std::string toText() const;
518
520 //
523 virtual Geometry* buffer(double distance) const;
524
529 //
532 virtual Geometry* buffer(double distance,int quadrantSegments) const;
533
570 virtual Geometry* buffer(double distance, int quadrantSegments,
571 int endCapStyle) const;
572
576 virtual Geometry* convexHull() const;
577
587 virtual Geometry* intersection(const Geometry *other) const;
588
598 Geometry* Union(const Geometry *other) const;
599 // throw(IllegalArgumentException *, TopologyException *);
600
618 AutoPtr Union() const;
619 // throw(IllegalArgumentException *, TopologyException *);
620
631 virtual Geometry* difference(const Geometry *other) const;
632
642 virtual Geometry* symDifference(const Geometry *other) const;
643
648 virtual bool equalsExact(const Geometry *other, double tolerance=0)
649 const=0; //Abstract
650
651 virtual void apply_rw(const CoordinateFilter *filter)=0; //Abstract
652 virtual void apply_ro(CoordinateFilter *filter) const=0; //Abstract
653 virtual void apply_rw(GeometryFilter *filter);
654 virtual void apply_ro(GeometryFilter *filter) const;
655 virtual void apply_rw(GeometryComponentFilter *filter);
656 virtual void apply_ro(GeometryComponentFilter *filter) const;
657
666 virtual void apply_rw(CoordinateSequenceFilter& filter)=0;
667
674 virtual void apply_ro(CoordinateSequenceFilter& filter) const=0;
675
685 template <class T>
686 void applyComponentFilter(T& f) const
687 {
688 for(std::size_t i=0, n=getNumGeometries(); i<n; ++i)
689 f.filter(getGeometryN(i));
690 }
691
693 virtual void normalize()=0; //Abstract
694
695 virtual int compareTo(const Geometry *geom) const;
696
701 virtual double distance(const Geometry *g) const;
702
704 virtual double getArea() const;
705
707 virtual double getLength() const;
708
720 virtual bool isWithinDistance(const Geometry *geom,
721 double cDistance) const;
722
732 virtual Point* getCentroid() const;
733
735 //
738 virtual bool getCentroid(Coordinate& ret) const;
739
750 virtual Point* getInteriorPoint() const;
751
752 /*
753 * \brief
754 * Notifies this Geometry that its Coordinates have been changed
755 * by an external party (using a CoordinateFilter, for example).
756 */
757 virtual void geometryChanged();
758
764 void geometryChangedAction();
765
766 protected:
767
769 mutable std::auto_ptr<Envelope> envelope;
770
772 static bool hasNonEmptyElements(const std::vector<Geometry *>* geometries);
773
775 static bool hasNullElements(const CoordinateSequence* list);
776
778 static bool hasNullElements(const std::vector<Geometry *>* lrs);
779
780 // static void reversePointOrder(CoordinateSequence* coordinates);
781 // static Coordinate& minCoordinate(CoordinateSequence* coordinates);
782 // static void scroll(CoordinateSequence* coordinates,Coordinate* firstCoordinate);
783 // static int indexOf(Coordinate* coordinate,CoordinateSequence* coordinates);
784 //
789 virtual bool isEquivalentClass(const Geometry *other) const;
790
791 static void checkNotGeometryCollection(const Geometry *g);
792 // throw(IllegalArgumentException *);
793
794 //virtual void checkEqualSRID(Geometry *other);
795
796 //virtual void checkEqualPrecisionModel(Geometry *other);
797
798 virtual Envelope::AutoPtr computeEnvelopeInternal() const=0; //Abstract
799
800 virtual int compareToSameClass(const Geometry *geom) const=0; //Abstract
801
802 int compare(std::vector<Coordinate> a, std::vector<Coordinate> b) const;
803
804 int compare(std::vector<Geometry *> a, std::vector<Geometry *> b) const;
805
806 bool equal(const Coordinate& a, const Coordinate& b,
807 double tolerance) const;
808 int SRID;
809
811 //Geometry* toInternalGeometry(const Geometry *g) const;
812
814 //Geometry* fromInternalGeometry(const Geometry *g) const;
815
817 //virtual bool isRectangle() const { return false; } -- moved to public
818
819 Geometry(const Geometry &geom);
820
830 Geometry(const GeometryFactory *factory);
831
832 private:
833
834 int getClassSortIndex() const;
835
836 class GeometryChangedFilter : public GeometryComponentFilter
837 {
838 public:
839 void filter_rw(Geometry* geom)
840 {
841 geom->geometryChangedAction();
842 }
843 };
844
845 static GeometryChangedFilter geometryChangedFilter;
846
848 //
851 const GeometryFactory *factory;
852
853 void* userData;
854 };
855
860 GEOS_DLL std::ostream& operator<< (std::ostream& os, const Geometry& geom);
861
862 struct GEOS_DLL GeometryGreaterThen {
863 bool operator()(const Geometry *first, const Geometry *second);
864 };
865
866
868 std::string geosversion();
869
875 std::string jtsport();
876
877 // We use this instead of std::pair<auto_ptr<Geometry>> because C++11
878 // forbids that construct:
879 // http://lwg.github.com/issues/lwg-closed.html#2068
880 struct GeomPtrPair {
881 typedef std::auto_ptr<Geometry> GeomPtr;
882 GeomPtr first;
883 GeomPtr second;
884 };
885
886 } // namespace geos::geom
887 } // namespace geos
888
889 #ifdef _MSC_VER
890 #pragma warning(pop)
891 #endif
892
893 #endif // ndef GEOS_GEOM_GEOMETRY_H
894
895 /**********************************************************************
896 * $Log$
897 * Revision 1.14 2006/07/08 00:33:55 strk
898 * * configure.in: incremented CAPI minor version, to avoid falling behind any future version from the 2.2. branch.
899 * * source/geom/Geometry.cpp, source/geom/GeometryFactory.cpp,
900 * source/geomgraph/EdgeRing.cpp,
901 * source/headers/geos/geom/Geometry.h,
902 * source/headers/geos/geom/GeometryFactory.h,
903 * source/headers/geos/geom/GeometryFactory.inl,
904 * source/headers/geos/geomgraph/EdgeRing.h:
905 * updated doxygen comments (sync with JTS head).
906 * * source/headers/geos/platform.h.in: include <inttypes.h>
907 * rather then <stdint.h>
908 *
909 * Revision 1.13 2006/06/12 10:10:39 strk
910 * Fixed getGeometryN() to take size_t rather then int, changed unsigned int parameters to size_t.
911 *
912 * Revision 1.12 2006/05/18 08:56:50 strk
913 * * source/geom/Geometry.cpp,
914 * source/headers/geos/geom/Geometry.h: added
915 * covers() and isCoveredBy() predicates.
916 * * tests/unit/Makefile.am,
917 * tests/unit/geom/Geometry/coversTest.cpp:
918 * added test for covers() predicates.
919 *
920 * Revision 1.11 2006/05/04 15:49:39 strk
921 * updated all Geometry::getDimension() methods to return Dimension::DimensionType (closes bug#93)
922 *
923 * Revision 1.10 2006/04/28 10:55:39 strk
924 * Geometry constructors made protected, to ensure all constructions use GeometryFactory,
925 * which has been made friend of all Geometry derivates. getNumPoints() changed to return
926 * size_t.
927 *
928 * Revision 1.9 2006/04/11 09:31:47 strk
929 * Added Geometry::AutoPtr typedef
930 *
931 * Revision 1.8 2006/04/10 18:15:09 strk
932 * Changed Geometry::envelope member to be of type auto_ptr<Envelope>.
933 * Changed computeEnvelopeInternal() signater to return auto_ptr<Envelope>
934 *
935 * Revision 1.7 2006/04/07 09:54:30 strk
936 * Geometry::getNumGeometries() changed to return 'unsigned int'
937 * rather then 'int'
938 *
939 * Revision 1.6 2006/03/31 16:53:53 strk
940 * Added comment about possible NULL return from getCoordinate()
941 *
942 * Revision 1.5 2006/03/24 09:52:41 strk
943 * USE_INLINE => GEOS_INLINE
944 *
945 * Revision 1.4 2006/03/23 15:10:29 strk
946 * Dropped by-pointer TopologyException constructor, various small cleanups
947 *
948 * Revision 1.3 2006/03/23 12:12:01 strk
949 * Fixes to allow build with -DGEOS_INLINE
950 *
951 * Revision 1.2 2006/03/20 12:03:25 strk
952 * Added operator<< for Geometry, writing HEXWKB
953 *
954 * Revision 1.1 2006/03/09 16:46:49 strk
955 * geos::geom namespace definition, first pass at headers split
956 *
957 **********************************************************************/