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

geom.h

00001 /**********************************************************************
00002  * $Id: geom.h,v 1.27 2004/09/16 09:48:06 strk Exp $
00003  *
00004  * GEOS - Geometry Engine Open Source
00005  * http://geos.refractions.net
00006  *
00007  * Copyright (C) 2001-2002 Vivid Solutions Inc.
00008  *
00009  * This is free software; you can redistribute and/or modify it under
00010  * the terms of the GNU Lesser General Public Licence as published
00011  * by the Free Software Foundation. 
00012  * See the COPYING file for more information.
00013  *
00014  **********************************************************************
00015  * $Log: geom.h,v $
00016  * Revision 1.27  2004/09/16 09:48:06  strk
00017  * Added Envelope::equals
00018  *
00019  * Revision 1.26  2004/09/13 12:39:14  strk
00020  * Made Point and MultiPoint subject to Validity tests.
00021  *
00022  * Revision 1.25  2004/09/07 08:29:57  strk
00023  * Fixed doxygen malformed comment for Coordinate class
00024  *
00025  * Revision 1.24  2004/07/27 16:35:46  strk
00026  * Geometry::getEnvelopeInternal() changed to return a const Envelope *.
00027  * This should reduce object copies as once computed the envelope of a
00028  * geometry remains the same.
00029  *
00030  * Revision 1.23  2004/07/26 16:35:19  strk
00031  * Removed dangling MultiPoint::isClosed() method definition.
00032  *
00033  * Revision 1.22  2004/07/22 16:58:01  strk
00034  * runtime version extractor functions split. geos::version() is now
00035  * geos::geosversion() and geos::jtsport()
00036  *
00037  * Revision 1.21  2004/07/22 08:45:50  strk
00038  * Documentation updates, memory leaks fixed.
00039  *
00040  * Revision 1.20  2004/07/22 07:19:21  strk
00041  * Changed getCoordinatesRO description.
00042  *
00043  * Revision 1.19  2004/07/22 07:04:49  strk
00044  * Documented missing geometry functions.
00045  *
00046  * Revision 1.18  2004/07/21 09:55:24  strk
00047  * CoordinateSequence::atLeastNCoordinatesOrNothing definition fix.
00048  * Documentation fixes.
00049  *
00050  * Revision 1.17  2004/07/20 08:34:18  strk
00051  * Fixed a bug in opDistance.h.
00052  * Removed doxygen tags from obsoleted CoordinateList.cpp.
00053  * Got doxygen to run with no warnings.
00054  *
00055  * Revision 1.16  2004/07/19 13:19:30  strk
00056  * Documentation fixes
00057  *
00058  * Revision 1.15  2004/07/19 10:34:06  strk
00059  * removed doxygen documentation of removed feature
00060  *
00061  * Revision 1.14  2004/07/17 09:18:54  strk
00062  * Added geos::version()
00063  *
00064  * Revision 1.13  2004/07/14 21:17:10  strk
00065  * added inequality operator for Coordinate
00066  *
00067  * Revision 1.12  2004/07/13 08:33:52  strk
00068  * Added missing virtual destructor to virtual classes.
00069  * Fixed implicit unsigned int -> int casts
00070  *
00071  * Revision 1.11  2004/07/12 19:16:39  strk
00072  * Commented out CoordinateList class definition.
00073  *
00074  * Revision 1.10  2004/07/08 19:34:49  strk
00075  * Mirrored JTS interface of CoordinateSequence, factory and
00076  * default implementations.
00077  * Added DefaultCoordinateSequenceFactory::instance() function.
00078  *
00079  * Revision 1.9  2004/07/07 09:38:12  strk
00080  * Dropped WKTWriter::stringOfChars (implemented by std::string).
00081  * Dropped WKTWriter default constructor (internally created GeometryFactory).
00082  * Updated XMLTester to respect the changes.
00083  * Main documentation page made nicer.
00084  *
00085  * Revision 1.8  2004/07/06 17:58:22  strk
00086  * Removed deprecated Geometry constructors based on PrecisionModel and
00087  * SRID specification. Removed SimpleGeometryPrecisionReducer capability
00088  * of changing Geometry's factory. Reverted Geometry::factory member
00089  * to be a reference to external factory.
00090  *
00091  * Revision 1.7  2004/07/05 19:40:48  strk
00092  * Added GeometryFactory::destroyGeometry(Geometry *)
00093  *
00094  * Revision 1.6  2004/07/05 15:20:18  strk
00095  * Documentation again.
00096  *
00097  * Revision 1.5  2004/07/05 14:23:03  strk
00098  * More documentation cleanups.
00099  *
00100  * Revision 1.4  2004/07/05 10:50:21  strk
00101  * deep-dopy construction taken out of Geometry and implemented only
00102  * in GeometryFactory.
00103  * Deep-copy geometry construction takes care of cleaning up copies
00104  * on exception.
00105  * Implemented clone() method for CoordinateSequence
00106  * Changed createMultiPoint(CoordinateSequence) signature to reflect
00107  * copy semantic (by-ref instead of by-pointer).
00108  * Cleaned up documentation.
00109  *
00110  * Revision 1.3  2004/07/03 12:51:37  strk
00111  * Documentation cleanups for DoxyGen.
00112  *
00113  * Revision 1.2  2004/07/02 14:27:32  strk
00114  * Added deep-copy / take-ownerhship for Point type.
00115  *
00116  * Revision 1.1  2004/07/02 13:20:42  strk
00117  * Header files moved under geos/ dir.
00118  *
00119  * Revision 1.68  2004/07/01 14:12:44  strk
00120  *
00121  * Geometry constructors come now in two flavors:
00122  *      - deep-copy args (pass-by-reference)
00123  *      - take-ownership of args (pass-by-pointer)
00124  * Same functionality is available through GeometryFactory,
00125  * including buildGeometry().
00126  *
00127  * Revision 1.67  2004/06/30 20:59:12  strk
00128  * Removed GeoemtryFactory copy from geometry constructors.
00129  * Enforced const-correctness on GeometryFactory arguments.
00130  *
00131  * Revision 1.66  2004/06/28 21:11:43  strk
00132  * Moved getGeometryTypeId() definitions from geom.h to each geometry module.
00133  * Added holes argument check in Polygon.cpp.
00134  *
00135  * Revision 1.65  2004/06/15 20:07:51  strk
00136  * GeometryCollections constructors make a deep copy of Geometry vector argument.
00137  *
00138  * Revision 1.64  2004/05/19 13:18:24  strk
00139  * made CoordinateSequence::toString() a const member function
00140  *
00141  * Revision 1.63  2004/05/17 21:14:47  ybychkov
00142  * JavaDoc updated
00143  *
00144  * Revision 1.62  2004/05/17 21:03:56  ybychkov
00145  * JavaDoc updated
00146  *
00147  * Revision 1.61  2004/05/14 12:14:08  strk
00148  * const correctness
00149  *
00150  * Revision 1.60  2004/05/07 09:05:13  strk
00151  * Some const correctness added. Fixed bug in GeometryFactory::createMultiPoint
00152  * to handle NULL CoordinateSequence.
00153  *
00154  * Revision 1.59  2004/05/05 10:54:48  strk
00155  * Removed some private static heap explicit allocation, less cleanup done by
00156  * the unloader.
00157  *
00158  * Revision 1.58  2004/04/20 08:52:01  strk
00159  * GeometryFactory and Geometry const correctness.
00160  * Memory leaks removed from SimpleGeometryPrecisionReducer
00161  * and GeometryFactory.
00162  *
00163  * Revision 1.57  2004/04/16 08:35:52  strk
00164  * Memory leaks fixed and const correctness applied for Point class.
00165  *
00166  * Revision 1.56  2004/04/16 07:42:06  strk
00167  * PrecisionModel::Type made an enum instead of a Type.
00168  *
00169  * Revision 1.55  2004/04/15 14:00:30  strk
00170  * Added new cleanup to Unload::Release
00171  *
00172  * Revision 1.54  2004/04/14 13:56:26  strk
00173  * All geometries returned by {from,to}InternalGeometry calls are
00174  * now deleted after use (unless NOT new).
00175  * Some 'commented' throw specifications in geom.h
00176  *
00177  * Revision 1.53  2004/04/14 07:29:43  strk
00178  * Fixed GeometryFactory constructors to copy given PrecisionModel. Added GeometryFactory copy constructor. Fixed Geometry constructors to copy GeometryFactory.
00179  *
00180  * Revision 1.52  2004/04/13 08:15:51  strk
00181  * Changed all 'long long' with int64.
00182  * Changed all 'long long' constants to end with two Ls.
00183  *
00184  * Revision 1.51  2004/04/10 22:41:24  ybychkov
00185  * "precision" upgraded to JTS 1.4
00186  *
00187  * Revision 1.50  2004/04/07 06:55:50  ybychkov
00188  * "operation/linemerge" ported from JTS 1.4
00189  *
00190  * Revision 1.49  2004/04/04 06:29:11  ybychkov
00191  * "planargraph" and "geom/utill" upgraded to JTS 1.4
00192  *
00193  * Revision 1.48  2004/04/01 10:44:34  ybychkov
00194  * All "geom" classes from JTS 1.3 upgraded to JTS 1.4
00195  *
00196  * Revision 1.47  2004/03/31 07:50:37  ybychkov
00197  * "geom" partially upgraded to JTS 1.4
00198  *
00199  * Revision 1.46  2004/03/29 06:59:24  ybychkov
00200  * "noding/snapround" package ported (JTS 1.4);
00201  * "operation", "operation/valid", "operation/relate" and "operation/overlay" upgraded to JTS 1.4;
00202  * "geom" partially upgraded.
00203  *
00204  * Revision 1.45  2004/03/18 10:42:44  ybychkov
00205  * "IO" and "Util" upgraded to JTS 1.4
00206  * "Geometry" partially upgraded.
00207  *
00208  * Revision 1.44  2004/03/17 02:00:33  ybychkov
00209  * "Algorithm" upgraded to JTS 1.4
00210  *
00211  * Revision 1.43  2004/03/01 22:04:59  strk
00212  * applied const correctness changes by Manuel Prieto Villegas <ManuelPrietoVillegas@telefonica.net>
00213  *
00214  * Revision 1.42  2003/11/07 01:23:42  pramsey
00215  * Add standard CVS headers licence notices and copyrights to all cpp and h
00216  * files.
00217  *
00218  *
00219  **********************************************************************/
00220 
00221 #ifndef GEOS_GEOM_H
00222 #define GEOS_GEOM_H
00223 
00224 #include <memory>
00225 #include <iostream>
00226 #include <string>
00227 #include <vector>
00228 #include <algorithm>
00229 #include <map>
00230 #include <math.h>
00231 #include <geos/platform.h>
00232 
00233 using namespace std;
00234 
00238 namespace geos {
00239 
00241 string geosversion();
00242 
00248 string jtsport();
00249 
00251 enum GeometryTypeId {
00253         GEOS_POINT,
00255         GEOS_LINESTRING,
00257         GEOS_LINEARRING,
00259         GEOS_POLYGON,
00261         GEOS_MULTIPOINT,
00263         GEOS_MULTILINESTRING,
00265         GEOS_MULTIPOLYGON,
00267         GEOS_GEOMETRYCOLLECTION
00268 };
00269 
00270 class Coordinate;
00271 
00313 class PrecisionModel {
00314 friend class Unload;
00315 public:
00317         /*
00318         * This class is only for use to support the "enums"
00319         * for the types of precision model.
00320         */
00321         typedef enum {
00322 
00329                 FIXED,
00330 
00336                 FLOATING,
00337 
00343                 FLOATING_SINGLE
00344 
00345         } Type;
00346         
00348         PrecisionModel(void);
00349 
00351 
00356         PrecisionModel(Type nModelType);
00357 
00358         /*
00359          * Creates a <code>PrecisionModel</code> with Fixed precision.
00360          *
00361          * Fixed-precision coordinates are represented as precise internal
00362          * coordinates, which are rounded to the grid defined by the
00363          * scale factor.
00364          *
00365          * @param  scale
00366          *      amount by which to multiply a coordinate after subtracting
00367          *      the offset, to obtain a precise coordinate
00368          * @param  offsetX  not used.
00369          * @param  offsetY  not used.
00370          *
00371          * @deprecated offsets are no longer supported, since internal
00372          * representation is rounded floating point
00373          */
00374         PrecisionModel(double newScale, double newOffsetX, double newOffsetY);
00375 
00387         PrecisionModel(double newScale);
00388 
00389         // copy constructor
00390         PrecisionModel(const PrecisionModel &pm);
00391 
00393         virtual ~PrecisionModel(void);
00394 
00395 
00397 
00402         static const double maximumPreciseValue;
00403 
00405         double makePrecise(double val) const;
00406 
00408         void makePrecise(Coordinate *coord) const;
00409 
00411 
00415         bool isFloating() const;
00416 
00418 
00423         int getMaximumSignificantDigits() const;
00424 
00426 
00429         Type getType() const;
00430 
00432         double getScale() const;
00433 
00434         /*
00435         * Returns the x-offset used to obtain a precise coordinate.
00436         *
00437         * @return the amount by which to subtract the x-coordinate before
00438         *         multiplying by the scale
00439         * @deprecated Offsets are no longer used
00440         */
00441         double getOffsetX() const;
00442 
00443         /*
00444         * Returns the y-offset used to obtain a precise coordinate.
00445         *
00446         * @return the amount by which to subtract the y-coordinate before
00447         *         multiplying by the scale
00448         * @deprecated Offsets are no longer used
00449         */
00450         double getOffsetY() const;
00451 
00452         /*
00453          *  Sets <code>internal</code> to the precise representation of <code>external</code>.
00454          *
00455          * @param external the original coordinate
00456          * @param internal the coordinate whose values will be changed to the
00457          *                 precise representation of <code>external</code>
00458          * @deprecated use makePrecise instead
00459          */
00460         void toInternal(const Coordinate& external, Coordinate* internal) const;
00461 
00462         /*
00463         *  Returns the precise representation of <code>external</code>.
00464         *
00465         *@param  external  the original coordinate
00466         *@return
00467         *       the coordinate whose values will be changed to the precise
00468         *       representation of <code>external</code>
00469         * @deprecated use makePrecise instead
00470         */
00471         Coordinate* toInternal(const Coordinate& external) const;
00472 
00473         /*
00474         *  Returns the external representation of <code>internal</code>.
00475         *
00476         *@param  internal  the original coordinate
00477         *@return           the coordinate whose values will be changed to the
00478         *      external representation of <code>internal</code>
00479         * @deprecated no longer needed, since internal representation is same as external representation
00480         */
00481         Coordinate* toExternal(const Coordinate& internal) const;
00482 
00483         /*
00484         *  Sets <code>external</code> to the external representation of
00485         *  <code>internal</code>.
00486         *
00487         * @param  internal  the original coordinate
00488         * @param  external
00489         *       the coordinate whose values will be changed to the
00490         *       external representation of <code>internal</code>
00491         * @deprecated no longer needed, since internal representation is same as external representation
00492         */
00493         void toExternal(const Coordinate& internal, Coordinate* external) const;
00494 
00495         string toString() const;
00496 
00498 
00512         int compareTo(const PrecisionModel* other) const;
00513 
00514 private:
00515         void setScale(double newScale);
00516         Type modelType;
00517         double scale;
00518         static const int64 serialVersionUID = 7777263578777803835LL;
00519 };
00520 
00541 class Coordinate {
00542 public:
00543         //void setNull(void);
00544         //static Coordinate& getNull(void);
00545         virtual ~Coordinate(){};
00546         //Coordinate(double xNew, double yNew, double zNew);
00547         //Coordinate(const Coordinate& c);
00548         //Coordinate(double xNew, double yNew);
00549         //void setCoordinate(Coordinate& other);
00550         //bool equals2D(Coordinate& other);
00551         //int compareTo(Coordinate& other);
00552         //bool equals3D(Coordinate& other);
00553         string toString() const;
00554         //void makePrecise();
00555         //double distance(Coordinate& p);
00556         static Coordinate nullCoord;
00557 
00558         void Coordinate::setNull() {
00559                 x=DoubleNotANumber;
00560                 y=DoubleNotANumber;
00561                 z=DoubleNotANumber;
00562         }
00563 
00564         static Coordinate& Coordinate::getNull() {
00565                 return nullCoord;
00566         }
00567 
00568         Coordinate::Coordinate() {
00569                 x=0.0;
00570                 y=0.0;
00571                 z=DoubleNotANumber;
00572         }
00573 
00574         Coordinate::Coordinate(double xNew, double yNew, double zNew) {
00575                 x=xNew;
00576                 y=yNew;
00577                 z=zNew;
00578         }
00579 
00580         Coordinate::Coordinate(const Coordinate& c){
00581                 x=c.x;
00582                 y=c.y;
00583                 z=c.z;
00584         }
00585 
00586         Coordinate::Coordinate(double xNew, double yNew){
00587                 x=xNew;
00588                 y=yNew;
00589                 z=DoubleNotANumber;
00590         }
00591 
00592         void Coordinate::setCoordinate(const Coordinate& other) {
00593                 x = other.x;
00594                 y = other.y;
00595                 z = other.z;
00596         }
00597 
00598         bool Coordinate::equals2D(const Coordinate& other) const {
00599                 if (x != other.x) {
00600                 return false;
00601                 }
00602                 if (y != other.y) {
00603                 return false;
00604                 }
00605                 return true;
00606         }
00607 
00608         int Coordinate::compareTo(const Coordinate& other) const {
00609                 if (x < other.x) {
00610                 return -1;
00611                 }
00612                 if (x > other.x) {
00613                 return 1;
00614                 }
00615                 if (y < other.y) {
00616                 return -1;
00617                 }
00618                 if (y > other.y) {
00619                 return 1;
00620                 }
00621                 return 0;
00622         }
00623 
00624         bool Coordinate::equals3D(const Coordinate& other) const {
00625                 return (x == other.x) && ( y == other.y) && (( z == other.z)||(z==DoubleNotANumber && other.z==DoubleNotANumber));
00626         }
00627 
00628         void Coordinate::makePrecise(const PrecisionModel *precisionModel) {
00629                 x = precisionModel->makePrecise(x);
00630                 y = precisionModel->makePrecise(y);
00631         }
00632 
00633         double Coordinate::distance(const Coordinate& p) const {
00634                 double dx = x - p.x;
00635                 double dy = y - p.y;
00636                 return sqrt(dx * dx + dy * dy);
00637         }
00638 
00639         int Coordinate::hashCode() {
00640                 //Algorithm from Effective Java by Joshua Bloch [Jon Aquino]
00641                 int result = 17;
00642                 result = 37 * result + hashCode(x);
00643                 result = 37 * result + hashCode(y);
00644                 return result;
00645         }
00646 
00651         static int Coordinate::hashCode(double x) {
00652                 int64 f = (int64)(x);
00653                 return (int)(f^(f>>32));
00654         }
00655 
00656 
00658         double x;
00660         double y;
00662         double z;
00663 
00664 private:
00665         static const int64 serialVersionUID=6683108902428366910LL;
00666 
00667 
00668 };
00669 
00670 
00671 //* class CoordinateList geom.h geos.h
00672 //*
00673 //* brief A list of Coordinates, which may be set to prevent
00674 //* repeated coordinates from occuring in the list.
00675 //
00676 //class CoordinateList {
00677 //public:
00678 //      ~CoordinateList(){};
00679 //
00680 //      // copy constructor
00681 //      CoordinateList(const CoordinateList &cl);
00682 //
00683 //      // constructor an empty CoordinateList
00684 //      CoordinateList();
00685 //
00686 //      /*
00687 //       * Constructs a new list from a vector of Coordinates.
00688 //       * Caller can specify if repeated points are to be removed.
00689 //       * Default is allowing repeated points.
00690 //       * Will take ownership of coords.
00691 //       */
00692 //      CoordinateList(vector<Coordinate> *coords, bool allowRepeted=false);
00693 //
00694 //      // Get a reference to the nth Coordinate 
00695 //      const Coordinate& getCoordinate(int n) const;
00696 //
00697 //      /*
00698 //       * \brief Add an array of coordinates 
00699 //       * @param vc The coordinates
00700 //       * @param allowRepeated if set to false, repeated coordinates
00701 //       *      are collapsed
00702 //       * @return true (as by general collection contract)
00703 //       */
00704 //      void add(vector<Coordinate>* vc, bool allowRepeated);
00705 //
00706 //      /*
00707 //       * \brief Add an array of coordinates 
00708 //       * @param cl The coordinates
00709 //       * @param allowRepeated if set to false, repeated coordinates
00710 //       * are collapsed
00711 //       * @param direction if false, the array is added in reverse order
00712 //       * @return true (as by general collection contract)
00713 //       */
00714 //      void add(CoordinateList *cl,bool allowRepeated,bool direction);
00715 //
00716 //      /*
00717 //       * \brief Add a coordinate
00718 //       * @param c The coordinate to add
00719 //       * @param allowRepeated if set to false, repeated coordinates
00720 //       * are collapsed
00721 //       * @return true (as by general collection contract)
00722 //       */
00723 //      void add(const Coordinate& c,bool allowRepeated);
00724 //
00725 //      // Add a Coordinate to the list
00726 //      void add(const Coordinate& c);
00727 //
00728 //      // Get vector
00729 //      const vector<Coordinate>* toCoordinateArray() const;
00730 //
00731 //private:
00732 //
00733 //      vector<Coordinate> *vect;
00734 //};
00735 
00755 class CoordinateSequence {
00756 public:
00757         virtual ~CoordinateSequence(){};
00758 
00762         virtual CoordinateSequence *clone() const=0;
00763 
00770         //virtual const Coordinate& getCoordinate(int i) const=0;
00771         virtual const Coordinate& getAt(int i) const=0;
00772 
00777         //virtual int size() const=0;
00778         virtual int getSize() const=0;
00779 
00789         virtual const vector<Coordinate>* toVector() const=0;
00790 
00798         void add(const vector<Coordinate>* vc, bool allowRepeated);
00799 
00808         void add(CoordinateSequence *cl,bool allowRepeated,bool direction);
00809 
00817         void add(const Coordinate& c,bool allowRepeated);
00818 
00820         virtual bool isEmpty() const=0;
00821 
00823         virtual void add(const Coordinate& c)=0;
00824 
00825         // Get number of coordinates
00826         //virtual int getSize() const=0;
00827 
00829         //virtual       const Coordinate& getAt(int pos) const=0;
00830 
00832         virtual void setAt(const Coordinate& c, int pos)=0;
00833 
00835         virtual void deleteAt(int pos)=0;
00836 
00838         virtual string toString() const=0;
00839 
00841         virtual void setPoints(const vector<Coordinate> &v)=0;
00842         
00844         bool hasRepeatedPoints() const;
00845 
00847         const Coordinate* minCoordinate() const;
00848 
00849 
00851         static CoordinateSequence* removeRepeatedPoints(const CoordinateSequence *cl);
00852 
00857         static bool hasRepeatedPoints(const CoordinateSequence *cl);
00858 
00863         static CoordinateSequence* atLeastNCoordinatesOrNothing(int n, CoordinateSequence *c);
00864 
00870         static const Coordinate* minCoordinate(CoordinateSequence *cl);
00871 
00873         static int indexOf(const Coordinate *coordinate, const CoordinateSequence *cl);
00879         static bool equals(CoordinateSequence *cl1, CoordinateSequence *cl2);
00880 
00882         static void scroll(CoordinateSequence *cl, const Coordinate *firstCoordinate);
00883 
00885         static void reverse(CoordinateSequence *cl);
00886 
00887 };
00888 
00894 class DefaultCoordinateSequence : public CoordinateSequence {
00895 public:
00896         //DefaultCoordinateSequence(int n);
00897         //DefaultCoordinateSequence(const Coordinate& c);
00898         //DefaultCoordinateSequence(const CoordinateSequence *c);
00899 
00900         DefaultCoordinateSequence(const DefaultCoordinateSequence &cl);
00901 
00902         CoordinateSequence *clone() const;
00903 
00904         //const Coordinate& getCoordinate(int pos) const;
00905         const Coordinate& getAt(int pos) const;
00906 
00907         //int size() const;
00908         int getSize() const;
00909         vector<Coordinate>* toVector() const;
00910 
00912         DefaultCoordinateSequence();
00913 
00915         DefaultCoordinateSequence(vector<Coordinate> *coords);
00916 
00918         DefaultCoordinateSequence(int n);
00919 
00920         virtual ~DefaultCoordinateSequence();
00921 
00922         bool isEmpty() const;
00923         void add(const Coordinate& c);
00924         void setAt(const Coordinate& c, int pos);
00925         void deleteAt(int pos);
00926         string toString() const;
00927         void setPoints(const vector<Coordinate> &v);
00928 private:
00929         vector<Coordinate> *vect;
00930 };
00931 
00932 struct point_3d {
00933         double x;
00934         double y;
00935         double z;
00936 };
00937 
00938 class PointCoordinateSequence : public CoordinateSequence {
00939 public:
00940         PointCoordinateSequence();
00941         PointCoordinateSequence(int n);
00942         PointCoordinateSequence(const Coordinate& c);
00943         PointCoordinateSequence(const PointCoordinateSequence &cl);
00944         PointCoordinateSequence(const CoordinateSequence *c);
00945         virtual ~PointCoordinateSequence();
00946         CoordinateSequence *clone() const;
00947         bool isEmpty() const;
00948         void add(const Coordinate& c);
00949         void add(point_3d p);
00950         int getSize() const;
00951         const Coordinate& getAt(int pos) const;
00952         point_3d getPointAt(int pos);
00953         void setAt(const Coordinate& c, int pos);
00954         void setAt(point_3d p, int pos);
00955         void deleteAt(int pos);
00956         vector<Coordinate>* toVector() const;
00957         vector<point_3d>* toPointVector();
00958         string toString() const;
00959         void setPoints(const vector<Coordinate> &v);
00960         void setPoints(vector<point_3d> &v);
00961 private:
00962         vector<point_3d> *vect;
00963 };
00964 
00972 class CoordinateSequenceFactory {
00973 public:
00974         // create an empty CoordinateSequence
00975         //virtual CoordinateSequence* createCoordinateSequence()=0;
00976 
00977         // create an empty CoordinateSequence with 'size' Coordinate slots
00978         //virtual CoordinateSequence* createCoordinateSequence(int size)=0;
00979 
00980         //virtual CoordinateSequence* createCoordinateSequence(const Coordinate& c)=0;
00981         // create an CoordinateSequence containing the given Coordinate 
00982         //virtual CoordinateSequence* createCoordinateSequence(const CoordinateSequence *c)=0;
00983 
00993         virtual CoordinateSequence *create(vector<Coordinate> *coordinates) const=0;
00994 };
00995 
01003 class DefaultCoordinateSequenceFactory: public CoordinateSequenceFactory {
01004 
01005 public:
01006         // create an empty DefaultCoordinateSequence
01007         //CoordinateSequence *createCoordinateSequence() {return new DefaultCoordinateSequence();};
01008         // create an empty DefaultCoordinateSequence with 'size' Coordinate slots
01009         //CoordinateSequence* createCoordinateSequence(int size) {return new DefaultCoordinateSequence(size);};
01010         //CoordinateSequence* createCoordinateSequence(const Coordinate& c) {return new DefaultCoordinateSequence(c);};
01011 
01012         // create an DefaultCoordinateSequence containing the given Coordinate 
01013         //CoordinateSequence* createCoordinateSequence(const CoordinateSequence *cl) {return new DefaultCoordinateSequence(cl);};
01014 
01015 
01020         CoordinateSequence *create(vector<Coordinate> *coords) const;
01021 
01025         static const CoordinateSequenceFactory *instance();
01026 };
01027 
01028 /*
01029  * \class PointCoordinateSequenceFactory geom.h geos.h
01030  *
01031  * \brief
01032  * Factory for PointCoordinateSequence objects.
01033  */
01034 class PointCoordinateSequenceFactory: public CoordinateSequenceFactory {
01035 public:
01036 
01037         CoordinateSequence *create(vector<Coordinate> *coords) const;
01038 };
01039 
01040 /*
01041  *  <code>Geometry</code> classes support the concept of applying a
01042  *  coordinate filter to every coordinate in the <code>Geometry</code>. A
01043  *  coordinate filter can either record information about each coordinate or
01044  *  change the coordinate in some way. Coordinate filters implement the
01045  *  interface <code>CoordinateFilter</code>. (<code>CoordinateFilter</code> is
01046  *  an example of the Gang-of-Four Visitor pattern). Coordinate filters can be
01047  *  used to implement such things as coordinate transformations, centroid and
01048  *  envelope computation, and many other functions.
01049  *
01050  */
01051 class CoordinateFilter {
01052 public:
01053    virtual ~CoordinateFilter() {}
01059    virtual void filter_rw(Coordinate* coord)=0;
01060    virtual void filter_ro(const Coordinate* coord)=0;
01061 };
01062 
01063 class Geometry;
01064 
01065 /*
01066  *  <code>Geometry</code> classes support the concept of applying
01067  *  a <code>GeometryComponentFilter</code>
01068  *  filter to the <code>Geometry</code>.
01069  *  The filter is applied to every component of the <code>Geometry</code>
01070  *  which is itself a <code>Geometry</code>.
01071  *  A <code>GeometryComponentFilter</code> filter can either
01072  *  record information about the <code>Geometry</code>
01073  *  or change the <code>Geometry</code> in some way.
01074  *  <code>GeometryComponentFilter</code>
01075  *  is an example of the Gang-of-Four Visitor pattern.
01076  *
01077  */
01078 class GeometryComponentFilter {
01079 public:
01085 //      virtual void filter(Geometry *geom)=0;
01086         virtual void filter_rw(Geometry *geom);
01087         virtual void filter_ro(const Geometry *geom); // Unsupported
01088 };
01089 
01090 
01091 /*
01092  * Constants representing the dimensions of a point, a curve and a surface.
01093  * Also, constants representing the dimensions of the empty geometry and
01094  * non-empty geometries, and a wildcard dimension meaning "any dimension".
01095  * 
01096  */
01097 class Dimension {
01098 public:
01099         enum {
01100                 DONTCARE=-3,    
01101                 True,                   
01102                 False,                  
01103                 P,                              
01104                 L,                              
01105                 A                               
01106         };
01107         //static const int P = 0;                       /// Dimension value of a point (0).
01108         //static const int L = 1;                       /// Dimension value of a curve (1).
01109         //static const int A = 2;                       /// Dimension value of a surface (2).
01110         //static const int False = -1;  /// Dimension value of the empty geometry (-1).
01111         //static const int True = -2;           /// Dimension value of non-empty geometries (= {P, L, A}).
01112         //static const int DONTCARE = -3;       /// Dimension value for any dimension (= {FALSE, TRUE}).
01113         static char toDimensionSymbol(int dimensionValue);
01114         static int toDimensionValue(char dimensionSymbol);
01115 };
01116 
01134 class Envelope {
01135 public:
01136         Envelope(void);
01137         Envelope(double x1, double x2, double y1, double y2);
01138         Envelope(const Coordinate& p1, const Coordinate& p2);
01139         Envelope(const Coordinate& p);
01140         Envelope(const Envelope &env);
01141         virtual ~Envelope(void);
01142         static bool intersects(const Coordinate& p1,const Coordinate& p2,const Coordinate& q);
01143         static bool intersects(const Coordinate& p1,const Coordinate& p2,const Coordinate& q1,const Coordinate& q2);
01144         void init(void);
01145         void init(double x1, double x2, double y1, double y2);
01146         void init(const Coordinate& p1, const Coordinate& p2);
01147         void init(const Coordinate& p);
01148         void init(Envelope env);
01149         void setToNull(void);
01150         bool isNull(void) const;
01151         double getWidth(void) const;
01152         double getHeight(void) const;
01153         double getMaxY() const;
01154         double getMaxX() const;
01155         double getMinY() const;
01156         double getMinX() const;
01157         void expandToInclude(const Coordinate& p);
01158         void expandToInclude(double x, double y);
01159         void expandToInclude(const Envelope* other);
01160         bool contains(const Coordinate& p) const;
01161         bool contains(double x, double y) const;
01162         bool contains(const Envelope* other) const;
01163         bool overlaps(const Coordinate& p) const;
01164         bool overlaps(double x, double y) const;
01165         bool overlaps(const Envelope* other) const;
01166         bool intersects(const Coordinate& p) const;
01167         bool intersects(double x, double y) const;
01168         bool intersects(const Envelope* other) const;
01169         bool equals(const Envelope* other) const;
01170         string toString(void) const;
01171         double distance(const Envelope* env) const;
01172     int hashCode() const;
01173 private:
01174         static double distance(double x0,double y0,double x1,double y1);
01175         double minx;    
01176         double maxx;    
01177         double miny;    
01178         double maxy;    
01179         static const int64 serialVersionUID=5873921885273102420LL;
01180 };
01181 
01182 class Geometry;
01183 class GeometryFilter;
01184 class IntersectionMatrix;
01185 
01186 
01187 class CGAlgorithms;
01188 class Point;
01189 class GeometryFactory;
01190 
01274 class Geometry{
01275 friend class Unload;
01276 public:
01277 
01278         Geometry(const Geometry &geom);
01279 
01286         Geometry(const GeometryFactory *factory);
01287 
01289         virtual ~Geometry();
01290 
01292         virtual Geometry* clone() const=0;
01293 
01301         const GeometryFactory* getFactory() const;
01302 
01316         void setUserData(void* newUserData);
01317 
01324         void* getUserData();
01325 
01326         /*
01327          * \brief
01328          * Returns the ID of the Spatial Reference System used by the
01329          * <code>Geometry</code>.
01330          *
01331          * GEOS supports Spatial Reference System information in the simple way
01332          * defined in the SFS. A Spatial Reference System ID (SRID) is present
01333          * in each <code>Geometry</code> object. <code>Geometry</code>
01334          * provides basic accessor operations for this field, but no others.
01335          * The SRID is represented as an integer.
01336          *
01337          * @return the ID of the coordinate space in which the
01338          * <code>Geometry</code> is defined.
01339          *
01340          * @deprecated use getUserData instead
01341          */
01342         virtual int getSRID() const;
01343 
01344         /*
01345          * Sets the ID of the Spatial Reference System used by the
01346          * <code>Geometry</code>.
01347          * @deprecated use {@link setUserData} instead
01348          */
01349         virtual void setSRID(int newSRID);
01350 
01355         virtual const PrecisionModel* getPrecisionModel() const;
01356 
01358         virtual const Coordinate* getCoordinate() const=0; //Abstract
01359 
01365         virtual CoordinateSequence* getCoordinates() const=0; //Abstract
01366 
01368         virtual int getNumPoints() const=0; //Abstract
01369 
01371         virtual bool isSimple() const=0; //Abstract
01372 
01374         virtual string getGeometryType() const=0; //Abstract
01375 
01377         virtual GeometryTypeId getGeometryTypeId() const=0; //Abstract
01378 
01388         virtual bool isValid() const;
01389 
01391         virtual bool isEmpty() const=0; //Abstract
01392 
01394         virtual int getDimension() const=0; //Abstract
01395 
01401         virtual Geometry* getBoundary() const=0; //Abstract
01402 
01404         virtual int getBoundaryDimension() const=0; //Abstract
01405 
01407         virtual Geometry* getEnvelope() const;
01408 
01413         virtual const Envelope* getEnvelopeInternal() const;
01414 
01420         virtual bool disjoint(const Geometry *other) const;
01421 
01426         virtual bool touches(const Geometry *other) const;
01427 
01429         virtual bool intersects(const Geometry *g) const;
01430 
01437         virtual bool crosses(const Geometry *g) const;
01438 
01443         virtual bool within(const Geometry *g) const;
01444 
01446         virtual bool contains(const Geometry *g) const;
01447 
01453         virtual bool overlaps(const Geometry *g) const;
01454 
01466         virtual bool relate(const Geometry *g, string intersectionPattern) const;
01468         virtual IntersectionMatrix* relate(const Geometry *g) const;
01469 
01475         virtual bool equals(const Geometry *g) const;
01476 
01478         virtual string toString() const;
01479 
01480         virtual string toText() const;
01481         
01483         virtual Geometry* buffer(double distance) const;
01484 
01486         virtual Geometry* buffer(double distance,int quadrantSegments) const;
01487 
01489         virtual Geometry* convexHull() const;
01490 
01495         virtual Geometry* intersection(const Geometry *other) const;
01496 
01501         virtual Geometry* Union(const Geometry *other) const;
01502                 // throw(IllegalArgumentException *, TopologyException *);
01503 
01509         virtual Geometry* difference(const Geometry *other) const;
01510 
01515         virtual Geometry* symDifference(const Geometry *other) const;
01516 
01521         virtual bool equalsExact(const Geometry *other, double tolerance)
01522                 const=0; //Abstract
01523 
01524         virtual void apply_rw(CoordinateFilter *filter)=0; //Abstract
01525         virtual void apply_ro(CoordinateFilter *filter) const=0; //Abstract
01526         virtual void apply_rw(GeometryFilter *filter);
01527         virtual void apply_ro(GeometryFilter *filter) const;
01528         virtual void apply_rw(GeometryComponentFilter *filter);
01529         virtual void apply_ro(GeometryComponentFilter *filter) const;
01530 
01532         virtual void normalize()=0; //Abstract
01533 
01534         virtual int compareTo(const Geometry *geom) const;
01535 
01540         virtual double distance(const Geometry *g) const;
01541 
01543         virtual double getArea() const;
01544 
01546         virtual double getLength() const;
01547 
01552         virtual bool isWithinDistance(const Geometry *geom,double cDistance);
01553 
01555         virtual Point* getCentroid() const;
01556 
01558         virtual Point* getInteriorPoint();
01559 
01560         /*
01561          * \brief
01562          * Notifies this Geometry that its Coordinates have been changed
01563          * by an external party (using a CoordinateFilter, for example).
01564          */
01565         virtual void geometryChanged();
01566 
01567         /*
01568          * \brief
01569          * Notifies this Geometry that its Coordinates have been changed
01570          * by an external party.
01571          */
01572         void geometryChangedAction();
01573 
01574 protected:
01575         mutable Envelope* envelope;
01576         
01578         static bool hasNonEmptyElements(const vector<Geometry *>* geometries);
01579 
01581         static bool hasNullElements(const CoordinateSequence* list);
01582 
01584         static bool hasNullElements(const vector<Geometry *>* lrs);
01585 
01586 //      static void reversePointOrder(CoordinateSequence* coordinates);
01587 //      static Coordinate& minCoordinate(CoordinateSequence* coordinates);
01588 //      static void scroll(CoordinateSequence* coordinates,Coordinate* firstCoordinate);
01589 //      static int indexOf(Coordinate* coordinate,CoordinateSequence* coordinates);
01590 //
01595         virtual bool isEquivalentClass(const Geometry *other) const;
01596 
01597         static void checkNotGeometryCollection(const Geometry *g); // throw(IllegalArgumentException *);
01598         //virtual void checkEqualSRID(Geometry *other);
01599         //virtual void checkEqualPrecisionModel(Geometry *other);
01600         virtual Envelope* computeEnvelopeInternal() const=0; //Abstract
01601         virtual int compareToSameClass(const Geometry *geom) const=0; //Abstract
01602         int compare(vector<Coordinate> a, vector<Coordinate> b) const;
01603         int compare(vector<Geometry *> a, vector<Geometry *> b) const;
01604         bool equal(const Coordinate& a, const Coordinate& b,double tolerance) const;
01605         int SRID;
01606 
01619         Geometry* toInternalGeometry(const Geometry *g) const;
01620         Geometry* fromInternalGeometry(const Geometry *g) const;
01621 private:
01622         virtual int getClassSortIndex() const;
01623         static GeometryComponentFilter geometryChangedFilter;
01624     static const int64 serialVersionUID = 8763622679187376702LL;
01625         const GeometryFactory *factory;
01626         static const GeometryFactory* INTERNAL_GEOMETRY_FACTORY;
01627         void* userData;
01628         Point* createPointFromInternalCoord(const Coordinate* coord,const Geometry *exemplar) const;
01629 };
01630 
01631 /*
01632  * <code>Geometry</code> classes support the concept of applying a <code>Geometry</code>
01633  *  filter to the <code>Geometry</code>. In the case of <code>GeometryCollection</code>
01634  *  subclasses, the filter is applied to every element <code>Geometry</code>. A
01635  *  <code>Geometry</code> filter can either record information about the <code>Geometry</code>
01636  *  or change the <code>Geometry</code> in some way. <code>Geometry</code>
01637  *  filters implement the interface <code>GeometryFilter</code>. (<code>GeometryFilter</code>
01638  *  is an example of the Gang-of-Four Visitor pattern).
01639  *
01640  */
01641 class GeometryFilter {
01642 public:
01648         virtual void filter_ro(const Geometry *geom)=0;
01649         virtual void filter_rw(Geometry *geom)=0;
01650 };
01651 
01652 /*
01653  * Represents a line segment defined by two {@link Coordinate}s.
01654  * Provides methods to compute various geometric properties
01655  * and relationships of line segments.
01656  * 
01657  * This class is designed to be easily mutable (to the extent of
01658  * having its contained points public).
01659  * This supports a common pattern of reusing a single LineSegment
01660  * object as a way of computing segment properties on the
01661  * segments defined by arrays or lists of {@link Coordinate}s.
01662  *
01663  */
01664 class LineSegment {
01665 public:
01666         Coordinate p0; 
01667         Coordinate p1; 
01668         LineSegment(void);
01669         LineSegment(const LineSegment &ls);
01670         LineSegment(const Coordinate& c0, const Coordinate& c1);
01671         virtual ~LineSegment(void);
01672         virtual void setCoordinates(const Coordinate& c0, const Coordinate& c1);
01673         virtual const Coordinate& getCoordinate(int i) const;
01674         virtual void setCoordinates(const LineSegment ls);
01675         virtual double getLength() const;
01681         virtual bool isHorizontal() const;
01687         virtual bool isVertical() const;
01707         virtual int orientationIndex(LineSegment *seg) const;
01708         virtual void reverse();
01709         virtual void normalize();
01710         virtual double angle() const;
01711         virtual double distance(const LineSegment ls) const;
01715         virtual double distance(const Coordinate& p) const;
01720         virtual double distancePerpendicular(const Coordinate& p) const;
01721         virtual double projectionFactor(const Coordinate& p) const;
01722         virtual Coordinate* project(const Coordinate& p) const;
01723         virtual LineSegment* project(const LineSegment *seg) const;
01724         virtual Coordinate* closestPoint(const Coordinate& p) const;
01725         virtual int compareTo(const LineSegment other) const;
01726         virtual bool equalsTopo(const LineSegment other) const;
01727 
01734         virtual CoordinateSequence* closestPoints(const LineSegment *line);
01735 
01747         Coordinate* intersection(const LineSegment *line) const;
01748         virtual string toString() const;
01749 private:
01750   static const int64 serialVersionUID=3252005833466256227LL;
01751 
01752 };
01753 
01754 class IntersectionMatrix {
01755 public:
01756         IntersectionMatrix();
01757         IntersectionMatrix(string elements);
01758         IntersectionMatrix(const IntersectionMatrix &im);
01759         virtual ~IntersectionMatrix();
01760         static bool matches(int actualDimensionValue, char requiredDimensionSymbol);
01761         static bool matches(string actualDimensionSymbols, string requiredDimensionSymbols);
01762         void add(IntersectionMatrix *im);
01763         void set(int row, int column, int dimensionValue);
01764         void set(string dimensionSymbols);
01765         void setAtLeast(int row, int column, int minimumDimensionValue);
01766         void setAtLeastIfValid(int row, int column, int minimumDimensionValue);
01767         void setAtLeast(string minimumDimensionSymbols);
01768         void setAll(int dimensionValue);
01769         int get(int row, int column);
01770         bool isDisjoint();
01771         bool isIntersects();
01772         bool isTouches(int dimensionOfGeometryA, int dimensionOfGeometryB);
01773         bool isCrosses(int dimensionOfGeometryA, int dimensionOfGeometryB);
01774         bool isWithin();
01775         bool isContains();
01776         bool isEquals(int dimensionOfGeometryA, int dimensionOfGeometryB);
01777         bool isOverlaps(int dimensionOfGeometryA, int dimensionOfGeometryB);
01778         bool matches(string requiredDimensionSymbols);
01779         IntersectionMatrix* transpose();
01780         string toString();
01781 private:
01782         int matrix[3][3];
01783 };
01784 
01785 /*
01786  *  Constants representing the location of a point relative to a geometry. They
01787  *  can also be thought of as the row or column index of a DE-9IM matrix. For a
01788  *  description of the DE-9IM, see the <A
01789  *  HREF="http://www.opengis.org/techno/specs.htm">OpenGIS Simple Features
01790  *  Specification for SQL</A> .
01791  */
01792 class Location {
01793 public:
01794         enum {
01798                 UNDEF=-1,   
01799 
01804                 INTERIOR,
01810                 BOUNDARY,
01816                 EXTERIOR = 2
01817         };
01818         //static const int INTERIOR = 0;
01819         //static const int BOUNDARY = 1;
01820         //static const int EXTERIOR = 2;
01821         //static const int UNDEF = -1;   ///Instead of NULL
01822         static char toLocationSymbol(int locationValue);
01823 };
01824 
01825 
01826 //Operators
01827 bool operator==(const Coordinate& a, const Coordinate& b);
01828 bool operator!=(const Coordinate& a, const Coordinate& b);
01829 bool operator==(const Envelope a, const Envelope b);
01830 bool operator==(const PrecisionModel a, const PrecisionModel b);
01831 bool operator==(const LineSegment a, const LineSegment b);
01832 
01833 bool lessThen(Coordinate& a,Coordinate& b);
01834 bool greaterThen(Geometry *first, Geometry *second);
01835 
01845 class GeometryCollection : public Geometry{
01846 public:
01847         GeometryCollection(const GeometryCollection &gc);
01848 
01873         GeometryCollection(vector<Geometry *> *newGeoms, const GeometryFactory *newFactory);
01874 
01875         virtual Geometry *clone() const;
01876 
01877         virtual ~GeometryCollection();
01878 
01892         virtual CoordinateSequence* getCoordinates() const;
01893 
01894         virtual bool isEmpty() const;
01895 
01901         virtual int getDimension() const;
01902 
01903         virtual Geometry* getBoundary() const;
01904 
01910         virtual int getBoundaryDimension() const;
01911 
01912         virtual int getNumPoints() const;
01913         virtual string getGeometryType() const;
01914         virtual GeometryTypeId getGeometryTypeId() const;
01915         virtual bool isSimple() const;
01916         virtual bool equalsExact(const Geometry *other, double tolerance) const;
01917 
01918         virtual void apply_ro(CoordinateFilter *filter) const;
01919         virtual void apply_rw(CoordinateFilter *filter);
01920         virtual void apply_ro(GeometryFilter *filter) const;
01921         virtual void apply_rw(GeometryFilter *filter);
01922         virtual void apply_ro(GeometryComponentFilter *filter) const;
01923         virtual void apply_rw(GeometryComponentFilter *filter);
01924         virtual void normalize();
01925         virtual const Coordinate* getCoordinate() const;
01927         virtual double getArea() const;
01929         virtual double getLength() const;
01931         virtual int getNumGeometries() const;
01933         virtual const Geometry* getGeometryN(int n) const;
01934 protected:
01935         vector<Geometry *>* geometries;
01936         virtual Envelope* computeEnvelopeInternal() const;
01937         virtual int compareToSameClass(const Geometry *gc) const;
01938 private:
01939         static const int64 serialVersionUID = -5694727726395021467LL;
01940 };
01941 
01942 class GeometryCollectionIterator {
01943 public:
01944         GeometryCollectionIterator();
01945         GeometryCollectionIterator(const GeometryCollectionIterator &gci);
01946         GeometryCollectionIterator(const GeometryCollection *newParent);
01947         virtual ~GeometryCollectionIterator();
01948         bool hasNext() const;
01949         const Geometry *next();
01950         void remove(); //Not implemented
01951 private:
01952         const GeometryCollection* parent;
01953         bool atStart;
01954         int max;
01955         int index;
01956         GeometryCollectionIterator* subcollectionIterator;
01957 };
01958 
01963 class Point : public Geometry{
01964 public:
01965 
01978         Point(CoordinateSequence *newCoords, const GeometryFactory *newFactory);
01979 
01980         Point(const Point &p); 
01981         virtual ~Point();
01982         Geometry *clone() const;
01983         CoordinateSequence* getCoordinates(void) const;
01984         int getNumPoints() const;
01985         bool isEmpty() const;
01986         bool isSimple() const;
01987         //bool isValid() const;
01988 
01990         int getDimension() const;
01991 
01993         int getBoundaryDimension() const;
01994 
01996         Geometry* getBoundary() const;
01997 
01998         double getX() const;
01999         double getY() const;
02000         const Coordinate* getCoordinate() const;
02001         string getGeometryType() const;
02002         virtual GeometryTypeId getGeometryTypeId() const;
02003         void apply_ro(CoordinateFilter *filter) const;
02004         void apply_rw(CoordinateFilter *filter);
02005         void apply_ro(GeometryFilter *filter) const;
02006         void apply_rw(GeometryFilter *filter);
02007         void apply_rw(GeometryComponentFilter *filter);
02008         void apply_ro(GeometryComponentFilter *filter) const;
02009         bool equalsExact(const Geometry *other, double tolerance) const;
02010         void normalize(void) { };
02011 protected:
02012         Envelope* computeEnvelopeInternal() const;
02013         int compareToSameClass(const Geometry *p) const;
02014 private:
02018         CoordinateSequence *coordinates;
02019         static const int64 serialVersionUID = 4902022702746614570LL;
02020 };
02021 
02026 class LineString: public Geometry {
02027 public:
02028         LineString(const LineString &ls);
02029 
02031         LineString(CoordinateSequence *pts, const GeometryFactory *newFactory);
02032 
02033         virtual ~LineString();
02034         virtual Geometry *clone() const;
02035         virtual CoordinateSequence* getCoordinates() const;
02036 
02038         const CoordinateSequence* getCoordinatesRO() const;
02039 
02040         virtual const Coordinate& getCoordinateN(int n) const;
02041 
02043         virtual int getDimension() const;
02044 
02050         virtual int getBoundaryDimension() const;
02051 
02057         virtual Geometry* getBoundary() const;
02058 
02059         virtual bool isEmpty() const;
02060         virtual int getNumPoints() const;
02061         virtual Point* getPointN(int n) const;
02062         virtual Point* getStartPoint() const;
02063         virtual Point* getEndPoint() const;
02064         virtual bool isClosed() const;
02065         virtual bool isRing() const;
02066         virtual string getGeometryType() const;
02067         virtual GeometryTypeId getGeometryTypeId() const;
02068         virtual bool isSimple() const;
02069         virtual bool isCoordinate(Coordinate& pt) const;
02070         virtual bool equalsExact(const Geometry *other, double tolerance) const;
02071         virtual void apply_rw(CoordinateFilter *filter);
02072         virtual void apply_ro(CoordinateFilter *filter) const;
02073         virtual void apply_rw(GeometryFilter *filter);
02074         virtual void apply_ro(GeometryFilter *filter) const;
02075         virtual void apply_rw(GeometryComponentFilter *filter);
02076         virtual void apply_ro(GeometryComponentFilter *filter) const;
02077 
02079         virtual void normalize();
02080 
02081         //was protected
02082         virtual int compareToSameClass(const Geometry *ls) const;
02083         virtual int compareTo(const LineString *ls) const;
02084         virtual const Coordinate* getCoordinate() const;
02085         virtual double getLength() const;
02086 protected:
02087         virtual Envelope* computeEnvelopeInternal() const;
02088         CoordinateSequence* points;
02089 private:
02090         static const int64 serialVersionUID = 3110669828065365560LL;
02091 };
02092 
02103 class LinearRing : public LineString{
02104 
02105 public:
02106 
02107         LinearRing(const LinearRing &lr);
02108 
02120         LinearRing(CoordinateSequence* points, const GeometryFactory *newFactory);
02121 
02122         virtual ~LinearRing();
02123         bool isSimple() const;
02124         string getGeometryType() const;
02125         virtual GeometryTypeId getGeometryTypeId() const;
02126         bool isClosed() const;
02127         void setPoints(CoordinateSequence* cl);
02128 private:
02129         static const int64 serialVersionUID = -4261142084085851829LL;
02130         void validateConstruction();
02131 };
02132 
02148 class Polygon: public Geometry{
02149 public:
02150         Polygon(const Polygon &p);
02151         virtual ~Polygon();
02152 
02171         Polygon(LinearRing *newShell, vector<Geometry *> *newHoles,
02172                 const GeometryFactory *newFactory);
02173 
02174         virtual Geometry *clone() const;
02175         CoordinateSequence* getCoordinates() const;
02176         int getNumPoints() const;
02177 
02179         int getDimension() const;
02180 
02182         int getBoundaryDimension() const;
02183 
02190         Geometry* getBoundary() const;
02191 
02192         bool isEmpty() const;
02193         bool isSimple() const;
02194         
02196         const LineString* getExteriorRing() const;
02197 
02199         int getNumInteriorRing() const;
02200 
02202         const LineString* getInteriorRingN(int n) const;
02203 
02204         string getGeometryType() const;
02205         virtual GeometryTypeId getGeometryTypeId() const;
02206         bool equalsExact(const Geometry *other, double tolerance) const;
02207         void apply_rw(CoordinateFilter *filter);
02208         void apply_ro(CoordinateFilter *filter) const;
02209         void apply_rw(GeometryFilter *filter);
02210         void apply_ro(GeometryFilter *filter) const;
02211         Geometry* convexHull() const;
02212         void normalize();
02213         int compareToSameClass(const Geometry *p) const; //was protected
02214         const Coordinate* getCoordinate() const;
02215 
02216         double getArea() const;
02217 
02219         double getLength() const;
02220 
02221         void apply_rw(GeometryComponentFilter *filter);
02222         void apply_ro(GeometryComponentFilter *filter) const;
02223 protected:
02224         LinearRing *shell;
02225         vector<Geometry *> *holes; //Actually vector<LinearRing *>
02226         Envelope* computeEnvelopeInternal() const;
02227 private:
02228         void normalize(LinearRing *ring, bool clockwise);
02229         static const int64 serialVersionUID = -3494792200821764533LL;
02230 };
02231 
02236 class MultiPoint: public GeometryCollection{
02237 public:
02238 
02257         MultiPoint(vector<Geometry *> *newPoints, const GeometryFactory *newFactory);
02258 
02259         virtual ~MultiPoint();
02260 
02262         int getDimension() const;
02263 
02265         int getBoundaryDimension() const;
02266 
02268         Geometry* getBoundary() const;
02269 
02270         string getGeometryType() const;
02271         virtual GeometryTypeId getGeometryTypeId() const;
02272         //bool isValid() const;
02273         bool isSimple() const;
02274         bool equalsExact(const Geometry *other, double tolerance) const;
02275 protected:
02276         const Coordinate* getCoordinate(int n) const;
02277 private:
02278         static const int64 serialVersionUID = -8048474874175355449LL;
02279 };
02280 
02285 class MultiLineString: public GeometryCollection{
02286 public:
02287 
02307         MultiLineString(vector<Geometry *> *newLines, const GeometryFactory *newFactory);
02308 
02309         virtual ~MultiLineString();
02310 
02312         int getDimension() const;
02313 
02319         int getBoundaryDimension() const;
02320 
02322         Geometry* getBoundary() const;
02323 
02324         string getGeometryType() const;
02325         virtual GeometryTypeId getGeometryTypeId() const;
02326         bool isClosed() const;
02327         bool isSimple() const;
02328         bool equalsExact(const Geometry *other, double tolerance) const;
02329 private:
02330         static const int64 serialVersionUID = 8166665132445433741LL;
02331 };
02332 
02337 class MultiPolygon: public GeometryCollection {
02338 
02339 public:
02340 
02362         MultiPolygon(vector<Geometry *> *newPolys, const GeometryFactory *newFactory);
02363 
02364         virtual ~MultiPolygon();
02365 
02367         int getDimension() const;
02368 
02370         int getBoundaryDimension() const;
02371 
02377         Geometry* getBoundary() const;
02378 
02379         string getGeometryType() const;
02380         virtual GeometryTypeId getGeometryTypeId() const;
02381         bool isSimple() const;
02382         bool equalsExact(const Geometry *other, double tolerance) const;
02383 private:
02384         static const int64 serialVersionUID = -551033529766975875LL;
02385 };
02386 
02392 class GeometryFactory {
02393 public:
02399         GeometryFactory();
02400 
02407         GeometryFactory(const PrecisionModel *pm, int newSRID, CoordinateSequenceFactory *nCoordinateSequenceFactory);
02408 
02415         GeometryFactory(CoordinateSequenceFactory *nCoordinateSequenceFactory);
02416 
02425         GeometryFactory(const PrecisionModel *pm);
02426 
02436         GeometryFactory(const PrecisionModel* pm, int newSRID);
02437 
02443         GeometryFactory(const GeometryFactory &gf);
02444 
02446         virtual ~GeometryFactory();
02447 
02448 //Skipped a lot of list to array convertors
02449 
02450         Point* createPointFromInternalCoord(const Coordinate* coord, const Geometry *exemplar) const;
02451 
02453         Geometry* toGeometry(const Envelope* envelope) const;
02454 
02456         const PrecisionModel* getPrecisionModel() const;
02457 
02459         Point* createPoint() const;
02460 
02462         Point* createPoint(const Coordinate& coordinate) const;
02463 
02465         Point* createPoint(CoordinateSequence *coordinates) const;
02466 
02468         Point* createPoint(const CoordinateSequence &coordinates) const;
02469 
02471         GeometryCollection* createGeometryCollection() const;
02472 
02474         GeometryCollection* createGeometryCollection(vector<Geometry *> *newGeoms) const;
02475 
02477         GeometryCollection* createGeometryCollection(const vector<Geometry *> &newGeoms) const;
02478 
02480         MultiLineString* createMultiLineString() const;
02481 
02483         MultiLineString* createMultiLineString(vector<Geometry *> *newLines) const;
02484 
02486         MultiLineString* createMultiLineString(const vector<Geometry *> &fromLines) const;
02487 
02489         MultiPolygon* createMultiPolygon() const;
02490 
02492         MultiPolygon* createMultiPolygon(vector<Geometry *> *newPolys) const;
02493 
02495         MultiPolygon* createMultiPolygon(const vector<Geometry *> &fromPolys) const;
02496 
02498         LinearRing* createLinearRing() const;
02499 
02501         LinearRing* createLinearRing(CoordinateSequence* newCoords) const;
02502 
02504         LinearRing* createLinearRing(const CoordinateSequence& coordinates) const;
02505 
02507         MultiPoint* createMultiPoint() const;
02508 
02510         MultiPoint* createMultiPoint(vector<Geometry *> *newPoints) const;
02511 
02513         MultiPoint* createMultiPoint(const vector<Geometry *> &fromPoints) const;
02514 
02516         MultiPoint* createMultiPoint(const CoordinateSequence &fromCoords) const;
02517 
02519         Polygon* createPolygon() const;
02520 
02522         Polygon* createPolygon(LinearRing *shell, vector<Geometry *> *holes) const;
02523 
02525         Polygon* createPolygon(const LinearRing &shell, const vector<Geometry *> &holes) const;
02526 
02528         LineString* createLineString() const;
02529 
02531         LineString* createLineString(CoordinateSequence* coordinates) const;
02532 
02534         LineString* createLineString(const CoordinateSequence& coordinates) const;
02535 
02537         Geometry* buildGeometry(vector<Geometry *> *geoms) const;
02538 
02540         Geometry* buildGeometry(const vector<Geometry *> &geoms) const;
02541         
02542         int getSRID() const {return SRID;};
02543 
02544         const CoordinateSequenceFactory* getCoordinateSequenceFactory() const {return coordinateListFactory;};
02545 
02547         Geometry* createGeometry(const Geometry *g) const;
02548 
02550         void destroyGeometry(Geometry *g) const;
02551 
02552 private:
02553         const PrecisionModel* precisionModel;
02554         int SRID;
02555         static const int64 serialVersionUID = -6820524753094095635LL;
02556         const CoordinateSequenceFactory *coordinateListFactory;
02557 };
02558 
02559 /*
02560  * Represents a planar triangle, and provides methods for calculating various
02561  * properties of triangles.
02562  */
02563 class Triangle {
02564 public:
02565         Coordinate p0,p1,p2;
02566         Triangle(const Coordinate& nP0,const Coordinate& nP1,const Coordinate& nP2);
02574         Coordinate* inCentre();
02575 };
02576 }
02577 #endif

Generated on Fri Nov 26 21:30:45 2004 for GEOS by  doxygen 1.3.9.1