Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | Related Pages

Geometry.h

00001 /**********************************************************************
00002  * $Id: Geometry.h 2556 2009-06-06 22:22:28Z strk $
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 Envelope;
00045                 class GeometryComponentFilter;
00046                 class GeometryFactory;
00047                 class GeometryFilter;
00048                 class IntersectionMatrix;
00049                 class PrecisionModel;
00050                 class Point;
00051         }
00052         namespace io { // geos.io
00053                 class Unload;
00054         } // namespace geos.io
00055 }
00056 
00057 namespace geos {
00058 namespace geom { // geos::geom
00059 
00061 enum GeometryTypeId {
00063         GEOS_POINT,
00065         GEOS_LINESTRING,
00067         GEOS_LINEARRING,
00069         GEOS_POLYGON,
00071         GEOS_MULTIPOINT,
00073         GEOS_MULTILINESTRING,
00075         GEOS_MULTIPOLYGON,
00077         GEOS_GEOMETRYCOLLECTION
00078 };
00079 
00163 class GEOS_DLL Geometry {
00164 
00165 public:
00166 
00167         friend class GeometryFactory;
00168 
00169         friend std::ostream& operator<< (std::ostream& os, const Geometry& geom);
00170 
00172         typedef std::vector<const Geometry *> ConstVect;
00173 
00175         typedef std::vector<Geometry *> NonConstVect;
00176 
00178         typedef std::auto_ptr<Geometry> AutoPtr;
00179 
00181         virtual Geometry* clone() const=0;
00182 
00184         virtual ~Geometry();
00185 
00186 
00194         const GeometryFactory* getFactory() const { return factory; }
00195 
00209         void setUserData(void* newUserData) { userData=newUserData; }
00210 
00217         void* getUserData() { return userData; }
00218 
00219         /*
00220          * \brief
00221          * Returns the ID of the Spatial Reference System used by the
00222          * <code>Geometry</code>.
00223          *
00224          * GEOS supports Spatial Reference System information in the simple way
00225          * defined in the SFS. A Spatial Reference System ID (SRID) is present
00226          * in each <code>Geometry</code> object. <code>Geometry</code>
00227          * provides basic accessor operations for this field, but no others.
00228          * The SRID is represented as an integer.
00229          *
00230          * @return the ID of the coordinate space in which the
00231          * <code>Geometry</code> is defined.
00232          *
00233          */
00234         virtual int getSRID() const { return SRID; }
00235 
00236         /*
00237          * Sets the ID of the Spatial Reference System used by the
00238          * <code>Geometry</code>.
00239          */
00240         virtual void setSRID(int newSRID) { SRID=newSRID; }
00241 
00246         const PrecisionModel* getPrecisionModel() const;
00247 
00252         virtual const Coordinate* getCoordinate() const=0; //Abstract
00253 
00259         virtual CoordinateSequence* getCoordinates() const=0; //Abstract
00260 
00262         virtual size_t getNumPoints() const=0; //Abstract
00263 
00265         virtual bool isSimple() const; 
00266 
00268         virtual std::string getGeometryType() const=0; //Abstract
00269 
00271         virtual GeometryTypeId getGeometryTypeId() const=0; //Abstract
00272 
00275         virtual size_t getNumGeometries() const { return 1; }
00276 
00279         virtual const Geometry* getGeometryN(size_t /*n*/) const { return this; }
00280 
00290         virtual bool isValid() const;
00291 
00293         virtual bool isEmpty() const=0; //Abstract
00294 
00296         virtual bool isRectangle() const { return false; }
00297 
00299         virtual Dimension::DimensionType getDimension() const=0; //Abstract
00300 
00317         virtual Geometry* getBoundary() const=0; //Abstract
00318 
00320         virtual int getBoundaryDimension() const=0; //Abstract
00321 
00323         virtual Geometry* getEnvelope() const;
00324 
00329         virtual const Envelope* getEnvelopeInternal() const;
00330 
00347         virtual bool disjoint(const Geometry *other) const;
00348 
00353         virtual bool touches(const Geometry *other) const;
00354 
00356         virtual bool intersects(const Geometry *g) const;
00357 
00380         virtual bool crosses(const Geometry *g) const;
00381 
00386         virtual bool within(const Geometry *g) const;
00387 
00389         virtual bool contains(const Geometry *g) const;
00390 
00396         virtual bool overlaps(const Geometry *g) const;
00397 
00412         virtual bool relate(const Geometry *g,
00413                         const std::string& intersectionPattern) const;
00414 
00415         bool relate(const Geometry& g, const std::string& intersectionPattern) const
00416         {
00417                 return relate(&g, intersectionPattern);
00418         }
00419 
00421         virtual IntersectionMatrix* relate(const Geometry *g) const;
00422         IntersectionMatrix* relate(const Geometry &g) const {
00423                 return relate(&g);
00424         }
00425 
00431         virtual bool equals(const Geometry *g) const;
00432 
00471         bool covers(const Geometry* g) const;
00472 
00503         bool coveredBy(const Geometry* g) const {
00504           return g->covers(this);
00505         }
00506 
00507 
00509         virtual std::string toString() const;
00510 
00511         virtual std::string toText() const;
00512         
00514         //
00517         virtual Geometry* buffer(double distance) const;
00518 
00523         //
00526         virtual Geometry* buffer(double distance,int quadrantSegments) const;
00527 
00564         virtual Geometry* buffer(double distance, int quadrantSegments,
00565                         int endCapStyle) const;
00566 
00570         virtual Geometry* convexHull() const;
00571 
00581         virtual Geometry* intersection(const Geometry *other) const;
00582 
00592         virtual Geometry* Union(const Geometry *other) const;
00593                 // throw(IllegalArgumentException *, TopologyException *);
00594 
00605         virtual Geometry* difference(const Geometry *other) const;
00606 
00616         virtual Geometry* symDifference(const Geometry *other) const;
00617 
00622         virtual bool equalsExact(const Geometry *other, double tolerance=0)
00623                 const=0; //Abstract
00624 
00625         virtual void apply_rw(const CoordinateFilter *filter)=0; //Abstract
00626         virtual void apply_ro(CoordinateFilter *filter) const=0; //Abstract
00627         virtual void apply_rw(GeometryFilter *filter);
00628         virtual void apply_ro(GeometryFilter *filter) const;
00629         virtual void apply_rw(GeometryComponentFilter *filter);
00630         virtual void apply_ro(GeometryComponentFilter *filter) const;
00631 
00640         virtual void apply_rw(CoordinateSequenceFilter& filter)=0;
00641 
00648         virtual void apply_ro(CoordinateSequenceFilter& filter) const=0;
00649 
00659         template <class T>
00660         void applyComponentFilter(T& f) const
00661         {
00662                 for(size_t i=0, n=getNumGeometries(); i<n; ++i)
00663                         f.filter(getGeometryN(i));
00664         }
00665 
00667         virtual void normalize()=0; //Abstract
00668 
00669         virtual int compareTo(const Geometry *geom) const;
00670 
00675         virtual double distance(const Geometry *g) const;
00676 
00678         virtual double getArea() const;
00679 
00681         virtual double getLength() const;
00682 
00687         virtual bool isWithinDistance(const Geometry *geom,double cDistance);
00688 
00698         virtual Point* getCentroid() const;
00699 
00701         //
00704         virtual bool getCentroid(Coordinate& ret) const;
00705 
00716         virtual Point* getInteriorPoint() const;
00717 
00718         /*
00719          * \brief
00720          * Notifies this Geometry that its Coordinates have been changed
00721          * by an external party (using a CoordinateFilter, for example).
00722          */
00723         virtual void geometryChanged();
00724 
00730         void geometryChangedAction();
00731 
00732 protected:
00733 
00735         mutable std::auto_ptr<Envelope> envelope;
00736         
00738         static bool hasNonEmptyElements(const std::vector<Geometry *>* geometries);
00739 
00741         static bool hasNullElements(const CoordinateSequence* list);
00742 
00744         static bool hasNullElements(const std::vector<Geometry *>* lrs);
00745 
00746 //      static void reversePointOrder(CoordinateSequence* coordinates);
00747 //      static Coordinate& minCoordinate(CoordinateSequence* coordinates);
00748 //      static void scroll(CoordinateSequence* coordinates,Coordinate* firstCoordinate);
00749 //      static int indexOf(Coordinate* coordinate,CoordinateSequence* coordinates);
00750 //
00755         virtual bool isEquivalentClass(const Geometry *other) const;
00756 
00757         static void checkNotGeometryCollection(const Geometry *g);
00758                         // throw(IllegalArgumentException *);
00759 
00760         //virtual void checkEqualSRID(Geometry *other);
00761 
00762         //virtual void checkEqualPrecisionModel(Geometry *other);
00763 
00764         virtual Envelope::AutoPtr computeEnvelopeInternal() const=0; //Abstract
00765 
00766         virtual int compareToSameClass(const Geometry *geom) const=0; //Abstract
00767 
00768         int compare(std::vector<Coordinate> a, std::vector<Coordinate> b) const;
00769 
00770         int compare(std::vector<Geometry *> a, std::vector<Geometry *> b) const;
00771 
00772         bool equal(const Coordinate& a, const Coordinate& b,
00773                         double tolerance) const;
00774         int SRID;
00775 
00777         //Geometry* toInternalGeometry(const Geometry *g) const;
00778 
00780         //Geometry* fromInternalGeometry(const Geometry *g) const;
00781 
00783         //virtual bool isRectangle() const { return false; } -- moved to public
00784 
00785         Geometry(const Geometry &geom);
00786 
00796         Geometry(const GeometryFactory *factory);
00797 
00798 private:
00799 
00800 
00801 
00802         int getClassSortIndex() const;
00803 
00804         class GeometryChangedFilter : public GeometryComponentFilter
00805         {
00806         public:
00807                 void filter_rw(Geometry* geom)
00808                 {
00809                         geom->geometryChangedAction();
00810                 }
00811         };
00812 
00813         static GeometryChangedFilter geometryChangedFilter;
00814 
00816         //
00819         const GeometryFactory *factory;
00820 
00821         static const GeometryFactory* INTERNAL_GEOMETRY_FACTORY;
00822 
00823         void* userData;
00824 };
00825 
00830 std::ostream& operator<< (std::ostream& os, const Geometry& geom);
00831 
00832 struct GEOS_DLL GeometryGreaterThen {
00833         bool operator()(const Geometry *first, const Geometry *second);
00834 };
00835 
00836 
00838 std::string geosversion();
00839 
00845 std::string jtsport();
00846 
00847 
00848 } // namespace geos::geom
00849 } // namespace geos
00850 
00851 #ifdef GEOS_INLINE
00852 # include <geos/geom/Geometry.inl>
00853 #endif
00854 
00855 #endif // ndef GEOS_GEOM_GEOMETRY_H
00856 
00857 /**********************************************************************
00858  * $Log$
00859  * Revision 1.14  2006/07/08 00:33:55  strk
00860  *         * configure.in: incremented CAPI minor version, to avoid                        falling behind any future version from the 2.2. branch.
00861  *         * source/geom/Geometry.cpp, source/geom/GeometryFactory.cpp,
00862  *         source/geomgraph/EdgeRing.cpp,
00863  *         source/headers/geos/geom/Geometry.h,
00864  *         source/headers/geos/geom/GeometryFactory.h,
00865  *         source/headers/geos/geom/GeometryFactory.inl,
00866  *         source/headers/geos/geomgraph/EdgeRing.h:
00867  *         updated doxygen comments (sync with JTS head).
00868  *         * source/headers/geos/platform.h.in: include <inttypes.h>
00869  *         rather then <stdint.h>
00870  *
00871  * Revision 1.13  2006/06/12 10:10:39  strk
00872  * Fixed getGeometryN() to take size_t rather then int, changed unsigned int parameters to size_t.
00873  *
00874  * Revision 1.12  2006/05/18 08:56:50  strk
00875  *         * source/geom/Geometry.cpp,
00876  *         source/headers/geos/geom/Geometry.h: added
00877  *         covers() and isCoveredBy() predicates.
00878  *         * tests/unit/Makefile.am,
00879  *         tests/unit/geom/Geometry/coversTest.cpp:
00880  *         added test for covers() predicates.
00881  *
00882  * Revision 1.11  2006/05/04 15:49:39  strk
00883  * updated all Geometry::getDimension() methods to return Dimension::DimensionType (closes bug#93)
00884  *
00885  * Revision 1.10  2006/04/28 10:55:39  strk
00886  * Geometry constructors made protected, to ensure all constructions use GeometryFactory,
00887  * which has been made friend of all Geometry derivates. getNumPoints() changed to return
00888  * size_t.
00889  *
00890  * Revision 1.9  2006/04/11 09:31:47  strk
00891  * Added Geometry::AutoPtr typedef
00892  *
00893  * Revision 1.8  2006/04/10 18:15:09  strk
00894  * Changed Geometry::envelope member to be of type auto_ptr<Envelope>.
00895  * Changed computeEnvelopeInternal() signater to return auto_ptr<Envelope>
00896  *
00897  * Revision 1.7  2006/04/07 09:54:30  strk
00898  * Geometry::getNumGeometries() changed to return 'unsigned int'
00899  * rather then 'int'
00900  *
00901  * Revision 1.6  2006/03/31 16:53:53  strk
00902  * Added comment about possible NULL return from getCoordinate()
00903  *
00904  * Revision 1.5  2006/03/24 09:52:41  strk
00905  * USE_INLINE => GEOS_INLINE
00906  *
00907  * Revision 1.4  2006/03/23 15:10:29  strk
00908  * Dropped by-pointer TopologyException constructor, various small cleanups
00909  *
00910  * Revision 1.3  2006/03/23 12:12:01  strk
00911  * Fixes to allow build with -DGEOS_INLINE
00912  *
00913  * Revision 1.2  2006/03/20 12:03:25  strk
00914  * Added operator<< for Geometry, writing HEXWKB
00915  *
00916  * Revision 1.1  2006/03/09 16:46:49  strk
00917  * geos::geom namespace definition, first pass at headers split
00918  *
00919  **********************************************************************/

Generated on Thu Jun 11 06:17:01 2009 for GEOS by  doxygen 1.4.4