GEOS
3.3.2
|
00001 /********************************************************************** 00002 * $Id: Geometry.h 3538 2011-12-09 10:44:54Z strk $ 00003 * 00004 * GEOS - Geometry Engine Open Source 00005 * http://geos.refractions.net 00006 * 00007 * Copyright (C) 2009 2011 Sandro Santilli <strk@keybit.net> 00008 * Copyright (C) 2005 2006 Refractions Research Inc. 00009 * Copyright (C) 2001-2002 Vivid Solutions Inc. 00010 * 00011 * This is free software; you can redistribute and/or modify it under 00012 * the terms of the GNU Lesser General Public Licence as published 00013 * by the Free Software Foundation. 00014 * See the COPYING file for more information. 00015 * 00016 ********************************************************************** 00017 * 00018 * Last port: geom/Geometry.java rev. 1.112 00019 * 00020 **********************************************************************/ 00021 00022 #ifndef GEOS_GEOM_GEOMETRY_H 00023 #define GEOS_GEOM_GEOMETRY_H 00024 00025 #include <geos/export.h> 00026 #include <geos/platform.h> 00027 #include <geos/inline.h> 00028 #include <geos/geom/Envelope.h> 00029 #include <geos/geom/Dimension.h> // for Dimension::DimensionType 00030 #include <geos/geom/GeometryComponentFilter.h> // for inheritance 00031 00032 #include <string> 00033 #include <iostream> 00034 #include <vector> 00035 #include <memory> 00036 00037 #ifdef _MSC_VER 00038 #pragma warning(push) 00039 #pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class 00040 #pragma warning(disable: 4355) // warning C4355: 'this' : used in base member initializer list 00041 #endif 00042 00043 // Forward declarations 00044 namespace geos { 00045 namespace geom { 00046 class Coordinate; 00047 class CoordinateFilter; 00048 class CoordinateSequence; 00049 class CoordinateSequenceFilter; 00050 class GeometryComponentFilter; 00051 class GeometryFactory; 00052 class GeometryFilter; 00053 class IntersectionMatrix; 00054 class PrecisionModel; 00055 class Point; 00056 } 00057 namespace io { // geos.io 00058 class Unload; 00059 } // namespace geos.io 00060 } 00061 00062 namespace geos { 00063 namespace geom { // geos::geom 00064 00066 enum GeometryTypeId { 00068 GEOS_POINT, 00070 GEOS_LINESTRING, 00072 GEOS_LINEARRING, 00074 GEOS_POLYGON, 00076 GEOS_MULTIPOINT, 00078 GEOS_MULTILINESTRING, 00080 GEOS_MULTIPOLYGON, 00082 GEOS_GEOMETRYCOLLECTION 00083 }; 00084 00168 class GEOS_DLL Geometry { 00169 00170 public: 00171 00172 friend class GeometryFactory; 00173 00175 typedef std::vector<const Geometry *> ConstVect; 00176 00178 typedef std::vector<Geometry *> NonConstVect; 00179 00181 typedef std::auto_ptr<Geometry> AutoPtr; 00182 00184 virtual Geometry* clone() const=0; 00185 00187 virtual ~Geometry(); 00188 00189 00197 const GeometryFactory* getFactory() const { return factory; } 00198 00212 void setUserData(void* newUserData) { userData=newUserData; } 00213 00220 void* getUserData() { return userData; } 00221 00222 /* 00223 * \brief 00224 * Returns the ID of the Spatial Reference System used by the 00225 * <code>Geometry</code>. 00226 * 00227 * GEOS supports Spatial Reference System information in the simple way 00228 * defined in the SFS. A Spatial Reference System ID (SRID) is present 00229 * in each <code>Geometry</code> object. <code>Geometry</code> 00230 * provides basic accessor operations for this field, but no others. 00231 * The SRID is represented as an integer. 00232 * 00233 * @return the ID of the coordinate space in which the 00234 * <code>Geometry</code> is defined. 00235 * 00236 */ 00237 virtual int getSRID() const { return SRID; } 00238 00239 /* 00240 * Sets the ID of the Spatial Reference System used by the 00241 * <code>Geometry</code>. 00242 */ 00243 virtual void setSRID(int newSRID) { SRID=newSRID; } 00244 00249 const PrecisionModel* getPrecisionModel() const; 00250 00255 virtual const Coordinate* getCoordinate() const=0; //Abstract 00256 00262 virtual CoordinateSequence* getCoordinates() const=0; //Abstract 00263 00265 virtual std::size_t getNumPoints() const=0; //Abstract 00266 00268 virtual bool isSimple() const; 00269 00271 virtual std::string getGeometryType() const=0; //Abstract 00272 00274 virtual GeometryTypeId getGeometryTypeId() const=0; //Abstract 00275 00278 virtual std::size_t getNumGeometries() const { return 1; } 00279 00282 virtual const Geometry* getGeometryN(std::size_t /*n*/) const { return this; } 00283 00293 virtual bool isValid() const; 00294 00296 virtual bool isEmpty() const=0; //Abstract 00297 00299 virtual bool isRectangle() const { return false; } 00300 00302 virtual Dimension::DimensionType getDimension() const=0; //Abstract 00303 00305 virtual int getCoordinateDimension() const=0; //Abstract 00306 00323 virtual Geometry* getBoundary() const=0; //Abstract 00324 00326 virtual int getBoundaryDimension() const=0; //Abstract 00327 00329 virtual Geometry* getEnvelope() const; 00330 00335 virtual const Envelope* getEnvelopeInternal() const; 00336 00353 virtual bool disjoint(const Geometry *other) const; 00354 00359 virtual bool touches(const Geometry *other) const; 00360 00362 virtual bool intersects(const Geometry *g) const; 00363 00386 virtual bool crosses(const Geometry *g) const; 00387 00392 virtual bool within(const Geometry *g) const; 00393 00395 virtual bool contains(const Geometry *g) const; 00396 00402 virtual bool overlaps(const Geometry *g) const; 00403 00418 virtual bool relate(const Geometry *g, 00419 const std::string& intersectionPattern) const; 00420 00421 bool relate(const Geometry& g, const std::string& intersectionPattern) const 00422 { 00423 return relate(&g, intersectionPattern); 00424 } 00425 00427 virtual IntersectionMatrix* relate(const Geometry *g) const; 00428 IntersectionMatrix* relate(const Geometry &g) const { 00429 return relate(&g); 00430 } 00431 00437 virtual bool equals(const Geometry *g) const; 00438 00477 bool covers(const Geometry* g) const; 00478 00509 bool coveredBy(const Geometry* g) const { 00510 return g->covers(this); 00511 } 00512 00513 00515 virtual std::string toString() const; 00516 00517 virtual std::string toText() const; 00518 00520 // 00523 virtual Geometry* buffer(double distance) const; 00524 00529 // 00532 virtual Geometry* buffer(double distance,int quadrantSegments) const; 00533 00570 virtual Geometry* buffer(double distance, int quadrantSegments, 00571 int endCapStyle) const; 00572 00576 virtual Geometry* convexHull() const; 00577 00587 virtual Geometry* intersection(const Geometry *other) const; 00588 00598 Geometry* Union(const Geometry *other) const; 00599 // throw(IllegalArgumentException *, TopologyException *); 00600 00618 AutoPtr Union() const; 00619 // throw(IllegalArgumentException *, TopologyException *); 00620 00631 virtual Geometry* difference(const Geometry *other) const; 00632 00642 virtual Geometry* symDifference(const Geometry *other) const; 00643 00648 virtual bool equalsExact(const Geometry *other, double tolerance=0) 00649 const=0; //Abstract 00650 00651 virtual void apply_rw(const CoordinateFilter *filter)=0; //Abstract 00652 virtual void apply_ro(CoordinateFilter *filter) const=0; //Abstract 00653 virtual void apply_rw(GeometryFilter *filter); 00654 virtual void apply_ro(GeometryFilter *filter) const; 00655 virtual void apply_rw(GeometryComponentFilter *filter); 00656 virtual void apply_ro(GeometryComponentFilter *filter) const; 00657 00666 virtual void apply_rw(CoordinateSequenceFilter& filter)=0; 00667 00674 virtual void apply_ro(CoordinateSequenceFilter& filter) const=0; 00675 00685 template <class T> 00686 void applyComponentFilter(T& f) const 00687 { 00688 for(std::size_t i=0, n=getNumGeometries(); i<n; ++i) 00689 f.filter(getGeometryN(i)); 00690 } 00691 00693 virtual void normalize()=0; //Abstract 00694 00695 virtual int compareTo(const Geometry *geom) const; 00696 00701 virtual double distance(const Geometry *g) const; 00702 00704 virtual double getArea() const; 00705 00707 virtual double getLength() const; 00708 00720 virtual bool isWithinDistance(const Geometry *geom, 00721 double cDistance) const; 00722 00732 virtual Point* getCentroid() const; 00733 00735 // 00738 virtual bool getCentroid(Coordinate& ret) const; 00739 00750 virtual Point* getInteriorPoint() const; 00751 00752 /* 00753 * \brief 00754 * Notifies this Geometry that its Coordinates have been changed 00755 * by an external party (using a CoordinateFilter, for example). 00756 */ 00757 virtual void geometryChanged(); 00758 00764 void geometryChangedAction(); 00765 00766 protected: 00767 00769 mutable std::auto_ptr<Envelope> envelope; 00770 00772 static bool hasNonEmptyElements(const std::vector<Geometry *>* geometries); 00773 00775 static bool hasNullElements(const CoordinateSequence* list); 00776 00778 static bool hasNullElements(const std::vector<Geometry *>* lrs); 00779 00780 // static void reversePointOrder(CoordinateSequence* coordinates); 00781 // static Coordinate& minCoordinate(CoordinateSequence* coordinates); 00782 // static void scroll(CoordinateSequence* coordinates,Coordinate* firstCoordinate); 00783 // static int indexOf(Coordinate* coordinate,CoordinateSequence* coordinates); 00784 // 00789 virtual bool isEquivalentClass(const Geometry *other) const; 00790 00791 static void checkNotGeometryCollection(const Geometry *g); 00792 // throw(IllegalArgumentException *); 00793 00794 //virtual void checkEqualSRID(Geometry *other); 00795 00796 //virtual void checkEqualPrecisionModel(Geometry *other); 00797 00798 virtual Envelope::AutoPtr computeEnvelopeInternal() const=0; //Abstract 00799 00800 virtual int compareToSameClass(const Geometry *geom) const=0; //Abstract 00801 00802 int compare(std::vector<Coordinate> a, std::vector<Coordinate> b) const; 00803 00804 int compare(std::vector<Geometry *> a, std::vector<Geometry *> b) const; 00805 00806 bool equal(const Coordinate& a, const Coordinate& b, 00807 double tolerance) const; 00808 int SRID; 00809 00811 //Geometry* toInternalGeometry(const Geometry *g) const; 00812 00814 //Geometry* fromInternalGeometry(const Geometry *g) const; 00815 00817 //virtual bool isRectangle() const { return false; } -- moved to public 00818 00819 Geometry(const Geometry &geom); 00820 00830 Geometry(const GeometryFactory *factory); 00831 00832 private: 00833 00834 int getClassSortIndex() const; 00835 00836 class GeometryChangedFilter : public GeometryComponentFilter 00837 { 00838 public: 00839 void filter_rw(Geometry* geom) 00840 { 00841 geom->geometryChangedAction(); 00842 } 00843 }; 00844 00845 static GeometryChangedFilter geometryChangedFilter; 00846 00848 // 00851 const GeometryFactory *factory; 00852 00853 static const GeometryFactory* INTERNAL_GEOMETRY_FACTORY; 00854 00855 void* userData; 00856 }; 00857 00862 GEOS_DLL std::ostream& operator<< (std::ostream& os, const Geometry& geom); 00863 00864 struct GEOS_DLL GeometryGreaterThen { 00865 bool operator()(const Geometry *first, const Geometry *second); 00866 }; 00867 00868 00870 std::string geosversion(); 00871 00877 std::string jtsport(); 00878 00879 // We use this instead of std::pair<auto_ptr<Geometry>> because C++11 00880 // forbids that construct: 00881 // http://lwg.github.com/issues/lwg-closed.html#2068 00882 struct GeomPtrPair { 00883 typedef std::auto_ptr<Geometry> GeomPtr; 00884 GeomPtr first; 00885 GeomPtr second; 00886 }; 00887 00888 } // namespace geos::geom 00889 } // namespace geos 00890 00891 #ifdef _MSC_VER 00892 #pragma warning(pop) 00893 #endif 00894 00895 #endif // ndef GEOS_GEOM_GEOMETRY_H 00896 00897 /********************************************************************** 00898 * $Log$ 00899 * Revision 1.14 2006/07/08 00:33:55 strk 00900 * * configure.in: incremented CAPI minor version, to avoid falling behind any future version from the 2.2. branch. 00901 * * source/geom/Geometry.cpp, source/geom/GeometryFactory.cpp, 00902 * source/geomgraph/EdgeRing.cpp, 00903 * source/headers/geos/geom/Geometry.h, 00904 * source/headers/geos/geom/GeometryFactory.h, 00905 * source/headers/geos/geom/GeometryFactory.inl, 00906 * source/headers/geos/geomgraph/EdgeRing.h: 00907 * updated doxygen comments (sync with JTS head). 00908 * * source/headers/geos/platform.h.in: include <inttypes.h> 00909 * rather then <stdint.h> 00910 * 00911 * Revision 1.13 2006/06/12 10:10:39 strk 00912 * Fixed getGeometryN() to take size_t rather then int, changed unsigned int parameters to size_t. 00913 * 00914 * Revision 1.12 2006/05/18 08:56:50 strk 00915 * * source/geom/Geometry.cpp, 00916 * source/headers/geos/geom/Geometry.h: added 00917 * covers() and isCoveredBy() predicates. 00918 * * tests/unit/Makefile.am, 00919 * tests/unit/geom/Geometry/coversTest.cpp: 00920 * added test for covers() predicates. 00921 * 00922 * Revision 1.11 2006/05/04 15:49:39 strk 00923 * updated all Geometry::getDimension() methods to return Dimension::DimensionType (closes bug#93) 00924 * 00925 * Revision 1.10 2006/04/28 10:55:39 strk 00926 * Geometry constructors made protected, to ensure all constructions use GeometryFactory, 00927 * which has been made friend of all Geometry derivates. getNumPoints() changed to return 00928 * size_t. 00929 * 00930 * Revision 1.9 2006/04/11 09:31:47 strk 00931 * Added Geometry::AutoPtr typedef 00932 * 00933 * Revision 1.8 2006/04/10 18:15:09 strk 00934 * Changed Geometry::envelope member to be of type auto_ptr<Envelope>. 00935 * Changed computeEnvelopeInternal() signater to return auto_ptr<Envelope> 00936 * 00937 * Revision 1.7 2006/04/07 09:54:30 strk 00938 * Geometry::getNumGeometries() changed to return 'unsigned int' 00939 * rather then 'int' 00940 * 00941 * Revision 1.6 2006/03/31 16:53:53 strk 00942 * Added comment about possible NULL return from getCoordinate() 00943 * 00944 * Revision 1.5 2006/03/24 09:52:41 strk 00945 * USE_INLINE => GEOS_INLINE 00946 * 00947 * Revision 1.4 2006/03/23 15:10:29 strk 00948 * Dropped by-pointer TopologyException constructor, various small cleanups 00949 * 00950 * Revision 1.3 2006/03/23 12:12:01 strk 00951 * Fixes to allow build with -DGEOS_INLINE 00952 * 00953 * Revision 1.2 2006/03/20 12:03:25 strk 00954 * Added operator<< for Geometry, writing HEXWKB 00955 * 00956 * Revision 1.1 2006/03/09 16:46:49 strk 00957 * geos::geom namespace definition, first pass at headers split 00958 * 00959 **********************************************************************/