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

- File List

# Geometry.h

    00001 /**********************************************************************
    00002  * $Id: Geometry.h 2757 2009-12-01 15:39:41Z mloskot $
    00003  *
    00004  * GEOS - Geometry Engine Open Source
    00005  * http://geos.refractions.net
    00006  *
    00007  * Copyright (C) 2009  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 // Forward declarations
    00038 namespace geos {
    00039         namespace geom {
    00040                 class Coordinate;
    00041                 class CoordinateFilter;
    00042                 class CoordinateSequence;
    00043                 class CoordinateSequenceFilter;
    00044                 class GeometryComponentFilter;
    00045                 class GeometryFactory;
    00046                 class GeometryFilter;
    00047                 class IntersectionMatrix;
    00048                 class PrecisionModel;
    00049                 class Point;
    00050         }
    00051         namespace io { // geos.io
    00052                 class Unload;
    00053         } // namespace geos.io
    00054 }
    00055
    00056 namespace geos {
    00057 namespace geom { // geos::geom
    00058
    00060 enum GeometryTypeId {
    00062         GEOS_POINT,
    00064         GEOS_LINESTRING,
    00066         GEOS_LINEARRING,
    00068         GEOS_POLYGON,
    00070         GEOS_MULTIPOINT,
    00072         GEOS_MULTILINESTRING,
    00074         GEOS_MULTIPOLYGON,
    00076         GEOS_GEOMETRYCOLLECTION
    00077 };
    00078
    00162 class GEOS_DLL Geometry {
    00163
    00164 public:
    00165
    00166         friend class GeometryFactory;
    00167
    00168         friend std::ostream& operator<< (std::ostream& os, const Geometry& geom);
    00169
    00171         typedef std::vector<const Geometry *> ConstVect;
    00172
    00174         typedef std::vector<Geometry *> NonConstVect;
    00175
    00177         typedef std::auto_ptr<Geometry> AutoPtr;
    00178
    00180         virtual Geometry* clone() const=0;
    00181
    00183         virtual ~Geometry();
    00184
    00185
    00193         const GeometryFactory* getFactory() const { return factory; }
    00194
    00208         void setUserData(void* newUserData) { userData=newUserData; }
    00209
    00216         void* getUserData() { return userData; }
    00217
    00218         /*
    00219          * \brief
    00220          * Returns the ID of the Spatial Reference System used by the
    00221          * <code>Geometry</code>.
    00222          *
    00223          * GEOS supports Spatial Reference System information in the simple way
    00224          * defined in the SFS. A Spatial Reference System ID (SRID) is present
    00225          * in each <code>Geometry</code> object. <code>Geometry</code>
    00226          * provides basic accessor operations for this field, but no others.
    00227          * The SRID is represented as an integer.
    00228          *
    00229          * @return the ID of the coordinate space in which the
    00230          * <code>Geometry</code> is defined.
    00231          *
    00232          */
    00233         virtual int getSRID() const { return SRID; }
    00234
    00235         /*
    00236          * Sets the ID of the Spatial Reference System used by the
    00237          * <code>Geometry</code>.
    00238          */
    00239         virtual void setSRID(int newSRID) { SRID=newSRID; }
    00240
    00245         const PrecisionModel* getPrecisionModel() const;
    00246
    00251         virtual const Coordinate* getCoordinate() const=0; //Abstract
    00252
    00258         virtual CoordinateSequence* getCoordinates() const=0; //Abstract
    00259
    00261         virtual size_t getNumPoints() const=0; //Abstract
    00262
    00264         virtual bool isSimple() const;
    00265
    00267         virtual std::string getGeometryType() const=0; //Abstract
    00268
    00270         virtual GeometryTypeId getGeometryTypeId() const=0; //Abstract
    00271
    00274         virtual size_t getNumGeometries() const { return 1; }
    00275
    00278         virtual const Geometry* getGeometryN(size_t /*n*/) const { return this; }
    00279
    00289         virtual bool isValid() const;
    00290
    00292         virtual bool isEmpty() const=0; //Abstract
    00293
    00295         virtual bool isRectangle() const { return false; }
    00296
    00298         virtual Dimension::DimensionType getDimension() const=0; //Abstract
    00299
    00316         virtual Geometry* getBoundary() const=0; //Abstract
    00317
    00319         virtual int getBoundaryDimension() const=0; //Abstract
    00320
    00322         virtual Geometry* getEnvelope() const;
    00323
    00328         virtual const Envelope* getEnvelopeInternal() const;
    00329
    00346         virtual bool disjoint(const Geometry *other) const;
    00347
    00352         virtual bool touches(const Geometry *other) const;
    00353
    00355         virtual bool intersects(const Geometry *g) const;
    00356
    00379         virtual bool crosses(const Geometry *g) const;
    00380
    00385         virtual bool within(const Geometry *g) const;
    00386
    00388         virtual bool contains(const Geometry *g) const;
    00389
    00395         virtual bool overlaps(const Geometry *g) const;
    00396
    00411         virtual bool relate(const Geometry *g,
    00412                         const std::string& intersectionPattern) const;
    00413
    00414         bool relate(const Geometry& g, const std::string& intersectionPattern) const
    00415         {
    00416                 return relate(&g, intersectionPattern);
    00417         }
    00418
    00420         virtual IntersectionMatrix* relate(const Geometry *g) const;
    00421         IntersectionMatrix* relate(const Geometry &g) const {
    00422                 return relate(&g);
    00423         }
    00424
    00430         virtual bool equals(const Geometry *g) const;
    00431
    00470         bool covers(const Geometry* g) const;
    00471
    00502         bool coveredBy(const Geometry* g) const {
    00503           return g->covers(this);
    00504         }
    00505
    00506
    00508         virtual std::string toString() const;
    00509
    00510         virtual std::string toText() const;
    00511
    00513         //
    00516         virtual Geometry* buffer(double distance) const;
    00517
    00522         //
    00525         virtual Geometry* buffer(double distance,int quadrantSegments) const;
    00526
    00563         virtual Geometry* buffer(double distance, int quadrantSegments,
    00564                         int endCapStyle) const;
    00565
    00569         virtual Geometry* convexHull() const;
    00570
    00580         virtual Geometry* intersection(const Geometry *other) const;
    00581
    00591         virtual Geometry* Union(const Geometry *other) const;
    00592                 // throw(IllegalArgumentException *, TopologyException *);
    00593
    00604         virtual Geometry* difference(const Geometry *other) const;
    00605
    00615         virtual Geometry* symDifference(const Geometry *other) const;
    00616
    00621         virtual bool equalsExact(const Geometry *other, double tolerance=0)
    00622                 const=0; //Abstract
    00623
    00624         virtual void apply_rw(const CoordinateFilter *filter)=0; //Abstract
    00625         virtual void apply_ro(CoordinateFilter *filter) const=0; //Abstract
    00626         virtual void apply_rw(GeometryFilter *filter);
    00627         virtual void apply_ro(GeometryFilter *filter) const;
    00628         virtual void apply_rw(GeometryComponentFilter *filter);
    00629         virtual void apply_ro(GeometryComponentFilter *filter) const;
    00630
    00639         virtual void apply_rw(CoordinateSequenceFilter& filter)=0;
    00640
    00647         virtual void apply_ro(CoordinateSequenceFilter& filter) const=0;
    00648
    00658         template <class T>
    00659         void applyComponentFilter(T& f) const
    00660         {
    00661                 for(size_t i=0, n=getNumGeometries(); i<n; ++i)
    00662                         f.filter(getGeometryN(i));
    00663         }
    00664
    00666         virtual void normalize()=0; //Abstract
    00667
    00668         virtual int compareTo(const Geometry *geom) const;
    00669
    00674         virtual double distance(const Geometry *g) const;
    00675
    00677         virtual double getArea() const;
    00678
    00680         virtual double getLength() const;
    00681
    00686         virtual bool isWithinDistance(const Geometry *geom,double cDistance);
    00687
    00697         virtual Point* getCentroid() const;
    00698
    00700         //
    00703         virtual bool getCentroid(Coordinate& ret) const;
    00704
    00715         virtual Point* getInteriorPoint() const;
    00716
    00717         /*
    00718          * \brief
    00719          * Notifies this Geometry that its Coordinates have been changed
    00720          * by an external party (using a CoordinateFilter, for example).
    00721          */
    00722         virtual void geometryChanged();
    00723
    00729         void geometryChangedAction();
    00730
    00731 protected:
    00732
    00734         mutable std::auto_ptr<Envelope> envelope;
    00735
    00737         static bool hasNonEmptyElements(const std::vector<Geometry *>* geometries);
    00738
    00740         static bool hasNullElements(const CoordinateSequence* list);
    00741
    00743         static bool hasNullElements(const std::vector<Geometry *>* lrs);
    00744
    00745 //      static void reversePointOrder(CoordinateSequence* coordinates);
    00746 //      static Coordinate& minCoordinate(CoordinateSequence* coordinates);
    00747 //      static void scroll(CoordinateSequence* coordinates,Coordinate* firstCoordinate);
    00748 //      static int indexOf(Coordinate* coordinate,CoordinateSequence* coordinates);
    00749 //
    00754         virtual bool isEquivalentClass(const Geometry *other) const;
    00755
    00756         static void checkNotGeometryCollection(const Geometry *g);
    00757                         // throw(IllegalArgumentException *);
    00758
    00759         //virtual void checkEqualSRID(Geometry *other);
    00760
    00761         //virtual void checkEqualPrecisionModel(Geometry *other);
    00762
    00763         virtual Envelope::AutoPtr computeEnvelopeInternal() const=0; //Abstract
    00764
    00765         virtual int compareToSameClass(const Geometry *geom) const=0; //Abstract
    00766
    00767         int compare(std::vector<Coordinate> a, std::vector<Coordinate> b) const;
    00768
    00769         int compare(std::vector<Geometry *> a, std::vector<Geometry *> b) const;
    00770
    00771         bool equal(const Coordinate& a, const Coordinate& b,
    00772                         double tolerance) const;
    00773         int SRID;
    00774
    00776         //Geometry* toInternalGeometry(const Geometry *g) const;
    00777
    00779         //Geometry* fromInternalGeometry(const Geometry *g) const;
    00780
    00782         //virtual bool isRectangle() const { return false; } -- moved to public
    00783
    00784         Geometry(const Geometry &geom);
    00785
    00795         Geometry(const GeometryFactory *factory);
    00796
    00797 private:
    00798
    00799
    00800
    00801         int getClassSortIndex() const;
    00802
    00803         class GeometryChangedFilter : public GeometryComponentFilter
    00804         {
    00805         public:
    00806                 void filter_rw(Geometry* geom)
    00807                 {
    00808                         geom->geometryChangedAction();
    00809                 }
    00810         };
    00811
    00812         static GeometryChangedFilter geometryChangedFilter;
    00813
    00815         //
    00818         const GeometryFactory *factory;
    00819
    00820         static const GeometryFactory* INTERNAL_GEOMETRY_FACTORY;
    00821
    00822         void* userData;
    00823 };
    00824
    00829 std::ostream& operator<< (std::ostream& os, const Geometry& geom);
    00830
    00831 struct GEOS_DLL GeometryGreaterThen {
    00832         bool operator()(const Geometry *first, const Geometry *second);
    00833 };
    00834
    00835
    00837 std::string geosversion();
    00838
    00844 std::string jtsport();
    00845
    00846
    00847 } // namespace geos::geom
    00848 } // namespace geos
    00849
    00850 #ifdef GEOS_INLINE
    00851 # include <geos/geom/Geometry.inl>
    00852 #endif
    00853
    00854 #endif // ndef GEOS_GEOM_GEOMETRY_H
    00855
    00856 /**********************************************************************
    00857  * $Log$
    00858  * Revision 1.14  2006/07/08 00:33:55  strk
    00859  *         * configure.in: incremented CAPI minor version, to avoid                        falling behind any future version from the 2.2. branch.
    00860  *         * source/geom/Geometry.cpp, source/geom/GeometryFactory.cpp,
    00861  *         source/geomgraph/EdgeRing.cpp,
    00862  *         source/headers/geos/geom/Geometry.h,
    00863  *         source/headers/geos/geom/GeometryFactory.h,
    00864  *         source/headers/geos/geom/GeometryFactory.inl,
    00865  *         source/headers/geos/geomgraph/EdgeRing.h:
    00866  *         updated doxygen comments (sync with JTS head).
    00867  *         * source/headers/geos/platform.h.in: include <inttypes.h>
    00868  *         rather then <stdint.h>
    00869  *
    00870  * Revision 1.13  2006/06/12 10:10:39  strk
    00871  * Fixed getGeometryN() to take size_t rather then int, changed unsigned int parameters to size_t.
    00872  *
    00873  * Revision 1.12  2006/05/18 08:56:50  strk
    00874  *         * source/geom/Geometry.cpp,
    00875  *         source/headers/geos/geom/Geometry.h: added
    00876  *         covers() and isCoveredBy() predicates.
    00877  *         * tests/unit/Makefile.am,
    00878  *         tests/unit/geom/Geometry/coversTest.cpp:
    00879  *         added test for covers() predicates.
    00880  *
    00881  * Revision 1.11  2006/05/04 15:49:39  strk
    00882  * updated all Geometry::getDimension() methods to return Dimension::DimensionType (closes bug#93)
    00883  *
    00884  * Revision 1.10  2006/04/28 10:55:39  strk
    00885  * Geometry constructors made protected, to ensure all constructions use GeometryFactory,
    00886  * which has been made friend of all Geometry derivates. getNumPoints() changed to return
    00887  * size_t.
    00888  *
    00889  * Revision 1.9  2006/04/11 09:31:47  strk
    00890  * Added Geometry::AutoPtr typedef
    00891  *
    00892  * Revision 1.8  2006/04/10 18:15:09  strk
    00893  * Changed Geometry::envelope member to be of type auto_ptr<Envelope>.
    00894  * Changed computeEnvelopeInternal() signater to return auto_ptr<Envelope>
    00895  *
    00896  * Revision 1.7  2006/04/07 09:54:30  strk
    00897  * Geometry::getNumGeometries() changed to return 'unsigned int'
    00898  * rather then 'int'
    00899  *
    00900  * Revision 1.6  2006/03/31 16:53:53  strk
    00901  * Added comment about possible NULL return from getCoordinate()
    00902  *
    00903  * Revision 1.5  2006/03/24 09:52:41  strk
    00904  * USE_INLINE => GEOS_INLINE
    00905  *
    00906  * Revision 1.4  2006/03/23 15:10:29  strk
    00907  * Dropped by-pointer TopologyException constructor, various small cleanups
    00908  *
    00909  * Revision 1.3  2006/03/23 12:12:01  strk
    00910  * Fixes to allow build with -DGEOS_INLINE
    00911  *
    00912  * Revision 1.2  2006/03/20 12:03:25  strk
    00913  * Added operator<< for Geometry, writing HEXWKB
    00914  *
    00915  * Revision 1.1  2006/03/09 16:46:49  strk
    00916  * geos::geom namespace definition, first pass at headers split
    00917  *
    00918  **********************************************************************/