GEOS: Geometry.h Source File

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

# Geometry.h

    00001 /**********************************************************************
    00002  * $Id: Geometry.h 1880 2006-10-27 11:54:17Z strk $
    00003  *
    00004  * GEOS - Geometry Engine Open Source
    00005  * http://geos.refractions.net
    00006  *
    00007  * Copyright (C) 2001-2002 Vivid Solutions Inc.
    00008  * Copyright (C) 2005 2006 Refractions Research Inc.
    00009  *
    00010  * This is free software; you can redistribute and/or modify it under
    00011  * the terms of the GNU Lesser General Public Licence as published
    00012  * by the Free Software Foundation.
    00013  * See the COPYING file for more information.
    00014  *
    00015  **********************************************************************
    00016  *
    00017  * Last port: geom/Geometry.java rev. 1.100
    00018  *
    00019  **********************************************************************/
    00020
    00021 #ifndef GEOS_GEOM_GEOMETRY_H
    00022 #define GEOS_GEOM_GEOMETRY_H
    00023
    00024 #include <geos/platform.h>
    00025 #include <geos/inline.h>
    00026 #include <geos/geom/Envelope.h>
    00027 #include <geos/geom/Dimension.h> // for Dimension::DimensionType
    00028
    00029 #include <string>
    00030 #include <iostream>
    00031 #include <vector>
    00032 #include <memory>
    00033
    00034 // Forward declarations
    00035 namespace geos {
    00036         namespace geom {
    00037                 class Coordinate;
    00038                 class CoordinateFilter;
    00039                 class CoordinateSequence;
    00040                 class Envelope;
    00041                 class GeometryComponentFilter;
    00042                 class GeometryFactory;
    00043                 class GeometryFilter;
    00044                 class IntersectionMatrix;
    00045                 class PrecisionModel;
    00046                 class Point;
    00047         }
    00048         namespace io { // geos.io
    00049                 class Unload;
    00050         } // namespace geos.io
    00051 }
    00052
    00053 namespace geos {
    00054 namespace geom { // geos::geom
    00055
    00057 enum GeometryTypeId {
    00059         GEOS_POINT,
    00061         GEOS_LINESTRING,
    00063         GEOS_LINEARRING,
    00065         GEOS_POLYGON,
    00067         GEOS_MULTIPOINT,
    00069         GEOS_MULTILINESTRING,
    00071         GEOS_MULTIPOLYGON,
    00073         GEOS_GEOMETRYCOLLECTION
    00074 };
    00075
    00159 class Geometry {
    00160
    00161 public:
    00162
    00163         friend class GeometryFactory;
    00164
    00165         friend std::ostream& operator<< (std::ostream& os, const Geometry& geom);
    00166
    00168         typedef std::vector<const Geometry *> ConstVect;
    00169
    00171         typedef std::vector<Geometry *> NonConstVect;
    00172
    00174         typedef std::auto_ptr<Geometry> AutoPtr;
    00175
    00177         virtual Geometry* clone() const=0;
    00178
    00180         virtual ~Geometry();
    00181
    00182
    00190         const GeometryFactory* getFactory() const { return factory; }
    00191
    00205         void setUserData(void* newUserData) { userData=newUserData; }
    00206
    00213         void* getUserData() { return userData; }
    00214
    00215         /*
    00216          * \brief
    00217          * Returns the ID of the Spatial Reference System used by the
    00218          * <code>Geometry</code>.
    00219          *
    00220          * GEOS supports Spatial Reference System information in the simple way
    00221          * defined in the SFS. A Spatial Reference System ID (SRID) is present
    00222          * in each <code>Geometry</code> object. <code>Geometry</code>
    00223          * provides basic accessor operations for this field, but no others.
    00224          * The SRID is represented as an integer.
    00225          *
    00226          * @return the ID of the coordinate space in which the
    00227          * <code>Geometry</code> is defined.
    00228          *
    00229          */
    00230         virtual int getSRID() const { return SRID; }
    00231
    00232         /*
    00233          * Sets the ID of the Spatial Reference System used by the
    00234          * <code>Geometry</code>.
    00235          */
    00236         virtual void setSRID(int newSRID) { SRID=newSRID; }
    00237
    00242         const PrecisionModel* getPrecisionModel() const;
    00243
    00248         virtual const Coordinate* getCoordinate() const=0; //Abstract
    00249
    00255         virtual CoordinateSequence* getCoordinates() const=0; //Abstract
    00256
    00258         virtual size_t getNumPoints() const=0; //Abstract
    00259
    00261         virtual bool isSimple() const=0; //Abstract
    00262
    00264         virtual std::string getGeometryType() const=0; //Abstract
    00265
    00267         virtual GeometryTypeId getGeometryTypeId() const=0; //Abstract
    00268
    00271         virtual size_t getNumGeometries() const { return 1; }
    00272
    00275         virtual const Geometry* getGeometryN(size_t /*n*/) const { return this; }
    00276
    00286         virtual bool isValid() const;
    00287
    00289         virtual bool isEmpty() const=0; //Abstract
    00290
    00292         virtual Dimension::DimensionType getDimension() const=0; //Abstract
    00293
    00300         virtual Geometry* getBoundary() const=0; //Abstract
    00301
    00303         virtual int getBoundaryDimension() const=0; //Abstract
    00304
    00306         virtual Geometry* getEnvelope() const;
    00307
    00312         virtual const Envelope* getEnvelopeInternal() const;
    00313
    00319         virtual bool disjoint(const Geometry *other) const;
    00320
    00325         virtual bool touches(const Geometry *other) const;
    00326
    00328         virtual bool intersects(const Geometry *g) const;
    00329
    00336         virtual bool crosses(const Geometry *g) const;
    00337
    00342         virtual bool within(const Geometry *g) const;
    00343
    00345         virtual bool contains(const Geometry *g) const;
    00346
    00352         virtual bool overlaps(const Geometry *g) const;
    00353
    00368         virtual bool relate(const Geometry *g,
    00369                         const std::string& intersectionPattern) const;
    00370
    00371         bool relate(const Geometry& g, const std::string& intersectionPattern) const
    00372         {
    00373                 return relate(&g, intersectionPattern);
    00374         }
    00375
    00377         virtual IntersectionMatrix* relate(const Geometry *g) const;
    00378         IntersectionMatrix* relate(const Geometry &g) const {
    00379                 return relate(&g);
    00380         }
    00381
    00387         virtual bool equals(const Geometry *g) const;
    00388
    00426         bool covers(const Geometry* g) const;
    00427
    00454         bool coveredBy(const Geometry* g) const {
    00455           return g->covers(this);
    00456         }
    00457
    00458
    00460         virtual std::string toString() const;
    00461
    00462         virtual std::string toText() const;
    00463
    00465         //
    00468         virtual Geometry* buffer(double distance) const;
    00469
    00474         //
    00477         virtual Geometry* buffer(double distance,int quadrantSegments) const;
    00478
    00515         virtual Geometry* buffer(double distance, int quadrantSegments,
    00516                         int endCapStyle) const;
    00517
    00521         virtual Geometry* convexHull() const;
    00522
    00531         virtual Geometry* intersection(const Geometry *other) const;
    00532
    00541         virtual Geometry* Union(const Geometry *other) const;
    00542                 // throw(IllegalArgumentException *, TopologyException *);
    00543
    00553         virtual Geometry* difference(const Geometry *other) const;
    00554
    00563         virtual Geometry* symDifference(const Geometry *other) const;
    00564
    00569         virtual bool equalsExact(const Geometry *other, double tolerance=0)
    00570                 const=0; //Abstract
    00571
    00572         virtual void apply_rw(const CoordinateFilter *filter)=0; //Abstract
    00573         virtual void apply_ro(CoordinateFilter *filter) const=0; //Abstract
    00574         virtual void apply_rw(GeometryFilter *filter);
    00575         virtual void apply_ro(GeometryFilter *filter) const;
    00576         virtual void apply_rw(GeometryComponentFilter *filter);
    00577         virtual void apply_ro(GeometryComponentFilter *filter) const;
    00578
    00588         template <class T>
    00589         void applyComponentFilter(T& f) const
    00590         {
    00591                 for(size_t i=0, n=getNumGeometries(); i<n; ++i)
    00592                         f.filter(getGeometryN(i));
    00593         }
    00594
    00596         virtual void normalize()=0; //Abstract
    00597
    00598         virtual int compareTo(const Geometry *geom) const;
    00599
    00604         virtual double distance(const Geometry *g) const;
    00605
    00607         virtual double getArea() const;
    00608
    00610         virtual double getLength() const;
    00611
    00616         virtual bool isWithinDistance(const Geometry *geom,double cDistance);
    00617
    00627         virtual Point* getCentroid() const;
    00628
    00630         //
    00633         virtual bool getCentroid(Coordinate& ret) const;
    00634
    00645         virtual Point* getInteriorPoint() const;
    00646
    00647         /*
    00648          * \brief
    00649          * Notifies this Geometry that its Coordinates have been changed
    00650          * by an external party (using a CoordinateFilter, for example).
    00651          */
    00652         virtual void geometryChanged();
    00653
    00659         void geometryChangedAction();
    00660
    00661 protected:
    00662         mutable std::auto_ptr<Envelope> envelope;
    00663
    00665         static bool hasNonEmptyElements(const std::vector<Geometry *>* geometries);
    00666
    00668         static bool hasNullElements(const CoordinateSequence* list);
    00669
    00671         static bool hasNullElements(const std::vector<Geometry *>* lrs);
    00672
    00673 //      static void reversePointOrder(CoordinateSequence* coordinates);
    00674 //      static Coordinate& minCoordinate(CoordinateSequence* coordinates);
    00675 //      static void scroll(CoordinateSequence* coordinates,Coordinate* firstCoordinate);
    00676 //      static int indexOf(Coordinate* coordinate,CoordinateSequence* coordinates);
    00677 //
    00682         virtual bool isEquivalentClass(const Geometry *other) const;
    00683
    00684         static void checkNotGeometryCollection(const Geometry *g);
    00685                         // throw(IllegalArgumentException *);
    00686
    00687         //virtual void checkEqualSRID(Geometry *other);
    00688
    00689         //virtual void checkEqualPrecisionModel(Geometry *other);
    00690
    00691         virtual Envelope::AutoPtr computeEnvelopeInternal() const=0; //Abstract
    00692
    00693         virtual int compareToSameClass(const Geometry *geom) const=0; //Abstract
    00694
    00695         int compare(std::vector<Coordinate> a, std::vector<Coordinate> b) const;
    00696
    00697         int compare(std::vector<Geometry *> a, std::vector<Geometry *> b) const;
    00698
    00699         bool equal(const Coordinate& a, const Coordinate& b,
    00700                         double tolerance) const;
    00701         int SRID;
    00702
    00704         //Geometry* toInternalGeometry(const Geometry *g) const;
    00705
    00707         //Geometry* fromInternalGeometry(const Geometry *g) const;
    00708
    00710         virtual bool isRectangle() const { return false; }
    00711
    00712         Geometry(const Geometry &geom);
    00713
    00720         Geometry(const GeometryFactory *factory);
    00721
    00722 private:
    00723         int getClassSortIndex() const;
    00724         static GeometryComponentFilter geometryChangedFilter;
    00725         const GeometryFactory *factory;
    00726         static const GeometryFactory* INTERNAL_GEOMETRY_FACTORY;
    00727         void* userData;
    00728 };
    00729
    00734 std::ostream& operator<< (std::ostream& os, const Geometry& geom);
    00735
    00736 struct GeometryGreaterThen {
    00737         bool operator()(const Geometry *first, const Geometry *second);
    00738 };
    00739
    00740
    00742 std::string geosversion();
    00743
    00749 std::string jtsport();
    00750
    00751
    00752 } // namespace geos::geom
    00753 } // namespace geos
    00754
    00755 #ifdef GEOS_INLINE
    00756 # include <geos/geom/Geometry.inl>
    00757 #endif
    00758
    00759 #endif // ndef GEOS_GEOM_GEOMETRY_H
    00760
    00761 /**********************************************************************
    00762  * $Log$
    00763  * Revision 1.14  2006/07/08 00:33:55  strk
    00764  *         * configure.in: incremented CAPI minor version, to avoid                        falling behind any future version from the 2.2. branch.
    00765  *         * source/geom/Geometry.cpp, source/geom/GeometryFactory.cpp,
    00766  *         source/geomgraph/EdgeRing.cpp,
    00767  *         source/headers/geos/geom/Geometry.h,
    00768  *         source/headers/geos/geom/GeometryFactory.h,
    00769  *         source/headers/geos/geom/GeometryFactory.inl,
    00770  *         source/headers/geos/geomgraph/EdgeRing.h:
    00771  *         updated doxygen comments (sync with JTS head).
    00772  *         * source/headers/geos/platform.h.in: include <inttypes.h>
    00773  *         rather then <stdint.h>
    00774  *
    00775  * Revision 1.13  2006/06/12 10:10:39  strk
    00776  * Fixed getGeometryN() to take size_t rather then int, changed unsigned int parameters to size_t.
    00777  *
    00778  * Revision 1.12  2006/05/18 08:56:50  strk
    00779  *         * source/geom/Geometry.cpp,
    00780  *         source/headers/geos/geom/Geometry.h: added
    00781  *         covers() and isCoveredBy() predicates.
    00782  *         * tests/unit/Makefile.am,
    00783  *         tests/unit/geom/Geometry/coversTest.cpp:
    00784  *         added test for covers() predicates.
    00785  *
    00786  * Revision 1.11  2006/05/04 15:49:39  strk
    00787  * updated all Geometry::getDimension() methods to return Dimension::DimensionType (closes bug#93)
    00788  *
    00789  * Revision 1.10  2006/04/28 10:55:39  strk
    00790  * Geometry constructors made protected, to ensure all constructions use GeometryFactory,
    00791  * which has been made friend of all Geometry derivates. getNumPoints() changed to return
    00792  * size_t.
    00793  *
    00794  * Revision 1.9  2006/04/11 09:31:47  strk
    00795  * Added Geometry::AutoPtr typedef
    00796  *
    00797  * Revision 1.8  2006/04/10 18:15:09  strk
    00798  * Changed Geometry::envelope member to be of type auto_ptr<Envelope>.
    00799  * Changed computeEnvelopeInternal() signater to return auto_ptr<Envelope>
    00800  *
    00801  * Revision 1.7  2006/04/07 09:54:30  strk
    00802  * Geometry::getNumGeometries() changed to return 'unsigned int'
    00803  * rather then 'int'
    00804  *
    00805  * Revision 1.6  2006/03/31 16:53:53  strk
    00806  * Added comment about possible NULL return from getCoordinate()
    00807  *
    00808  * Revision 1.5  2006/03/24 09:52:41  strk
    00809  * USE_INLINE => GEOS_INLINE
    00810  *
    00811  * Revision 1.4  2006/03/23 15:10:29  strk
    00812  * Dropped by-pointer TopologyException constructor, various small cleanups
    00813  *
    00814  * Revision 1.3  2006/03/23 12:12:01  strk
    00815  * Fixes to allow build with -DGEOS_INLINE
    00816  *
    00817  * Revision 1.2  2006/03/20 12:03:25  strk
    00818  * Added operator<< for Geometry, writing HEXWKB
    00819  *
    00820  * Revision 1.1  2006/03/09 16:46:49  strk
    00821  * geos::geom namespace definition, first pass at headers split
    00822  *
    00823  **********************************************************************/