00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
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
00319
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
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374 PrecisionModel(double newScale, double newOffsetX, double newOffsetY);
00375
00387 PrecisionModel(double newScale);
00388
00389
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
00436
00437
00438
00439
00440
00441 double getOffsetX() const;
00442
00443
00444
00445
00446
00447
00448
00449
00450 double getOffsetY() const;
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460 void toInternal(const Coordinate& external, Coordinate* internal) const;
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471 Coordinate* toInternal(const Coordinate& external) const;
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481 Coordinate* toExternal(const Coordinate& internal) const;
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491
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
00544
00545 virtual ~Coordinate(){};
00546
00547
00548
00549
00550
00551
00552
00553 string toString() const;
00554
00555
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
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
00672
00673
00674
00675
00676
00677
00678
00679
00680
00681
00682
00683
00684
00685
00686
00687
00688
00689
00690
00691
00692
00693
00694
00695
00696
00697
00698
00699
00700
00701
00702
00703
00704
00705
00706
00707
00708
00709
00710
00711
00712
00713
00714
00715
00716
00717
00718
00719
00720
00721
00722
00723
00724
00725
00726
00727
00728
00729
00730
00731
00732
00733
00734
00735
00755 class CoordinateSequence {
00756 public:
00757 virtual ~CoordinateSequence(){};
00758
00762 virtual CoordinateSequence *clone() const=0;
00763
00770
00771 virtual const Coordinate& getAt(int i) const=0;
00772
00777
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
00826
00827
00829
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
00897
00898
00899
00900 DefaultCoordinateSequence(const DefaultCoordinateSequence &cl);
00901
00902 CoordinateSequence *clone() const;
00903
00904
00905 const Coordinate& getAt(int pos) const;
00906
00907
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
00975
00976
00977
00978
00979
00980
00981
00982
00983
00993 virtual CoordinateSequence *create(vector<Coordinate> *coordinates) const=0;
00994 };
00995
01003 class DefaultCoordinateSequenceFactory: public CoordinateSequenceFactory {
01004
01005 public:
01006
01007
01008
01009
01010
01011
01012
01013
01014
01015
01020 CoordinateSequence *create(vector<Coordinate> *coords) const;
01021
01025 static const CoordinateSequenceFactory *instance();
01026 };
01027
01028
01029
01030
01031
01032
01033
01034 class PointCoordinateSequenceFactory: public CoordinateSequenceFactory {
01035 public:
01036
01037 CoordinateSequence *create(vector<Coordinate> *coords) const;
01038 };
01039
01040
01041
01042
01043
01044
01045
01046
01047
01048
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
01067
01068
01069
01070
01071
01072
01073
01074
01075
01076
01077
01078 class GeometryComponentFilter {
01079 public:
01085
01086 virtual void filter_rw(Geometry *geom);
01087 virtual void filter_ro(const Geometry *geom);
01088 };
01089
01090
01091
01092
01093
01094
01095
01096
01097 class Dimension {
01098 public:
01099 enum {
01100 DONTCARE=-3,
01101 True,
01102 False,
01103 P,
01104 L,
01105 A
01106 };
01107
01108
01109
01110
01111
01112
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
01328
01329
01330
01331
01332
01333
01334
01335
01336
01337
01338
01339
01340
01341
01342 virtual int getSRID() const;
01343
01344
01345
01346
01347
01348
01349 virtual void setSRID(int newSRID);
01350
01355 virtual const PrecisionModel* getPrecisionModel() const;
01356
01358 virtual const Coordinate* getCoordinate() const=0;
01359
01365 virtual CoordinateSequence* getCoordinates() const=0;
01366
01368 virtual int getNumPoints() const=0;
01369
01371 virtual bool isSimple() const=0;
01372
01374 virtual string getGeometryType() const=0;
01375
01377 virtual GeometryTypeId getGeometryTypeId() const=0;
01378
01388 virtual bool isValid() const;
01389
01391 virtual bool isEmpty() const=0;
01392
01394 virtual int getDimension() const=0;
01395
01401 virtual Geometry* getBoundary() const=0;
01402
01404 virtual int getBoundaryDimension() const=0;
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
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;
01523
01524 virtual void apply_rw(CoordinateFilter *filter)=0;
01525 virtual void apply_ro(CoordinateFilter *filter) const=0;
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;
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
01562
01563
01564
01565 virtual void geometryChanged();
01566
01567
01568
01569
01570
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
01587
01588
01589
01590
01595 virtual bool isEquivalentClass(const Geometry *other) const;
01596
01597 static void checkNotGeometryCollection(const Geometry *g);
01598
01599
01600 virtual Envelope* computeEnvelopeInternal() const=0;
01601 virtual int compareToSameClass(const Geometry *geom) const=0;
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
01633
01634
01635
01636
01637
01638
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
01654
01655
01656
01657
01658
01659
01660
01661
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
01787
01788
01789
01790
01791
01792 class Location {
01793 public:
01794 enum {
01798 UNDEF=-1,
01799
01804 INTERIOR,
01810 BOUNDARY,
01816 EXTERIOR = 2
01817 };
01818
01819
01820
01821
01822 static char toLocationSymbol(int locationValue);
01823 };
01824
01825
01826
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();
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
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
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;
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;
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
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
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
02561
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