geom.h

00001 /**********************************************************************
00002  * $Id: geom.h,v 1.34.2.2.2.5 2006/04/28 18:39:57 sgillies Exp $
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 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 #ifndef GEOS_GEOM_H
00018 #define GEOS_GEOM_H
00019 
00020 #include <memory>
00021 #include <iostream>
00022 #include <string>
00023 #include <vector>
00024 #include <algorithm>
00025 #include <map>
00026 #include <cmath>
00027 #include <geos/platform.h>
00028 
00029 using namespace std;
00030 
00034 namespace geos {
00035 
00037 string geosversion();
00038 
00044 string jtsport();
00045 
00047 enum GeometryTypeId {
00049         GEOS_POINT,
00051         GEOS_LINESTRING,
00053         GEOS_LINEARRING,
00055         GEOS_POLYGON,
00057         GEOS_MULTIPOINT,
00059         GEOS_MULTILINESTRING,
00061         GEOS_MULTIPOLYGON,
00063         GEOS_GEOMETRYCOLLECTION
00064 };
00065 
00066 class Coordinate;
00067 
00109 class PrecisionModel {
00110 friend class Unload;
00111 public:
00113         /*
00114         * This class is only for use to support the "enums"
00115         * for the types of precision model.
00116         */
00117         typedef enum {
00118 
00125                 FIXED,
00126 
00132                 FLOATING,
00133 
00139                 FLOATING_SINGLE
00140 
00141         } Type;
00142         
00144         PrecisionModel(void);
00145 
00147 
00152         PrecisionModel(Type nModelType);
00153 
00154         /*
00155          * Creates a <code>PrecisionModel</code> with Fixed precision.
00156          *
00157          * Fixed-precision coordinates are represented as precise internal
00158          * coordinates, which are rounded to the grid defined by the
00159          * scale factor.
00160          *
00161          * @param  scale
00162          *      amount by which to multiply a coordinate after subtracting
00163          *      the offset, to obtain a precise coordinate
00164          * @param  offsetX  not used.
00165          * @param  offsetY  not used.
00166          *
00167          * @deprecated offsets are no longer supported, since internal
00168          * representation is rounded floating point
00169          */
00170         PrecisionModel(double newScale, double newOffsetX, double newOffsetY);
00171 
00183         PrecisionModel(double newScale);
00184 
00185         // copy constructor
00186         PrecisionModel(const PrecisionModel &pm);
00187 
00189         virtual ~PrecisionModel(void);
00190 
00191 
00193 
00198         static const double maximumPreciseValue;
00199 
00201         double makePrecise(double val) const;
00202 
00204         void makePrecise(Coordinate *coord) const;
00205 
00207 
00211         bool isFloating() const;
00212 
00214 
00219         int getMaximumSignificantDigits() const;
00220 
00222 
00225         Type getType() const;
00226 
00228         double getScale() const;
00229 
00230         /*
00231         * Returns the x-offset used to obtain a precise coordinate.
00232         *
00233         * @return the amount by which to subtract the x-coordinate before
00234         *         multiplying by the scale
00235         * @deprecated Offsets are no longer used
00236         */
00237         double getOffsetX() const;
00238 
00239         /*
00240         * Returns the y-offset used to obtain a precise coordinate.
00241         *
00242         * @return the amount by which to subtract the y-coordinate before
00243         *         multiplying by the scale
00244         * @deprecated Offsets are no longer used
00245         */
00246         double getOffsetY() const;
00247 
00248         /*
00249          *  Sets <code>internal</code> to the precise representation of <code>external</code>.
00250          *
00251          * @param external the original coordinate
00252          * @param internal the coordinate whose values will be changed to the
00253          *                 precise representation of <code>external</code>
00254          * @deprecated use makePrecise instead
00255          */
00256         void toInternal(const Coordinate& external, Coordinate* internal) const;
00257 
00258         /*
00259         *  Returns the precise representation of <code>external</code>.
00260         *
00261         *@param  external  the original coordinate
00262         *@return
00263         *       the coordinate whose values will be changed to the precise
00264         *       representation of <code>external</code>
00265         * @deprecated use makePrecise instead
00266         */
00267         Coordinate* toInternal(const Coordinate& external) const;
00268 
00269         /*
00270         *  Returns the external representation of <code>internal</code>.
00271         *
00272         *@param  internal  the original coordinate
00273         *@return           the coordinate whose values will be changed to the
00274         *      external representation of <code>internal</code>
00275         * @deprecated no longer needed, since internal representation is same as external representation
00276         */
00277         Coordinate* toExternal(const Coordinate& internal) const;
00278 
00279         /*
00280         *  Sets <code>external</code> to the external representation of
00281         *  <code>internal</code>.
00282         *
00283         * @param  internal  the original coordinate
00284         * @param  external
00285         *       the coordinate whose values will be changed to the
00286         *       external representation of <code>internal</code>
00287         * @deprecated no longer needed, since internal representation is same as external representation
00288         */
00289         void toExternal(const Coordinate& internal, Coordinate* external) const;
00290 
00291         string toString() const;
00292 
00294 
00308         int compareTo(const PrecisionModel* other) const;
00309 
00310 private:
00311         void setScale(double newScale);
00312         Type modelType;
00313         double scale;
00314 #ifdef INT64_CONST_IS_I64
00315         static const int64 serialVersionUID = 7777263578777803835I64;
00316 #else        
00317         static const int64 serialVersionUID = 7777263578777803835LL;
00318 #endif        
00319 };
00320 
00341 // Define the following to make assignments and copy constructions
00342 // NON-inline (will let profilers report usages)
00343 //#define PROFILE_COORDINATE_COPIES 1
00344 class Coordinate {
00345 public:
00346         //void setNull(void);
00347         //static Coordinate& getNull(void);
00348         virtual ~Coordinate(){};
00349         //Coordinate(double xNew, double yNew, double zNew);
00350         //Coordinate(const Coordinate& c);
00351         //Coordinate(double xNew, double yNew);
00352         //void setCoordinate(Coordinate& other);
00353         //bool equals2D(Coordinate& other);
00354         //int compareTo(Coordinate& other);
00355         //bool equals3D(Coordinate& other);
00356         string toString() const;
00357         //void makePrecise();
00358         //double distance(Coordinate& p);
00359         static Coordinate nullCoord;
00360 
00361         void setNull() {
00362                 x=DoubleNotANumber;
00363                 y=DoubleNotANumber;
00364                 z=DoubleNotANumber;
00365         }
00366 
00367         static Coordinate& getNull() {
00368                 return nullCoord;
00369         }
00370 
00371         Coordinate() {
00372                 x=0.0;
00373                 y=0.0;
00374                 z=DoubleNotANumber;
00375         }
00376 
00377         Coordinate(double xNew, double yNew, double zNew) {
00378                 x=xNew;
00379                 y=yNew;
00380                 z=zNew;
00381         }
00382 
00383 #ifndef PROFILE_COORDINATE_COPIES
00384         Coordinate(const Coordinate& c){
00385                 x=c.x;
00386                 y=c.y;
00387                 z=c.z;
00388         }
00389 #else
00390         Coordinate(const Coordinate& c);
00391         Coordinate &operator=(const Coordinate &c);
00392 #endif
00393 
00394         Coordinate(double xNew, double yNew){
00395                 x=xNew;
00396                 y=yNew;
00397                 z=DoubleNotANumber;
00398         }
00399 
00400         void setCoordinate(const Coordinate& other) {
00401                 x = other.x;
00402                 y = other.y;
00403                 z = other.z;
00404         }
00405 
00406         bool equals2D(const Coordinate& other) const {
00407                 if (x != other.x) {
00408                 return false;
00409                 }
00410                 if (y != other.y) {
00411                 return false;
00412                 }
00413                 return true;
00414         }
00415 
00416         int compareTo(const Coordinate& other) const {
00417                 if (x < other.x) {
00418                 return -1;
00419                 }
00420                 if (x > other.x) {
00421                 return 1;
00422                 }
00423                 if (y < other.y) {
00424                 return -1;
00425                 }
00426                 if (y > other.y) {
00427                 return 1;
00428                 }
00429                 return 0;
00430         }
00431 
00432         bool equals3D(const Coordinate& other) const {
00433                 return (x == other.x) && ( y == other.y) && ((z == other.z)||(ISNAN(z) && ISNAN(other.z)));
00434         }
00435 
00436         void makePrecise(const PrecisionModel *precisionModel) {
00437                 x = precisionModel->makePrecise(x);
00438                 y = precisionModel->makePrecise(y);
00439         }
00440 
00441         double distance(const Coordinate& p) const {
00442                 double dx = x - p.x;
00443                 double dy = y - p.y;
00444                 return sqrt(dx * dx + dy * dy);
00445         }
00446 
00447         int hashCode() {
00448                 //Algorithm from Effective Java by Joshua Bloch [Jon Aquino]
00449                 int result = 17;
00450                 result = 37 * result + hashCode(x);
00451                 result = 37 * result + hashCode(y);
00452                 return result;
00453         }
00454 
00459         static int hashCode(double x) {
00460                 int64 f = (int64)(x);
00461                 return (int)(f^(f>>32));
00462         }
00463 
00464 
00466         double x;
00468         double y;
00470         double z;
00471 
00472 private:
00473 #ifdef INT64_CONST_IS_I64
00474         static const int64 serialVersionUID=6683108902428366910I64;
00475 #else
00476         static const int64 serialVersionUID=6683108902428366910LL;
00477 #endif
00478 
00479 };
00480 
00481 
00482 //* class CoordinateList geom.h geos.h
00483 //*
00484 //* brief A list of Coordinates, which may be set to prevent
00485 //* repeated coordinates from occuring in the list.
00486 //
00487 //class CoordinateList {
00488 //public:
00489 //      ~CoordinateList(){};
00490 //
00491 //      // copy constructor
00492 //      CoordinateList(const CoordinateList &cl);
00493 //
00494 //      // constructor an empty CoordinateList
00495 //      CoordinateList();
00496 //
00497 //      /*
00498 //       * Constructs a new list from a vector of Coordinates.
00499 //       * Caller can specify if repeated points are to be removed.
00500 //       * Default is allowing repeated points.
00501 //       * Will take ownership of coords.
00502 //       */
00503 //      CoordinateList(vector<Coordinate> *coords, bool allowRepeted=false);
00504 //
00505 //      // Get a reference to the nth Coordinate 
00506 //      const Coordinate& getCoordinate(int n) const;
00507 //
00508 //      /*
00509 //       * \brief Add an array of coordinates 
00510 //       * @param vc The coordinates
00511 //       * @param allowRepeated if set to false, repeated coordinates
00512 //       *      are collapsed
00513 //       * @return true (as by general collection contract)
00514 //       */
00515 //      void add(vector<Coordinate>* vc, bool allowRepeated);
00516 //
00517 //      /*
00518 //       * \brief Add an array of coordinates 
00519 //       * @param cl The coordinates
00520 //       * @param allowRepeated if set to false, repeated coordinates
00521 //       * are collapsed
00522 //       * @param direction if false, the array is added in reverse order
00523 //       * @return true (as by general collection contract)
00524 //       */
00525 //      void add(CoordinateList *cl,bool allowRepeated,bool direction);
00526 //
00527 //      /*
00528 //       * \brief Add a coordinate
00529 //       * @param c The coordinate to add
00530 //       * @param allowRepeated if set to false, repeated coordinates
00531 //       * are collapsed
00532 //       * @return true (as by general collection contract)
00533 //       */
00534 //      void add(const Coordinate& c,bool allowRepeated);
00535 //
00536 //      // Add a Coordinate to the list
00537 //      void add(const Coordinate& c);
00538 //
00539 //      // Get vector
00540 //      const vector<Coordinate>* toCoordinateArray() const;
00541 //
00542 //private:
00543 //
00544 //      vector<Coordinate> *vect;
00545 //};
00546 
00566 class CoordinateSequence {
00567 public:
00568         virtual ~CoordinateSequence(){};
00569 
00573         virtual CoordinateSequence *clone() const=0;
00574 
00581         //virtual const Coordinate& getCoordinate(int i) const=0;
00582         virtual const Coordinate& getAt(int i) const=0;
00583 
00588         //virtual int size() const=0;
00589         virtual int getSize() const=0;
00590 
00600         virtual const vector<Coordinate>* toVector() const=0;
00601 
00609         void add(const vector<Coordinate>* vc, bool allowRepeated);
00610 
00611         /* This is here for backward compatibility.. */
00612         void add(CoordinateSequence *cl,bool allowRepeated,bool direction);
00613 
00622         void add(const CoordinateSequence *cl,bool allowRepeated,bool direction);
00623 
00631         void add(const Coordinate& c,bool allowRepeated);
00632 
00634         virtual bool isEmpty() const=0;
00635 
00637         virtual void add(const Coordinate& c)=0;
00638 
00639         // Get number of coordinates
00640         //virtual int getSize() const=0;
00641 
00643         //virtual       const Coordinate& getAt(int pos) const=0;
00644 
00646         virtual void setAt(const Coordinate& c, int pos)=0;
00647 
00649         virtual void deleteAt(int pos)=0;
00650 
00652         virtual string toString() const=0;
00653 
00655         virtual void setPoints(const vector<Coordinate> &v)=0;
00656         
00658         bool hasRepeatedPoints() const;
00659 
00661         const Coordinate* minCoordinate() const;
00662 
00663 
00665         static CoordinateSequence* removeRepeatedPoints(const CoordinateSequence *cl);
00666 
00671         static bool hasRepeatedPoints(const CoordinateSequence *cl);
00672 
00677         static CoordinateSequence* atLeastNCoordinatesOrNothing(int n, CoordinateSequence *c);
00678 
00684         static const Coordinate* minCoordinate(CoordinateSequence *cl);
00685 
00687         static int indexOf(const Coordinate *coordinate, const CoordinateSequence *cl);
00693         static bool equals(CoordinateSequence *cl1, CoordinateSequence *cl2);
00694 
00696         static void scroll(CoordinateSequence *cl, const Coordinate *firstCoordinate);
00697 
00699         static void reverse(CoordinateSequence *cl);
00700 
00702         virtual unsigned int getDimension() const=0;
00703 
00704         virtual double getOrdinate(unsigned int index, unsigned int ordinateIndex) const=0;
00705 
00706         virtual void setOrdinate(unsigned int index, unsigned int ordinateIndex, double value)=0;
00707 
00709         enum { X,Y,Z,M };
00710 
00711         double getX(unsigned int index) const { return getOrdinate(index, X); }
00712         double getY(unsigned int index) const { return getOrdinate(index, Y); }
00713         double getZ(unsigned int index) const { return getOrdinate(index, Z); }
00714 };
00715 
00721 class DefaultCoordinateSequence : public CoordinateSequence {
00722 public:
00723 
00724         DefaultCoordinateSequence(const DefaultCoordinateSequence &cl);
00725 
00726         CoordinateSequence *clone() const;
00727 
00728         //const Coordinate& getCoordinate(int pos) const;
00729         const Coordinate& getAt(int pos) const;
00730 
00731         //int size() const;
00732         int getSize() const;
00733         const vector<Coordinate>* toVector() const;
00734 
00736         DefaultCoordinateSequence();
00737 
00739         DefaultCoordinateSequence(vector<Coordinate> *coords);
00740 
00742         DefaultCoordinateSequence(int n);
00743 
00744         virtual ~DefaultCoordinateSequence();
00745 
00746         bool isEmpty() const;
00747         void add(const Coordinate& c);
00748         void setAt(const Coordinate& c, int pos);
00749         void deleteAt(int pos);
00750         string toString() const;
00751         void setPoints(const vector<Coordinate> &v);
00752 private:
00753         vector<Coordinate> *vect;
00754 
00755 public:
00756         unsigned int getDimension() const { return 3; }
00757         void setOrdinate(unsigned int index, unsigned int ordinateIndex, double value);
00758         double getOrdinate(unsigned int index, unsigned int ordinateIndex) const;
00759 };
00760 
00761 struct point_3d {
00762         double x;
00763         double y;
00764         double z;
00765 };
00766 
00767 class PointCoordinateSequence : public CoordinateSequence {
00768 public:
00769         PointCoordinateSequence();
00770         PointCoordinateSequence(int n);
00771         PointCoordinateSequence(const Coordinate& c);
00772         PointCoordinateSequence(const PointCoordinateSequence &cl);
00773         PointCoordinateSequence(const CoordinateSequence *c);
00774         virtual ~PointCoordinateSequence();
00775         CoordinateSequence *clone() const;
00776         bool isEmpty() const;
00777         void add(const Coordinate& c);
00778         void add(point_3d p);
00779         int getSize() const;
00780         const Coordinate& getAt(int pos) const;
00781         point_3d getPointAt(int pos);
00782         void setAt(const Coordinate& c, int pos);
00783         void setAt(point_3d p, int pos);
00784         void deleteAt(int pos);
00785         const vector<Coordinate>* toVector() const;
00786         vector<point_3d>* toPointVector();
00787         string toString() const;
00788         void setPoints(const vector<Coordinate> &v);
00789         void setPoints(vector<point_3d> &v);
00790 private:
00791         vector<point_3d> *vect;
00792         mutable vector<Coordinate>*cached_vector;
00793 public:
00794         unsigned int getDimension() const { return 3; }
00795         void setOrdinate(unsigned int index, unsigned int ordinateIndex, double value);
00796         double getOrdinate(unsigned int index, unsigned int ordinateIndex) const;
00797 };
00798 
00806 class CoordinateSequenceFactory {
00807 public:
00808         // create an empty CoordinateSequence
00809         //virtual CoordinateSequence* createCoordinateSequence()=0;
00810 
00811         // create an empty CoordinateSequence with 'size' Coordinate slots
00812         //virtual CoordinateSequence* createCoordinateSequence(int size)=0;
00813 
00814         //virtual CoordinateSequence* createCoordinateSequence(const Coordinate& c)=0;
00815         // create an CoordinateSequence containing the given Coordinate 
00816         //virtual CoordinateSequence* createCoordinateSequence(const CoordinateSequence *c)=0;
00817 
00827         virtual CoordinateSequence *create(vector<Coordinate> *coordinates) const=0;
00828 
00829         virtual CoordinateSequence *create(unsigned int size, unsigned int dims) const=0;
00830 };
00831 
00839 class DefaultCoordinateSequenceFactory: public CoordinateSequenceFactory {
00840 
00841 public:
00842         // create an empty DefaultCoordinateSequence
00843         //CoordinateSequence *createCoordinateSequence() {return new DefaultCoordinateSequence();};
00844         // create an empty DefaultCoordinateSequence with 'size' Coordinate slots
00845         //CoordinateSequence* createCoordinateSequence(int size) {return new DefaultCoordinateSequence(size);};
00846         //CoordinateSequence* createCoordinateSequence(const Coordinate& c) {return new DefaultCoordinateSequence(c);};
00847 
00848         // create an DefaultCoordinateSequence containing the given Coordinate 
00849         //CoordinateSequence* createCoordinateSequence(const CoordinateSequence *cl) {return new DefaultCoordinateSequence(cl);};
00850 
00851 
00856         CoordinateSequence *create(vector<Coordinate> *coords) const;
00857 
00861         static const CoordinateSequenceFactory *instance();
00862 
00863         CoordinateSequence *create(unsigned int size, unsigned int dims) const;
00864 };
00865 
00866 /*
00867  * \class PointCoordinateSequenceFactory geom.h geos.h
00868  *
00869  * \brief
00870  * Factory for PointCoordinateSequence objects.
00871  */
00872 class PointCoordinateSequenceFactory: public CoordinateSequenceFactory {
00873 public:
00874 
00875         CoordinateSequence *create(vector<Coordinate> *coords) const;
00876         CoordinateSequence *create(unsigned int size, unsigned int dims) const;
00877 };
00878 
00879 /*
00880  * <code>Geometry</code> classes support the concept of applying a
00881  * coordinate filter to every coordinate in the <code>Geometry</code>. A
00882  * coordinate filter can either record information about each coordinate or
00883  * change the coordinate in some way. Coordinate filters implement the
00884  * interface <code>CoordinateFilter</code>. (<code>CoordinateFilter</code> is
00885  * an example of the Gang-of-Four Visitor pattern). Coordinate filters can be
00886  * used to implement such things as coordinate transformations, centroid and
00887  * envelope computation, and many other functions.
00888  *
00889  */
00890 class CoordinateFilter {
00891 public:
00892    virtual ~CoordinateFilter() {}
00898    virtual void filter_rw(Coordinate* coord)=0;
00899    virtual void filter_ro(const Coordinate* coord)=0;
00900 };
00901 
00902 class Geometry;
00903 
00904 /*
00905  *  <code>Geometry</code> classes support the concept of applying
00906  *  a <code>GeometryComponentFilter</code>
00907  *  filter to the <code>Geometry</code>.
00908  *  The filter is applied to every component of the <code>Geometry</code>
00909  *  which is itself a <code>Geometry</code>.
00910  *  A <code>GeometryComponentFilter</code> filter can either
00911  *  record information about the <code>Geometry</code>
00912  *  or change the <code>Geometry</code> in some way.
00913  *  <code>GeometryComponentFilter</code>
00914  *  is an example of the Gang-of-Four Visitor pattern.
00915  *
00916  */
00917 class GeometryComponentFilter {
00918 public:
00924 //      virtual void filter(Geometry *geom)=0;
00925         virtual void filter_rw(Geometry *geom);
00926         virtual void filter_ro(const Geometry *geom); // Unsupported
00927 };
00928 
00929 
00930 /*
00931  * Constants representing the dimensions of a point, a curve and a surface.
00932  * Also, constants representing the dimensions of the empty geometry and
00933  * non-empty geometries, and a wildcard dimension meaning "any dimension".
00934  * 
00935  */
00936 class Dimension {
00937 public:
00938         enum {
00939                 DONTCARE=-3,    
00940                 True,                   
00941                 False,                  
00942                 P,                              
00943                 L,                              
00944                 A                               
00945         };
00946         //static const int P = 0;                       /// Dimension value of a point (0).
00947         //static const int L = 1;                       /// Dimension value of a curve (1).
00948         //static const int A = 2;                       /// Dimension value of a surface (2).
00949         //static const int False = -1;  /// Dimension value of the empty geometry (-1).
00950         //static const int True = -2;           /// Dimension value of non-empty geometries (= {P, L, A}).
00951         //static const int DONTCARE = -3;       /// Dimension value for any dimension (= {FALSE, TRUE}).
00952         static char toDimensionSymbol(int dimensionValue);
00953         static int toDimensionValue(char dimensionSymbol);
00954 };
00955 
00973 class Envelope {
00974 public:
00975         Envelope(void);
00976         Envelope(double x1, double x2, double y1, double y2);
00977         Envelope(const Coordinate& p1, const Coordinate& p2);
00978         Envelope(const Coordinate& p);
00979         Envelope(const Envelope &env);
00980         virtual ~Envelope(void);
00981         static bool intersects(const Coordinate& p1,const Coordinate& p2,const Coordinate& q);
00982         static bool intersects(const Coordinate& p1,const Coordinate& p2,const Coordinate& q1,const Coordinate& q2);
00983         void init(void);
00984         void init(double x1, double x2, double y1, double y2);
00985         void init(const Coordinate& p1, const Coordinate& p2);
00986         void init(const Coordinate& p);
00987         void init(Envelope env);
00988         void setToNull(void);
00989         bool isNull(void) const;
00990         double getWidth(void) const;
00991         double getHeight(void) const;
00992         double getMaxY() const;
00993         double getMaxX() const;
00994         double getMinY() const;
00995         double getMinX() const;
00996         void expandToInclude(const Coordinate& p);
00997         void expandToInclude(double x, double y);
00998         void expandToInclude(const Envelope* other);
00999         bool contains(const Coordinate& p) const;
01000         bool contains(double x, double y) const;
01001         bool contains(const Envelope* other) const;
01002         bool overlaps(const Coordinate& p) const;
01003         bool overlaps(double x, double y) const;
01004         bool overlaps(const Envelope* other) const;
01005         bool intersects(const Coordinate& p) const;
01006         bool intersects(double x, double y) const;
01007         bool intersects(const Envelope* other) const;
01008         bool equals(const Envelope* other) const;
01009         string toString(void) const;
01010         double distance(const Envelope* env) const;
01011         int hashCode() const;
01012 
01013 private:
01014         static double distance(double x0,double y0,double x1,double y1);
01015         double minx;    
01016         double maxx;    
01017         double miny;    
01018         double maxy;    
01019 #ifdef INT64_CONST_IS_I64
01020         static const int64 serialVersionUID=5873921885273102420I64;
01021 #else        
01022         static const int64 serialVersionUID=5873921885273102420LL;
01023 #endif        
01024 };
01025 
01026 class Geometry;
01027 class GeometryFilter;
01028 class IntersectionMatrix;
01029 
01030 
01031 class CGAlgorithms;
01032 class Point;
01033 class GeometryFactory;
01034 
01118 class Geometry{
01119 friend class Unload;
01120 public:
01121 
01122         Geometry(const Geometry &geom);
01123 
01130         Geometry(const GeometryFactory *factory);
01131 
01133         virtual ~Geometry();
01134 
01136         virtual Geometry* clone() const=0;
01137 
01145         const GeometryFactory* getFactory() const;
01146 
01160         void setUserData(void* newUserData);
01161 
01168         void* getUserData();
01169 
01170         /*
01171          * \brief
01172          * Returns the ID of the Spatial Reference System used by the
01173          * <code>Geometry</code>.
01174          *
01175          * GEOS supports Spatial Reference System information in the simple way
01176          * defined in the SFS. A Spatial Reference System ID (SRID) is present
01177          * in each <code>Geometry</code> object. <code>Geometry</code>
01178          * provides basic accessor operations for this field, but no others.
01179          * The SRID is represented as an integer.
01180          *
01181          * @return the ID of the coordinate space in which the
01182          * <code>Geometry</code> is defined.
01183          *
01184          * @deprecated use getUserData instead
01185          */
01186         virtual int getSRID() const;
01187 
01188         /*
01189          * Sets the ID of the Spatial Reference System used by the
01190          * <code>Geometry</code>.
01191          * @deprecated use setUserData instead
01192          */
01193         virtual void setSRID(int newSRID);
01194 
01199         virtual const PrecisionModel* getPrecisionModel() const;
01200 
01202         virtual const Coordinate* getCoordinate() const=0; //Abstract
01203 
01209         virtual CoordinateSequence* getCoordinates() const=0; //Abstract
01210 
01212         virtual int getNumPoints() const=0; //Abstract
01213 
01215         virtual bool isSimple() const=0; //Abstract
01216 
01218         virtual string getGeometryType() const=0; //Abstract
01219 
01221         virtual GeometryTypeId getGeometryTypeId() const=0; //Abstract
01222 
01232         virtual bool isValid() const;
01233 
01235         virtual bool isEmpty() const=0; //Abstract
01236 
01238         virtual int getDimension() const=0; //Abstract
01239 
01245         virtual Geometry* getBoundary() const=0; //Abstract
01246 
01248         virtual int getBoundaryDimension() const=0; //Abstract
01249 
01251         virtual Geometry* getEnvelope() const;
01252 
01257         virtual const Envelope* getEnvelopeInternal() const;
01258 
01264         virtual bool disjoint(const Geometry *other) const;
01265 
01270         virtual bool touches(const Geometry *other) const;
01271 
01273         virtual bool intersects(const Geometry *g) const;
01274 
01281         virtual bool crosses(const Geometry *g) const;
01282 
01287         virtual bool within(const Geometry *g) const;
01288 
01290         virtual bool contains(const Geometry *g) const;
01291 
01297         virtual bool overlaps(const Geometry *g) const;
01298 
01310         virtual bool relate(const Geometry *g, string intersectionPattern) const;
01312         virtual IntersectionMatrix* relate(const Geometry *g) const;
01313 
01319         virtual bool equals(const Geometry *g) const;
01320 
01322         virtual string toString() const;
01323 
01324         virtual string toText() const;
01325         
01327         virtual Geometry* buffer(double distance) const;
01328 
01330         virtual Geometry* buffer(double distance,int quadrantSegments) const;
01331 
01333         virtual Geometry* convexHull() const;
01334 
01339         virtual Geometry* intersection(const Geometry *other) const;
01340 
01345         virtual Geometry* Union(const Geometry *other) const;
01346                 // throw(IllegalArgumentException *, TopologyException *);
01347 
01353         virtual Geometry* difference(const Geometry *other) const;
01354 
01359         virtual Geometry* symDifference(const Geometry *other) const;
01360 
01365         virtual bool equalsExact(const Geometry *other, double tolerance)
01366                 const=0; //Abstract
01367 
01368         virtual void apply_rw(CoordinateFilter *filter)=0; //Abstract
01369         virtual void apply_ro(CoordinateFilter *filter) const=0; //Abstract
01370         virtual void apply_rw(GeometryFilter *filter);
01371         virtual void apply_ro(GeometryFilter *filter) const;
01372         virtual void apply_rw(GeometryComponentFilter *filter);
01373         virtual void apply_ro(GeometryComponentFilter *filter) const;
01374 
01376         virtual void normalize()=0; //Abstract
01377 
01378         virtual int compareTo(const Geometry *geom) const;
01379 
01384         virtual double distance(const Geometry *g) const;
01385 
01387         virtual double getArea() const;
01388 
01390         virtual double getLength() const;
01391 
01396         virtual bool isWithinDistance(const Geometry *geom,double cDistance);
01397 
01399         virtual Point* getCentroid() const;
01400 
01402         virtual Point* getInteriorPoint();
01403 
01404         /*
01405          * \brief
01406          * Notifies this Geometry that its Coordinates have been changed
01407          * by an external party (using a CoordinateFilter, for example).
01408          */
01409         virtual void geometryChanged();
01410 
01411         /*
01412          * \brief
01413          * Notifies this Geometry that its Coordinates have been changed
01414          * by an external party.
01415          */
01416         void geometryChangedAction();
01417 
01418 protected:
01419         mutable Envelope* envelope;
01420         
01422         static bool hasNonEmptyElements(const vector<Geometry *>* geometries);
01423 
01425         static bool hasNullElements(const CoordinateSequence* list);
01426 
01428         static bool hasNullElements(const vector<Geometry *>* lrs);
01429 
01430 //      static void reversePointOrder(CoordinateSequence* coordinates);
01431 //      static Coordinate& minCoordinate(CoordinateSequence* coordinates);
01432 //      static void scroll(CoordinateSequence* coordinates,Coordinate* firstCoordinate);
01433 //      static int indexOf(Coordinate* coordinate,CoordinateSequence* coordinates);
01434 //
01439         virtual bool isEquivalentClass(const Geometry *other) const;
01440 
01441         static void checkNotGeometryCollection(const Geometry *g); // throw(IllegalArgumentException *);
01442         //virtual void checkEqualSRID(Geometry *other);
01443         //virtual void checkEqualPrecisionModel(Geometry *other);
01444         virtual Envelope* computeEnvelopeInternal() const=0; //Abstract
01445         virtual int compareToSameClass(const Geometry *geom) const=0; //Abstract
01446         int compare(vector<Coordinate> a, vector<Coordinate> b) const;
01447         int compare(vector<Geometry *> a, vector<Geometry *> b) const;
01448         bool equal(const Coordinate& a, const Coordinate& b,double tolerance) const;
01449         int SRID;
01450 
01463         Geometry* toInternalGeometry(const Geometry *g) const;
01464         Geometry* fromInternalGeometry(const Geometry *g) const;
01465 private:
01466         virtual int getClassSortIndex() const;
01467         static GeometryComponentFilter geometryChangedFilter;
01468 #ifdef INT64_CONST_IS_I64
01469     static const int64 serialVersionUID = 8763622679187376702I64;
01470 #else
01471     static const int64 serialVersionUID = 8763622679187376702LL;
01472 #endif
01473         const GeometryFactory *factory;
01474         static const GeometryFactory* INTERNAL_GEOMETRY_FACTORY;
01475         void* userData;
01476         Point* createPointFromInternalCoord(const Coordinate* coord,const Geometry *exemplar) const;
01477 };
01478 
01479 /*
01480  * Geometry classes support the concept of applying a Geometry
01481  * filter to the Geometry. In the case of GeometryCollection
01482  * subclasses, the filter is applied to every element Geometry.
01483  * A Geometry filter can either record information about the Geometry
01484  * or change the Geometry in some way.
01485  * Geometry filters implement the interface GeometryFilter.
01486  * (GeometryFilter is an example of the Gang-of-Four Visitor pattern).
01487  */
01488 class GeometryFilter {
01489 public:
01490         /*
01491          * Performs an operation with or on <code>geom</code>.
01492          *
01493          * @param  geom  a <code>Geometry</code> to which the filter
01494          *         is applied.
01495          */
01496         virtual void filter_ro(const Geometry *geom)=0;
01497         virtual void filter_rw(Geometry *geom)=0;
01498 };
01499 
01500 /*
01501  * Represents a line segment defined by two {@link Coordinate}s.
01502  * Provides methods to compute various geometric properties
01503  * and relationships of line segments.
01504  * 
01505  * This class is designed to be easily mutable (to the extent of
01506  * having its contained points public).
01507  * This supports a common pattern of reusing a single LineSegment
01508  * object as a way of computing segment properties on the
01509  * segments defined by arrays or lists of {@link Coordinate}s.
01510  *
01511  */
01512 class LineSegment {
01513 public:
01514         Coordinate p0; 
01515         Coordinate p1; 
01516         LineSegment(void);
01517         LineSegment(const LineSegment &ls);
01518         LineSegment(const Coordinate& c0, const Coordinate& c1);
01519         virtual ~LineSegment(void);
01520         virtual void setCoordinates(const Coordinate& c0, const Coordinate& c1);
01521         virtual const Coordinate& getCoordinate(int i) const;
01522         virtual void setCoordinates(const LineSegment ls);
01523         virtual double getLength() const;
01529         virtual bool isHorizontal() const;
01535         virtual bool isVertical() const;
01555         virtual int orientationIndex(LineSegment *seg) const;
01556         virtual void reverse();
01557         virtual void normalize();
01558         virtual double angle() const;
01559         virtual double distance(const LineSegment ls) const;
01563         virtual double distance(const Coordinate& p) const;
01568         virtual double distancePerpendicular(const Coordinate& p) const;
01569         virtual double projectionFactor(const Coordinate& p) const;
01570         virtual Coordinate* project(const Coordinate& p) const;
01571         virtual LineSegment* project(const LineSegment *seg) const;
01572         virtual Coordinate* closestPoint(const Coordinate& p) const;
01573         virtual int compareTo(const LineSegment other) const;
01574         virtual bool equalsTopo(const LineSegment other) const;
01575 
01582         virtual CoordinateSequence* closestPoints(const LineSegment *line);
01583 
01595         Coordinate* intersection(const LineSegment *line) const;
01596         virtual string toString() const;
01597 private:
01598 #ifdef INT64_CONST_IS_I64
01599   static const int64 serialVersionUID=3252005833466256227I64;
01600 #else
01601   static const int64 serialVersionUID=3252005833466256227LL;
01602 #endif
01603 
01604 };
01605 
01606 class IntersectionMatrix {
01607 public:
01608         IntersectionMatrix();
01609         IntersectionMatrix(string elements);
01610         IntersectionMatrix(const IntersectionMatrix &im);
01611         virtual ~IntersectionMatrix();
01612         static bool matches(int actualDimensionValue, char requiredDimensionSymbol);
01613         static bool matches(string actualDimensionSymbols, string requiredDimensionSymbols);
01614         void add(IntersectionMatrix *im);
01615         void set(int row, int column, int dimensionValue);
01616         void set(string dimensionSymbols);
01617         void setAtLeast(int row, int column, int minimumDimensionValue);
01618         void setAtLeastIfValid(int row, int column, int minimumDimensionValue);
01619         void setAtLeast(string minimumDimensionSymbols);
01620         void setAll(int dimensionValue);
01621         int get(int row, int column);
01622         bool isDisjoint();
01623         bool isIntersects();
01624         bool isTouches(int dimensionOfGeometryA, int dimensionOfGeometryB);
01625         bool isCrosses(int dimensionOfGeometryA, int dimensionOfGeometryB);
01626         bool isWithin();
01627         bool isContains();
01628         bool isEquals(int dimensionOfGeometryA, int dimensionOfGeometryB);
01629         bool isOverlaps(int dimensionOfGeometryA, int dimensionOfGeometryB);
01630         bool matches(string requiredDimensionSymbols);
01631         IntersectionMatrix* transpose();
01632         string toString();
01633 private:
01634         int matrix[3][3];
01635 };
01636 
01637 /*
01638  *  Constants representing the location of a point relative to a geometry. They
01639  *  can also be thought of as the row or column index of a DE-9IM matrix. For a
01640  *  description of the DE-9IM, see the <A
01641  *  HREF="http://www.opengis.org/techno/specs.htm">OpenGIS Simple Features
01642  *  Specification for SQL</A> .
01643  */
01644 class Location {
01645 public:
01646         enum {
01650                 UNDEF=-1,   
01651 
01656                 INTERIOR,
01662                 BOUNDARY,
01668                 EXTERIOR = 2
01669         };
01670         //static const int INTERIOR = 0;
01671         //static const int BOUNDARY = 1;
01672         //static const int EXTERIOR = 2;
01673         //static const int UNDEF = -1;   ///Instead of NULL
01674         static char toLocationSymbol(int locationValue);
01675 };
01676 
01677 
01678 //Operators
01679 bool operator==(const Coordinate& a, const Coordinate& b);
01680 bool operator!=(const Coordinate& a, const Coordinate& b);
01681 bool operator==(const Envelope a, const Envelope b);
01682 bool operator==(const PrecisionModel a, const PrecisionModel b);
01683 bool operator==(const LineSegment a, const LineSegment b);
01684 
01685 bool lessThen(Coordinate& a,Coordinate& b);
01686 bool greaterThen(Geometry *first, Geometry *second);
01687 
01697 class GeometryCollection : public Geometry{
01698 public:
01699         GeometryCollection(const GeometryCollection &gc);
01700 
01725         GeometryCollection(vector<Geometry *> *newGeoms, const GeometryFactory *newFactory);
01726 
01727         virtual Geometry *clone() const;
01728 
01729         virtual ~GeometryCollection();
01730 
01744         virtual CoordinateSequence* getCoordinates() const;
01745 
01746         virtual bool isEmpty() const;
01747 
01753         virtual int getDimension() const;
01754 
01755         virtual Geometry* getBoundary() const;
01756 
01762         virtual int getBoundaryDimension() const;
01763 
01764         virtual int getNumPoints() const;
01765         virtual string getGeometryType() const;
01766         virtual GeometryTypeId getGeometryTypeId() const;
01767         virtual bool isSimple() const;
01768         virtual bool equalsExact(const Geometry *other, double tolerance) const;
01769 
01770         virtual void apply_ro(CoordinateFilter *filter) const;
01771         virtual void apply_rw(CoordinateFilter *filter);
01772         virtual void apply_ro(GeometryFilter *filter) const;
01773         virtual void apply_rw(GeometryFilter *filter);
01774         virtual void apply_ro(GeometryComponentFilter *filter) const;
01775         virtual void apply_rw(GeometryComponentFilter *filter);
01776         virtual void normalize();
01777         virtual const Coordinate* getCoordinate() const;
01779         virtual double getArea() const;
01781         virtual double getLength() const;
01783         virtual int getNumGeometries() const;
01785         virtual const Geometry* getGeometryN(int n) const;
01786 protected:
01787         vector<Geometry *>* geometries;
01788         virtual Envelope* computeEnvelopeInternal() const;
01789         virtual int compareToSameClass(const Geometry *gc) const;
01790 private:
01791 #ifdef INT64_CONST_IS_I64
01792         static const int64 serialVersionUID = -5694727726395021467I64;
01793 #else
01794         static const int64 serialVersionUID = -5694727726395021467LL;
01795 #endif        
01796 };
01797 
01798 class GeometryCollectionIterator {
01799 public:
01800         GeometryCollectionIterator();
01801         GeometryCollectionIterator(const GeometryCollectionIterator &gci);
01802         GeometryCollectionIterator(const GeometryCollection *newParent);
01803         virtual ~GeometryCollectionIterator();
01804         bool hasNext() const;
01805         const Geometry *next();
01806         void remove(); //Not implemented
01807 private:
01808         const GeometryCollection* parent;
01809         bool atStart;
01810         int max;
01811         int index;
01812         GeometryCollectionIterator* subcollectionIterator;
01813 };
01814 
01819 class Point : public Geometry{
01820 public:
01821 
01834         Point(CoordinateSequence *newCoords, const GeometryFactory *newFactory);
01835 
01836         Point(const Point &p); 
01837         virtual ~Point();
01838         Geometry *clone() const;
01839         CoordinateSequence* getCoordinates(void) const;
01840         int getNumPoints() const;
01841         bool isEmpty() const;
01842         bool isSimple() const;
01843         //bool isValid() const;
01844 
01846         int getDimension() const;
01847 
01849         int getBoundaryDimension() const;
01850 
01852         Geometry* getBoundary() const;
01853 
01854         double getX() const;
01855         double getY() const;
01856         const Coordinate* getCoordinate() const;
01857         string getGeometryType() const;
01858         virtual GeometryTypeId getGeometryTypeId() const;
01859         void apply_ro(CoordinateFilter *filter) const;
01860         void apply_rw(CoordinateFilter *filter);
01861         void apply_ro(GeometryFilter *filter) const;
01862         void apply_rw(GeometryFilter *filter);
01863         void apply_rw(GeometryComponentFilter *filter);
01864         void apply_ro(GeometryComponentFilter *filter) const;
01865         bool equalsExact(const Geometry *other, double tolerance) const;
01866         void normalize(void) { };
01867 protected:
01868         Envelope* computeEnvelopeInternal() const;
01869         int compareToSameClass(const Geometry *p) const;
01870 private:
01874         CoordinateSequence *coordinates;
01875 #ifdef INT64_CONST_IS_I64
01876         static const int64 serialVersionUID = 4902022702746614570I64;
01877 #else        
01878         static const int64 serialVersionUID = 4902022702746614570LL;
01879 #endif        
01880 public:
01881         const CoordinateSequence *getCoordinatesRO() const;
01882 };
01883 
01888 class LineString: public Geometry {
01889 public:
01890         LineString(const LineString &ls);
01891 
01893         LineString(CoordinateSequence *pts, const GeometryFactory *newFactory);
01894 
01895         virtual ~LineString();
01896         virtual Geometry *clone() const;
01897         virtual CoordinateSequence* getCoordinates() const;
01898 
01900         const CoordinateSequence* getCoordinatesRO() const;
01901 
01902         virtual const Coordinate& getCoordinateN(int n) const;
01903 
01905         virtual int getDimension() const;
01906 
01912         virtual int getBoundaryDimension() const;
01913 
01919         virtual Geometry* getBoundary() const;
01920 
01921         virtual bool isEmpty() const;
01922         virtual int getNumPoints() const;
01923         virtual Point* getPointN(int n) const;
01924         virtual Point* getStartPoint() const;
01925         virtual Point* getEndPoint() const;
01926         virtual bool isClosed() const;
01927         virtual bool isRing() const;
01928         virtual string getGeometryType() const;
01929         virtual GeometryTypeId getGeometryTypeId() const;
01930         virtual bool isSimple() const;
01931         virtual bool isCoordinate(Coordinate& pt) const;
01932         virtual bool equalsExact(const Geometry *other, double tolerance) const;
01933         virtual void apply_rw(CoordinateFilter *filter);
01934         virtual void apply_ro(CoordinateFilter *filter) const;
01935         virtual void apply_rw(GeometryFilter *filter);
01936         virtual void apply_ro(GeometryFilter *filter) const;
01937         virtual void apply_rw(GeometryComponentFilter *filter);
01938         virtual void apply_ro(GeometryComponentFilter *filter) const;
01939 
01941         virtual void normalize();
01942 
01943         //was protected
01944         virtual int compareToSameClass(const Geometry *ls) const;
01945         virtual int compareTo(const LineString *ls) const;
01946         virtual const Coordinate* getCoordinate() const;
01947         virtual double getLength() const;
01948 protected:
01949         virtual Envelope* computeEnvelopeInternal() const;
01950         CoordinateSequence* points;
01951 private:
01952 #ifdef INT64_CONST_IS_I64
01953         static const int64 serialVersionUID = 3110669828065365560I64;
01954 #else
01955         static const int64 serialVersionUID = 3110669828065365560LL;
01956 #endif        
01957 };
01958 
01969 class LinearRing : public LineString{
01970 
01971 public:
01972 
01973         LinearRing(const LinearRing &lr);
01974 
01986         LinearRing(CoordinateSequence* points, const GeometryFactory *newFactory);
01987 
01988         virtual ~LinearRing();
01989         bool isSimple() const;
01990         string getGeometryType() const;
01991         virtual GeometryTypeId getGeometryTypeId() const;
01992         bool isClosed() const;
01993         void setPoints(CoordinateSequence* cl);
01994     Geometry* clone() const;
01995 private:
01996 #ifdef INT64_CONST_IS_I64
01997         static const int64 serialVersionUID = -4261142084085851829I64;
01998 #else
01999         static const int64 serialVersionUID = -4261142084085851829LL;
02000 #endif        
02001         void validateConstruction();
02002 };
02003 
02019 class Polygon: public Geometry{
02020 public:
02021         Polygon(const Polygon &p);
02022         virtual ~Polygon();
02023 
02042         Polygon(LinearRing *newShell, vector<Geometry *> *newHoles,
02043                 const GeometryFactory *newFactory);
02044 
02045         virtual Geometry *clone() const;
02046         CoordinateSequence* getCoordinates() const;
02047         int getNumPoints() const;
02048 
02050         int getDimension() const;
02051 
02053         int getBoundaryDimension() const;
02054 
02061         Geometry* getBoundary() const;
02062 
02063         bool isEmpty() const;
02064         bool isSimple() const;
02065         
02067         const LineString* getExteriorRing() const;
02068 
02070         int getNumInteriorRing() const;
02071 
02073         const LineString* getInteriorRingN(int n) const;
02074 
02075         string getGeometryType() const;
02076         virtual GeometryTypeId getGeometryTypeId() const;
02077         bool equalsExact(const Geometry *other, double tolerance) const;
02078         void apply_rw(CoordinateFilter *filter);
02079         void apply_ro(CoordinateFilter *filter) const;
02080         void apply_rw(GeometryFilter *filter);
02081         void apply_ro(GeometryFilter *filter) const;
02082         Geometry* convexHull() const;
02083         void normalize();
02084         int compareToSameClass(const Geometry *p) const; //was protected
02085         const Coordinate* getCoordinate() const;
02086 
02087         double getArea() const;
02088 
02090         double getLength() const;
02091 
02092         void apply_rw(GeometryComponentFilter *filter);
02093         void apply_ro(GeometryComponentFilter *filter) const;
02094 protected:
02095         LinearRing *shell;
02096         vector<Geometry *> *holes; //Actually vector<LinearRing *>
02097         Envelope* computeEnvelopeInternal() const;
02098 private:
02099         void normalize(LinearRing *ring, bool clockwise);
02100 #ifdef INT64_CONST_IS_I64
02101         static const int64 serialVersionUID = -3494792200821764533I64;
02102 #else
02103         static const int64 serialVersionUID = -3494792200821764533LL;
02104 #endif        
02105 };
02106 
02111 class MultiPoint: public GeometryCollection{
02112 public:
02113 
02132         MultiPoint(vector<Geometry *> *newPoints, const GeometryFactory *newFactory);
02133 
02134         virtual ~MultiPoint();
02135 
02137         int getDimension() const;
02138 
02140         int getBoundaryDimension() const;
02141 
02143         Geometry* getBoundary() const;
02144 
02145         string getGeometryType() const;
02146         virtual GeometryTypeId getGeometryTypeId() const;
02147         //bool isValid() const;
02148         bool isSimple() const;
02149         bool equalsExact(const Geometry *other, double tolerance) const;
02150 protected:
02151         const Coordinate* getCoordinate(int n) const;
02152 private:
02153 #ifdef INT64_CONST_IS_I64
02154         static const int64 serialVersionUID = -8048474874175355449I64;
02155 #else
02156         static const int64 serialVersionUID = -8048474874175355449LL;
02157 #endif        
02158 };
02159 
02164 class MultiLineString: public GeometryCollection{
02165 public:
02166 
02186         MultiLineString(vector<Geometry *> *newLines, const GeometryFactory *newFactory);
02187 
02188         virtual ~MultiLineString();
02189 
02191         int getDimension() const;
02192 
02198         int getBoundaryDimension() const;
02199 
02201         Geometry* getBoundary() const;
02202 
02203         string getGeometryType() const;
02204         virtual GeometryTypeId getGeometryTypeId() const;
02205         bool isClosed() const;
02206         bool isSimple() const;
02207         bool equalsExact(const Geometry *other, double tolerance) const;
02208 private:
02209 #ifdef INT64_CONST_IS_I64
02210         static const int64 serialVersionUID = 8166665132445433741I64;
02211 #else
02212         static const int64 serialVersionUID = 8166665132445433741LL;
02213 #endif        
02214 };
02215 
02220 class MultiPolygon: public GeometryCollection {
02221 
02222 public:
02223 
02245         MultiPolygon(vector<Geometry *> *newPolys, const GeometryFactory *newFactory);
02246 
02247         virtual ~MultiPolygon();
02248 
02250         int getDimension() const;
02251 
02253         int getBoundaryDimension() const;
02254 
02260         Geometry* getBoundary() const;
02261 
02262         string getGeometryType() const;
02263         virtual GeometryTypeId getGeometryTypeId() const;
02264         bool isSimple() const;
02265         bool equalsExact(const Geometry *other, double tolerance) const;
02266 private:
02267 #ifdef INT64_CONST_IS_I64
02268         static const int64 serialVersionUID = -551033529766975875I64;
02269 #else
02270         static const int64 serialVersionUID = -551033529766975875LL;
02271 #endif        
02272 };
02273 
02279 class GeometryFactory {
02280 public:
02286         GeometryFactory();
02287 
02294         GeometryFactory(const PrecisionModel *pm, int newSRID, CoordinateSequenceFactory *nCoordinateSequenceFactory);
02295 
02302         GeometryFactory(CoordinateSequenceFactory *nCoordinateSequenceFactory);
02303 
02312         GeometryFactory(const PrecisionModel *pm);
02313 
02323         GeometryFactory(const PrecisionModel* pm, int newSRID);
02324 
02330         GeometryFactory(const GeometryFactory &gf);
02331 
02333         virtual ~GeometryFactory();
02334 
02335 //Skipped a lot of list to array convertors
02336 
02337         Point* createPointFromInternalCoord(const Coordinate* coord, const Geometry *exemplar) const;
02338 
02340         Geometry* toGeometry(const Envelope* envelope) const;
02341 
02343         const PrecisionModel* getPrecisionModel() const;
02344 
02346         Point* createPoint() const;
02347 
02349         Point* createPoint(const Coordinate& coordinate) const;
02350 
02352         Point* createPoint(CoordinateSequence *coordinates) const;
02353 
02355         Point* createPoint(const CoordinateSequence &coordinates) const;
02356 
02358         GeometryCollection* createGeometryCollection() const;
02359 
02361         GeometryCollection* createGeometryCollection(vector<Geometry *> *newGeoms) const;
02362 
02364         GeometryCollection* createGeometryCollection(const vector<Geometry *> &newGeoms) const;
02365 
02367         MultiLineString* createMultiLineString() const;
02368 
02370         MultiLineString* createMultiLineString(vector<Geometry *> *newLines) const;
02371 
02373         MultiLineString* createMultiLineString(const vector<Geometry *> &fromLines) const;
02374 
02376         MultiPolygon* createMultiPolygon() const;
02377 
02379         MultiPolygon* createMultiPolygon(vector<Geometry *> *newPolys) const;
02380 
02382         MultiPolygon* createMultiPolygon(const vector<Geometry *> &fromPolys) const;
02383 
02385         LinearRing* createLinearRing() const;
02386 
02388         LinearRing* createLinearRing(CoordinateSequence* newCoords) const;
02389 
02391         LinearRing* createLinearRing(const CoordinateSequence& coordinates) const;
02392 
02394         MultiPoint* createMultiPoint() const;
02395 
02397         MultiPoint* createMultiPoint(vector<Geometry *> *newPoints) const;
02398 
02400         MultiPoint* createMultiPoint(const vector<Geometry *> &fromPoints) const;
02401 
02403         MultiPoint* createMultiPoint(const CoordinateSequence &fromCoords) const;
02404 
02406         Polygon* createPolygon() const;
02407 
02409         Polygon* createPolygon(LinearRing *shell, vector<Geometry *> *holes) const;
02410 
02412         Polygon* createPolygon(const LinearRing &shell, const vector<Geometry *> &holes) const;
02413 
02415         LineString* createLineString() const;
02416 
02418         LineString* createLineString(CoordinateSequence* coordinates) const;
02419 
02421         LineString* createLineString(const CoordinateSequence& coordinates) const;
02422 
02424         Geometry* buildGeometry(vector<Geometry *> *geoms) const;
02425 
02427         Geometry* buildGeometry(const vector<Geometry *> &geoms) const;
02428         
02429         int getSRID() const {return SRID;};
02430 
02431         const CoordinateSequenceFactory* getCoordinateSequenceFactory() const {return coordinateListFactory;};
02432 
02434         Geometry* createGeometry(const Geometry *g) const;
02435 
02437         void destroyGeometry(Geometry *g) const;
02438 
02439 private:
02440         const PrecisionModel* precisionModel;
02441         int SRID;
02442 #ifdef INT64_CONST_IS_I64
02443         static const int64 serialVersionUID = -6820524753094095635I64;
02444 #else
02445         static const int64 serialVersionUID = -6820524753094095635LL;
02446 #endif        
02447         const CoordinateSequenceFactory *coordinateListFactory;
02448 };
02449 
02450 /*
02451  * Represents a planar triangle, and provides methods for calculating various
02452  * properties of triangles.
02453  */
02454 class Triangle {
02455 public:
02456         Coordinate p0,p1,p2;
02457         Triangle(const Coordinate& nP0,const Coordinate& nP1,const Coordinate& nP2);
02465         Coordinate* inCentre();
02466 };
02467 
02468 } // namespace geos
02469 #endif
02470 
02471 /**********************************************************************
02472  * $Log: geom.h,v $
02473  * Revision 1.34.2.2.2.5  2006/04/28 18:39:57  sgillies
02474  * Add LinearRing::clone (bug 102)
02475  *
02476  * Revision 1.34.2.2.2.4  2006/01/16 11:08:38  strk
02477  * Removed invalid full qualification of in-class-declaration methods.
02478  *
02479  * Revision 1.34.2.2.2.3  2005/11/29 17:52:21  strk
02480  * undef PROFILE_COORDINATE_COPIES (was introduced by previous commit, to easy profiling)
02481  *
02482  * Revision 1.34.2.2.2.2  2005/11/29 17:51:15  strk
02483  * Forgot to add the capi/ dir
02484  *
02485  * Revision 1.34.2.2.2.1  2005/11/29 16:58:17  strk
02486  * Back-ported WKB IO and C api.
02487  * Added required higher dimensional interfaces for CoordinateSequence
02488  *
02489  * Revision 1.34.2.2  2005/11/08 09:08:07  strk
02490  * Cleaned up a couple of Doxygen warnings
02491  *
02492  * Revision 1.34.2.1  2005/05/23 18:16:40  strk
02493  * more math.h to cmath conversions
02494  *
02495  * Revision 1.34  2004/12/03 22:52:56  strk
02496  * enforced const return of CoordinateSequence::toVector() method to derivate classes.
02497  *
02498  * Revision 1.33  2004/12/03 16:22:36  frank
02499  * update to use I64 on MSVC for 64 bit integer constants, also toVector chg.
02500  *
02501  * Revision 1.32  2004/11/29 16:05:33  strk
02502  * Fixed a bug in LineIntersector::interpolateZ causing NaN values
02503  * to come out.
02504  * Handled dimensional collapses in ElevationMatrix.
02505  * Added ISNAN macro and changed ISNAN/FINITE macros to avoid
02506  * dispendious isnan() and finite() calls.
02507  *
02508  * Revision 1.31  2004/11/23 16:22:49  strk
02509  * Added ElevationMatrix class and components to do post-processing draping of overlayed geometries.
02510  *
02511  * Revision 1.30  2004/11/17 08:13:16  strk
02512  * Indentation changes.
02513  * Some Z_COMPUTATION activated by default.
02514  *
02515  * Revision 1.29  2004/11/08 10:57:42  strk
02516  * Moved Log lines at the bottom, and cut oldest
02517  *
02518  * Revision 1.28  2004/10/13 10:03:02  strk
02519  * Added missing linemerge and polygonize operation.
02520  * Bug fixes and leaks removal from the newly added modules and
02521  * planargraph (used by them).
02522  * Some comments and indentation changes.
02523  *
02524  * Revision 1.27  2004/09/16 09:48:06  strk
02525  * Added Envelope::equals
02526  *
02527  * Revision 1.26  2004/09/13 12:39:14  strk
02528  * Made Point and MultiPoint subject to Validity tests.
02529  *
02530  * Revision 1.25  2004/09/07 08:29:57  strk
02531  * Fixed doxygen malformed comment for Coordinate class
02532  *
02533  * Revision 1.24  2004/07/27 16:35:46  strk
02534  * Geometry::getEnvelopeInternal() changed to return a const Envelope *.
02535  * This should reduce object copies as once computed the envelope of a
02536  * geometry remains the same.
02537  *
02538  * Revision 1.23  2004/07/26 16:35:19  strk
02539  * Removed dangling MultiPoint::isClosed() method definition.
02540  *
02541  * Revision 1.22  2004/07/22 16:58:01  strk
02542  * runtime version extractor functions split. geos::version() is now
02543  * geos::geosversion() and geos::jtsport()
02544  *
02545  **********************************************************************/

Generated on Mon Jan 8 23:49:01 2007 for GEOS by  doxygen 1.5.1