00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
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
00115
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
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170 PrecisionModel(double newScale, double newOffsetX, double newOffsetY);
00171
00183 PrecisionModel(double newScale);
00184
00185
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
00232
00233
00234
00235
00236
00237 double getOffsetX() const;
00238
00239
00240
00241
00242
00243
00244
00245
00246 double getOffsetY() const;
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256 void toInternal(const Coordinate& external, Coordinate* internal) const;
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267 Coordinate* toInternal(const Coordinate& external) const;
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277 Coordinate* toExternal(const Coordinate& internal) const;
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
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
00342
00343
00344 class Coordinate {
00345 public:
00346
00347
00348 virtual ~Coordinate(){};
00349
00350
00351
00352
00353
00354
00355
00356 string toString() const;
00357
00358
00359 static Coordinate nullCoord;
00360
00361 void Coordinate::setNull() {
00362 x=DoubleNotANumber;
00363 y=DoubleNotANumber;
00364 z=DoubleNotANumber;
00365 }
00366
00367 static Coordinate& Coordinate::getNull() {
00368 return nullCoord;
00369 }
00370
00371 Coordinate::Coordinate() {
00372 x=0.0;
00373 y=0.0;
00374 z=DoubleNotANumber;
00375 }
00376
00377 Coordinate::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::Coordinate(const Coordinate& c){
00385 x=c.x;
00386 y=c.y;
00387 z=c.z;
00388 }
00389 #else
00390 Coordinate::Coordinate(const Coordinate& c);
00391 Coordinate &operator=(const Coordinate &c);
00392 #endif
00393
00394 Coordinate::Coordinate(double xNew, double yNew){
00395 x=xNew;
00396 y=yNew;
00397 z=DoubleNotANumber;
00398 }
00399
00400 void Coordinate::setCoordinate(const Coordinate& other) {
00401 x = other.x;
00402 y = other.y;
00403 z = other.z;
00404 }
00405
00406 bool Coordinate::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 Coordinate::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 Coordinate::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 Coordinate::makePrecise(const PrecisionModel *precisionModel) {
00437 x = precisionModel->makePrecise(x);
00438 y = precisionModel->makePrecise(y);
00439 }
00440
00441 double Coordinate::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 Coordinate::hashCode() {
00448
00449 int result = 17;
00450 result = 37 * result + hashCode(x);
00451 result = 37 * result + hashCode(y);
00452 return result;
00453 }
00454
00459 static int Coordinate::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
00483
00484
00485
00486
00487
00488
00489
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509
00510
00511
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523
00524
00525
00526
00527
00528
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538
00539
00540
00541
00542
00543
00544
00545
00546
00566 class CoordinateSequence {
00567 public:
00568 virtual ~CoordinateSequence(){};
00569
00573 virtual CoordinateSequence *clone() const=0;
00574
00581
00582 virtual const Coordinate& getAt(int i) const=0;
00583
00588
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
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
00640
00641
00643
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
00729 const Coordinate& getAt(int pos) const;
00730
00731
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
00809
00810
00811
00812
00813
00814
00815
00816
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
00843
00844
00845
00846
00847
00848
00849
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
00868
00869
00870
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
00881
00882
00883
00884
00885
00886
00887
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
00906
00907
00908
00909
00910
00911
00912
00913
00914
00915
00916
00917 class GeometryComponentFilter {
00918 public:
00924
00925 virtual void filter_rw(Geometry *geom);
00926 virtual void filter_ro(const Geometry *geom);
00927 };
00928
00929
00930
00931
00932
00933
00934
00935
00936 class Dimension {
00937 public:
00938 enum {
00939 DONTCARE=-3,
00940 True,
00941 False,
00942 P,
00943 L,
00944 A
00945 };
00946
00947
00948
00949
00950
00951
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
01172
01173
01174
01175
01176
01177
01178
01179
01180
01181
01182
01183
01184
01185
01186 virtual int getSRID() const;
01187
01188
01189
01190
01191
01192
01193 virtual void setSRID(int newSRID);
01194
01199 virtual const PrecisionModel* getPrecisionModel() const;
01200
01202 virtual const Coordinate* getCoordinate() const=0;
01203
01209 virtual CoordinateSequence* getCoordinates() const=0;
01210
01212 virtual int getNumPoints() const=0;
01213
01215 virtual bool isSimple() const=0;
01216
01218 virtual string getGeometryType() const=0;
01219
01221 virtual GeometryTypeId getGeometryTypeId() const=0;
01222
01232 virtual bool isValid() const;
01233
01235 virtual bool isEmpty() const=0;
01236
01238 virtual int getDimension() const=0;
01239
01245 virtual Geometry* getBoundary() const=0;
01246
01248 virtual int getBoundaryDimension() const=0;
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
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;
01367
01368 virtual void apply_rw(CoordinateFilter *filter)=0;
01369 virtual void apply_ro(CoordinateFilter *filter) const=0;
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;
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
01406
01407
01408
01409 virtual void geometryChanged();
01410
01411
01412
01413
01414
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
01431
01432
01433
01434
01439 virtual bool isEquivalentClass(const Geometry *other) const;
01440
01441 static void checkNotGeometryCollection(const Geometry *g);
01442
01443
01444 virtual Envelope* computeEnvelopeInternal() const=0;
01445 virtual int compareToSameClass(const Geometry *geom) const=0;
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
01481
01482
01483
01484
01485
01486
01487
01488 class GeometryFilter {
01489 public:
01490
01491
01492
01493
01494
01495
01496 virtual void filter_ro(const Geometry *geom)=0;
01497 virtual void filter_rw(Geometry *geom)=0;
01498 };
01499
01500
01501
01502
01503
01504
01505
01506
01507
01508
01509
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
01639
01640
01641
01642
01643
01644 class Location {
01645 public:
01646 enum {
01650 UNDEF=-1,
01651
01656 INTERIOR,
01662 BOUNDARY,
01668 EXTERIOR = 2
01669 };
01670
01671
01672
01673
01674 static char toLocationSymbol(int locationValue);
01675 };
01676
01677
01678
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();
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
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
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 private:
01995 #ifdef INT64_CONST_IS_I64
01996 static const int64 serialVersionUID = -4261142084085851829I64;
01997 #else
01998 static const int64 serialVersionUID = -4261142084085851829LL;
01999 #endif
02000 void validateConstruction();
02001 };
02002
02018 class Polygon: public Geometry{
02019 public:
02020 Polygon(const Polygon &p);
02021 virtual ~Polygon();
02022
02041 Polygon(LinearRing *newShell, vector<Geometry *> *newHoles,
02042 const GeometryFactory *newFactory);
02043
02044 virtual Geometry *clone() const;
02045 CoordinateSequence* getCoordinates() const;
02046 int getNumPoints() const;
02047
02049 int getDimension() const;
02050
02052 int getBoundaryDimension() const;
02053
02060 Geometry* getBoundary() const;
02061
02062 bool isEmpty() const;
02063 bool isSimple() const;
02064
02066 const LineString* getExteriorRing() const;
02067
02069 int getNumInteriorRing() const;
02070
02072 const LineString* getInteriorRingN(int n) const;
02073
02074 string getGeometryType() const;
02075 virtual GeometryTypeId getGeometryTypeId() const;
02076 bool equalsExact(const Geometry *other, double tolerance) const;
02077 void apply_rw(CoordinateFilter *filter);
02078 void apply_ro(CoordinateFilter *filter) const;
02079 void apply_rw(GeometryFilter *filter);
02080 void apply_ro(GeometryFilter *filter) const;
02081 Geometry* convexHull() const;
02082 void normalize();
02083 int compareToSameClass(const Geometry *p) const;
02084 const Coordinate* getCoordinate() const;
02085
02086 double getArea() const;
02087
02089 double getLength() const;
02090
02091 void apply_rw(GeometryComponentFilter *filter);
02092 void apply_ro(GeometryComponentFilter *filter) const;
02093 protected:
02094 LinearRing *shell;
02095 vector<Geometry *> *holes;
02096 Envelope* computeEnvelopeInternal() const;
02097 private:
02098 void normalize(LinearRing *ring, bool clockwise);
02099 #ifdef INT64_CONST_IS_I64
02100 static const int64 serialVersionUID = -3494792200821764533I64;
02101 #else
02102 static const int64 serialVersionUID = -3494792200821764533LL;
02103 #endif
02104 };
02105
02110 class MultiPoint: public GeometryCollection{
02111 public:
02112
02131 MultiPoint(vector<Geometry *> *newPoints, const GeometryFactory *newFactory);
02132
02133 virtual ~MultiPoint();
02134
02136 int getDimension() const;
02137
02139 int getBoundaryDimension() const;
02140
02142 Geometry* getBoundary() const;
02143
02144 string getGeometryType() const;
02145 virtual GeometryTypeId getGeometryTypeId() const;
02146
02147 bool isSimple() const;
02148 bool equalsExact(const Geometry *other, double tolerance) const;
02149 protected:
02150 const Coordinate* getCoordinate(int n) const;
02151 private:
02152 #ifdef INT64_CONST_IS_I64
02153 static const int64 serialVersionUID = -8048474874175355449I64;
02154 #else
02155 static const int64 serialVersionUID = -8048474874175355449LL;
02156 #endif
02157 };
02158
02163 class MultiLineString: public GeometryCollection{
02164 public:
02165
02185 MultiLineString(vector<Geometry *> *newLines, const GeometryFactory *newFactory);
02186
02187 virtual ~MultiLineString();
02188
02190 int getDimension() const;
02191
02197 int getBoundaryDimension() const;
02198
02200 Geometry* getBoundary() const;
02201
02202 string getGeometryType() const;
02203 virtual GeometryTypeId getGeometryTypeId() const;
02204 bool isClosed() const;
02205 bool isSimple() const;
02206 bool equalsExact(const Geometry *other, double tolerance) const;
02207 private:
02208 #ifdef INT64_CONST_IS_I64
02209 static const int64 serialVersionUID = 8166665132445433741I64;
02210 #else
02211 static const int64 serialVersionUID = 8166665132445433741LL;
02212 #endif
02213 };
02214
02219 class MultiPolygon: public GeometryCollection {
02220
02221 public:
02222
02244 MultiPolygon(vector<Geometry *> *newPolys, const GeometryFactory *newFactory);
02245
02246 virtual ~MultiPolygon();
02247
02249 int getDimension() const;
02250
02252 int getBoundaryDimension() const;
02253
02259 Geometry* getBoundary() const;
02260
02261 string getGeometryType() const;
02262 virtual GeometryTypeId getGeometryTypeId() const;
02263 bool isSimple() const;
02264 bool equalsExact(const Geometry *other, double tolerance) const;
02265 private:
02266 #ifdef INT64_CONST_IS_I64
02267 static const int64 serialVersionUID = -551033529766975875I64;
02268 #else
02269 static const int64 serialVersionUID = -551033529766975875LL;
02270 #endif
02271 };
02272
02278 class GeometryFactory {
02279 public:
02285 GeometryFactory();
02286
02293 GeometryFactory(const PrecisionModel *pm, int newSRID, CoordinateSequenceFactory *nCoordinateSequenceFactory);
02294
02301 GeometryFactory(CoordinateSequenceFactory *nCoordinateSequenceFactory);
02302
02311 GeometryFactory(const PrecisionModel *pm);
02312
02322 GeometryFactory(const PrecisionModel* pm, int newSRID);
02323
02329 GeometryFactory(const GeometryFactory &gf);
02330
02332 virtual ~GeometryFactory();
02333
02334
02335
02336 Point* createPointFromInternalCoord(const Coordinate* coord, const Geometry *exemplar) const;
02337
02339 Geometry* toGeometry(const Envelope* envelope) const;
02340
02342 const PrecisionModel* getPrecisionModel() const;
02343
02345 Point* createPoint() const;
02346
02348 Point* createPoint(const Coordinate& coordinate) const;
02349
02351 Point* createPoint(CoordinateSequence *coordinates) const;
02352
02354 Point* createPoint(const CoordinateSequence &coordinates) const;
02355
02357 GeometryCollection* createGeometryCollection() const;
02358
02360 GeometryCollection* createGeometryCollection(vector<Geometry *> *newGeoms) const;
02361
02363 GeometryCollection* createGeometryCollection(const vector<Geometry *> &newGeoms) const;
02364
02366 MultiLineString* createMultiLineString() const;
02367
02369 MultiLineString* createMultiLineString(vector<Geometry *> *newLines) const;
02370
02372 MultiLineString* createMultiLineString(const vector<Geometry *> &fromLines) const;
02373
02375 MultiPolygon* createMultiPolygon() const;
02376
02378 MultiPolygon* createMultiPolygon(vector<Geometry *> *newPolys) const;
02379
02381 MultiPolygon* createMultiPolygon(const vector<Geometry *> &fromPolys) const;
02382
02384 LinearRing* createLinearRing() const;
02385
02387 LinearRing* createLinearRing(CoordinateSequence* newCoords) const;
02388
02390 LinearRing* createLinearRing(const CoordinateSequence& coordinates) const;
02391
02393 MultiPoint* createMultiPoint() const;
02394
02396 MultiPoint* createMultiPoint(vector<Geometry *> *newPoints) const;
02397
02399 MultiPoint* createMultiPoint(const vector<Geometry *> &fromPoints) const;
02400
02402 MultiPoint* createMultiPoint(const CoordinateSequence &fromCoords) const;
02403
02405 Polygon* createPolygon() const;
02406
02408 Polygon* createPolygon(LinearRing *shell, vector<Geometry *> *holes) const;
02409
02411 Polygon* createPolygon(const LinearRing &shell, const vector<Geometry *> &holes) const;
02412
02414 LineString* createLineString() const;
02415
02417 LineString* createLineString(CoordinateSequence* coordinates) const;
02418
02420 LineString* createLineString(const CoordinateSequence& coordinates) const;
02421
02423 Geometry* buildGeometry(vector<Geometry *> *geoms) const;
02424
02426 Geometry* buildGeometry(const vector<Geometry *> &geoms) const;
02427
02428 int getSRID() const {return SRID;};
02429
02430 const CoordinateSequenceFactory* getCoordinateSequenceFactory() const {return coordinateListFactory;};
02431
02433 Geometry* createGeometry(const Geometry *g) const;
02434
02436 void destroyGeometry(Geometry *g) const;
02437
02438 private:
02439 const PrecisionModel* precisionModel;
02440 int SRID;
02441 #ifdef INT64_CONST_IS_I64
02442 static const int64 serialVersionUID = -6820524753094095635I64;
02443 #else
02444 static const int64 serialVersionUID = -6820524753094095635LL;
02445 #endif
02446 const CoordinateSequenceFactory *coordinateListFactory;
02447 };
02448
02449
02450
02451
02452
02453 class Triangle {
02454 public:
02455 Coordinate p0,p1,p2;
02456 Triangle(const Coordinate& nP0,const Coordinate& nP1,const Coordinate& nP2);
02464 Coordinate* inCentre();
02465 };
02466
02467 }
02468 #endif
02469
02470
02471
02472
02473
02474
02475
02476
02477
02478
02479
02480
02481
02482
02483
02484
02485
02486
02487
02488
02489
02490
02491
02492
02493
02494
02495
02496
02497
02498
02499
02500
02501
02502
02503
02504
02505
02506
02507
02508
02509
02510
02511
02512
02513
02514
02515
02516
02517
02518
02519
02520
02521
02522
02523
02524
02525
02526
02527
02528
02529
02530
02531
02532
02533
02534
02535
02536
02537
02538