00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef GEOS_GEOM_H
00017 #define GEOS_GEOM_H
00018
00019 #include <memory>
00020 #include <iostream>
00021 #include <string>
00022 #include <vector>
00023 #include <algorithm>
00024 #include <map>
00025 #include <math.h>
00026 #include <geos/platform.h>
00027
00028 using namespace std;
00029
00033 namespace geos {
00034
00036 string geosversion();
00037
00043 string jtsport();
00044
00046 enum GeometryTypeId {
00048 GEOS_POINT,
00050 GEOS_LINESTRING,
00052 GEOS_LINEARRING,
00054 GEOS_POLYGON,
00056 GEOS_MULTIPOINT,
00058 GEOS_MULTILINESTRING,
00060 GEOS_MULTIPOLYGON,
00062 GEOS_GEOMETRYCOLLECTION
00063 };
00064
00065 class Coordinate;
00066
00108 class PrecisionModel {
00109 friend class Unload;
00110 public:
00112
00113
00114
00115
00116 typedef enum {
00117
00124 FIXED,
00125
00131 FLOATING,
00132
00138 FLOATING_SINGLE
00139
00140 } Type;
00141
00143 PrecisionModel(void);
00144
00146
00151 PrecisionModel(Type nModelType);
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169 PrecisionModel(double newScale, double newOffsetX, double newOffsetY);
00170
00182 PrecisionModel(double newScale);
00183
00184
00185 PrecisionModel(const PrecisionModel &pm);
00186
00188 virtual ~PrecisionModel(void);
00189
00190
00192
00197 static const double maximumPreciseValue;
00198
00200 double makePrecise(double val) const;
00201
00203 void makePrecise(Coordinate *coord) const;
00204
00206
00210 bool isFloating() const;
00211
00213
00218 int getMaximumSignificantDigits() const;
00219
00221
00224 Type getType() const;
00225
00227 double getScale() const;
00228
00229
00230
00231
00232
00233
00234
00235
00236 double getOffsetX() const;
00237
00238
00239
00240
00241
00242
00243
00244
00245 double getOffsetY() const;
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255 void toInternal(const Coordinate& external, Coordinate* internal) const;
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266 Coordinate* toInternal(const Coordinate& external) const;
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276 Coordinate* toExternal(const Coordinate& internal) const;
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288 void toExternal(const Coordinate& internal, Coordinate* external) const;
00289
00290 string toString() const;
00291
00293
00307 int compareTo(const PrecisionModel* other) const;
00308
00309 private:
00310 void setScale(double newScale);
00311 Type modelType;
00312 double scale;
00313 #ifdef INT64_CONST_IS_I64
00314 static const int64 serialVersionUID = 7777263578777803835I64;
00315 #else
00316 static const int64 serialVersionUID = 7777263578777803835LL;
00317 #endif
00318 };
00319
00340 class Coordinate {
00341 public:
00342
00343
00344 virtual ~Coordinate(){};
00345
00346
00347
00348
00349
00350
00351
00352 string toString() const;
00353
00354
00355 static Coordinate nullCoord;
00356
00357 void Coordinate::setNull() {
00358 x=DoubleNotANumber;
00359 y=DoubleNotANumber;
00360 z=DoubleNotANumber;
00361 }
00362
00363 static Coordinate& Coordinate::getNull() {
00364 return nullCoord;
00365 }
00366
00367 Coordinate::Coordinate() {
00368 x=0.0;
00369 y=0.0;
00370 z=DoubleNotANumber;
00371 }
00372
00373 Coordinate::Coordinate(double xNew, double yNew, double zNew) {
00374 x=xNew;
00375 y=yNew;
00376 z=zNew;
00377 }
00378
00379 Coordinate::Coordinate(const Coordinate& c){
00380 x=c.x;
00381 y=c.y;
00382 z=c.z;
00383 }
00384
00385 Coordinate::Coordinate(double xNew, double yNew){
00386 x=xNew;
00387 y=yNew;
00388 z=DoubleNotANumber;
00389 }
00390
00391 void Coordinate::setCoordinate(const Coordinate& other) {
00392 x = other.x;
00393 y = other.y;
00394 z = other.z;
00395 }
00396
00397 bool Coordinate::equals2D(const Coordinate& other) const {
00398 if (x != other.x) {
00399 return false;
00400 }
00401 if (y != other.y) {
00402 return false;
00403 }
00404 return true;
00405 }
00406
00407 int Coordinate::compareTo(const Coordinate& other) const {
00408 if (x < other.x) {
00409 return -1;
00410 }
00411 if (x > other.x) {
00412 return 1;
00413 }
00414 if (y < other.y) {
00415 return -1;
00416 }
00417 if (y > other.y) {
00418 return 1;
00419 }
00420 return 0;
00421 }
00422
00423 bool Coordinate::equals3D(const Coordinate& other) const {
00424 return (x == other.x) && ( y == other.y) && ((z == other.z)||(ISNAN(z) && ISNAN(other.z)));
00425 }
00426
00427 void Coordinate::makePrecise(const PrecisionModel *precisionModel) {
00428 x = precisionModel->makePrecise(x);
00429 y = precisionModel->makePrecise(y);
00430 }
00431
00432 double Coordinate::distance(const Coordinate& p) const {
00433 double dx = x - p.x;
00434 double dy = y - p.y;
00435 return sqrt(dx * dx + dy * dy);
00436 }
00437
00438 int Coordinate::hashCode() {
00439
00440 int result = 17;
00441 result = 37 * result + hashCode(x);
00442 result = 37 * result + hashCode(y);
00443 return result;
00444 }
00445
00450 static int Coordinate::hashCode(double x) {
00451 int64 f = (int64)(x);
00452 return (int)(f^(f>>32));
00453 }
00454
00455
00457 double x;
00459 double y;
00461 double z;
00462
00463 private:
00464 #ifdef INT64_CONST_IS_I64
00465 static const int64 serialVersionUID=6683108902428366910I64;
00466 #else
00467 static const int64 serialVersionUID=6683108902428366910LL;
00468 #endif
00469
00470 };
00471
00472
00473
00474
00475
00476
00477
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
00557 class CoordinateSequence {
00558 public:
00559 virtual ~CoordinateSequence(){};
00560
00564 virtual CoordinateSequence *clone() const=0;
00565
00572
00573 virtual const Coordinate& getAt(int i) const=0;
00574
00579
00580 virtual int getSize() const=0;
00581
00591 virtual const vector<Coordinate>* toVector() const=0;
00592
00600 void add(const vector<Coordinate>* vc, bool allowRepeated);
00601
00602
00603 void add(CoordinateSequence *cl,bool allowRepeated,bool direction);
00604
00613 void add(const CoordinateSequence *cl,bool allowRepeated,bool direction);
00614
00622 void add(const Coordinate& c,bool allowRepeated);
00623
00625 virtual bool isEmpty() const=0;
00626
00628 virtual void add(const Coordinate& c)=0;
00629
00630
00631
00632
00634
00635
00637 virtual void setAt(const Coordinate& c, int pos)=0;
00638
00640 virtual void deleteAt(int pos)=0;
00641
00643 virtual string toString() const=0;
00644
00646 virtual void setPoints(const vector<Coordinate> &v)=0;
00647
00649 bool hasRepeatedPoints() const;
00650
00652 const Coordinate* minCoordinate() const;
00653
00654
00656 static CoordinateSequence* removeRepeatedPoints(const CoordinateSequence *cl);
00657
00662 static bool hasRepeatedPoints(const CoordinateSequence *cl);
00663
00668 static CoordinateSequence* atLeastNCoordinatesOrNothing(int n, CoordinateSequence *c);
00669
00675 static const Coordinate* minCoordinate(CoordinateSequence *cl);
00676
00678 static int indexOf(const Coordinate *coordinate, const CoordinateSequence *cl);
00684 static bool equals(CoordinateSequence *cl1, CoordinateSequence *cl2);
00685
00687 static void scroll(CoordinateSequence *cl, const Coordinate *firstCoordinate);
00688
00690 static void reverse(CoordinateSequence *cl);
00691
00692 };
00693
00699 class DefaultCoordinateSequence : public CoordinateSequence {
00700 public:
00701
00702 DefaultCoordinateSequence(const DefaultCoordinateSequence &cl);
00703
00704 CoordinateSequence *clone() const;
00705
00706
00707 const Coordinate& getAt(int pos) const;
00708
00709
00710 int getSize() const;
00711 const vector<Coordinate>* toVector() const;
00712
00714 DefaultCoordinateSequence();
00715
00717 DefaultCoordinateSequence(vector<Coordinate> *coords);
00718
00720 DefaultCoordinateSequence(int n);
00721
00722 virtual ~DefaultCoordinateSequence();
00723
00724 bool isEmpty() const;
00725 void add(const Coordinate& c);
00726 void setAt(const Coordinate& c, int pos);
00727 void deleteAt(int pos);
00728 string toString() const;
00729 void setPoints(const vector<Coordinate> &v);
00730 private:
00731 vector<Coordinate> *vect;
00732 };
00733
00734 struct point_3d {
00735 double x;
00736 double y;
00737 double z;
00738 };
00739
00740 class PointCoordinateSequence : public CoordinateSequence {
00741 public:
00742 PointCoordinateSequence();
00743 PointCoordinateSequence(int n);
00744 PointCoordinateSequence(const Coordinate& c);
00745 PointCoordinateSequence(const PointCoordinateSequence &cl);
00746 PointCoordinateSequence(const CoordinateSequence *c);
00747 virtual ~PointCoordinateSequence();
00748 CoordinateSequence *clone() const;
00749 bool isEmpty() const;
00750 void add(const Coordinate& c);
00751 void add(point_3d p);
00752 int getSize() const;
00753 const Coordinate& getAt(int pos) const;
00754 point_3d getPointAt(int pos);
00755 void setAt(const Coordinate& c, int pos);
00756 void setAt(point_3d p, int pos);
00757 void deleteAt(int pos);
00758 const vector<Coordinate>* toVector() const;
00759 vector<point_3d>* toPointVector();
00760 string toString() const;
00761 void setPoints(const vector<Coordinate> &v);
00762 void setPoints(vector<point_3d> &v);
00763 private:
00764 vector<point_3d> *vect;
00765 mutable vector<Coordinate>*cached_vector;
00766 };
00767
00775 class CoordinateSequenceFactory {
00776 public:
00777
00778
00779
00780
00781
00782
00783
00784
00785
00786
00796 virtual CoordinateSequence *create(vector<Coordinate> *coordinates) const=0;
00797 };
00798
00806 class DefaultCoordinateSequenceFactory: public CoordinateSequenceFactory {
00807
00808 public:
00809
00810
00811
00812
00813
00814
00815
00816
00817
00818
00823 CoordinateSequence *create(vector<Coordinate> *coords) const;
00824
00828 static const CoordinateSequenceFactory *instance();
00829 };
00830
00831
00832
00833
00834
00835
00836
00837 class PointCoordinateSequenceFactory: public CoordinateSequenceFactory {
00838 public:
00839
00840 CoordinateSequence *create(vector<Coordinate> *coords) const;
00841 };
00842
00843
00844
00845
00846
00847
00848
00849
00850
00851
00852
00853
00854 class CoordinateFilter {
00855 public:
00856 virtual ~CoordinateFilter() {}
00862 virtual void filter_rw(Coordinate* coord)=0;
00863 virtual void filter_ro(const Coordinate* coord)=0;
00864 };
00865
00866 class Geometry;
00867
00868
00869
00870
00871
00872
00873
00874
00875
00876
00877
00878
00879
00880
00881 class GeometryComponentFilter {
00882 public:
00888
00889 virtual void filter_rw(Geometry *geom);
00890 virtual void filter_ro(const Geometry *geom);
00891 };
00892
00893
00894
00895
00896
00897
00898
00899
00900 class Dimension {
00901 public:
00902 enum {
00903 DONTCARE=-3,
00904 True,
00905 False,
00906 P,
00907 L,
00908 A
00909 };
00910
00911
00912
00913
00914
00915
00916 static char toDimensionSymbol(int dimensionValue);
00917 static int toDimensionValue(char dimensionSymbol);
00918 };
00919
00937 class Envelope {
00938 public:
00939 Envelope(void);
00940 Envelope(double x1, double x2, double y1, double y2);
00941 Envelope(const Coordinate& p1, const Coordinate& p2);
00942 Envelope(const Coordinate& p);
00943 Envelope(const Envelope &env);
00944 virtual ~Envelope(void);
00945 static bool intersects(const Coordinate& p1,const Coordinate& p2,const Coordinate& q);
00946 static bool intersects(const Coordinate& p1,const Coordinate& p2,const Coordinate& q1,const Coordinate& q2);
00947 void init(void);
00948 void init(double x1, double x2, double y1, double y2);
00949 void init(const Coordinate& p1, const Coordinate& p2);
00950 void init(const Coordinate& p);
00951 void init(Envelope env);
00952 void setToNull(void);
00953 bool isNull(void) const;
00954 double getWidth(void) const;
00955 double getHeight(void) const;
00956 double getMaxY() const;
00957 double getMaxX() const;
00958 double getMinY() const;
00959 double getMinX() const;
00960 void expandToInclude(const Coordinate& p);
00961 void expandToInclude(double x, double y);
00962 void expandToInclude(const Envelope* other);
00963 bool contains(const Coordinate& p) const;
00964 bool contains(double x, double y) const;
00965 bool contains(const Envelope* other) const;
00966 bool overlaps(const Coordinate& p) const;
00967 bool overlaps(double x, double y) const;
00968 bool overlaps(const Envelope* other) const;
00969 bool intersects(const Coordinate& p) const;
00970 bool intersects(double x, double y) const;
00971 bool intersects(const Envelope* other) const;
00972 bool equals(const Envelope* other) const;
00973 string toString(void) const;
00974 double distance(const Envelope* env) const;
00975 int hashCode() const;
00976
00977 private:
00978 static double distance(double x0,double y0,double x1,double y1);
00979 double minx;
00980 double maxx;
00981 double miny;
00982 double maxy;
00983 #ifdef INT64_CONST_IS_I64
00984 static const int64 serialVersionUID=5873921885273102420I64;
00985 #else
00986 static const int64 serialVersionUID=5873921885273102420LL;
00987 #endif
00988 };
00989
00990 class Geometry;
00991 class GeometryFilter;
00992 class IntersectionMatrix;
00993
00994
00995 class CGAlgorithms;
00996 class Point;
00997 class GeometryFactory;
00998
01082 class Geometry{
01083 friend class Unload;
01084 public:
01085
01086 Geometry(const Geometry &geom);
01087
01094 Geometry(const GeometryFactory *factory);
01095
01097 virtual ~Geometry();
01098
01100 virtual Geometry* clone() const=0;
01101
01109 const GeometryFactory* getFactory() const;
01110
01124 void setUserData(void* newUserData);
01125
01132 void* getUserData();
01133
01134
01135
01136
01137
01138
01139
01140
01141
01142
01143
01144
01145
01146
01147
01148
01149
01150 virtual int getSRID() const;
01151
01152
01153
01154
01155
01156
01157 virtual void setSRID(int newSRID);
01158
01163 virtual const PrecisionModel* getPrecisionModel() const;
01164
01166 virtual const Coordinate* getCoordinate() const=0;
01167
01173 virtual CoordinateSequence* getCoordinates() const=0;
01174
01176 virtual int getNumPoints() const=0;
01177
01179 virtual bool isSimple() const=0;
01180
01182 virtual string getGeometryType() const=0;
01183
01185 virtual GeometryTypeId getGeometryTypeId() const=0;
01186
01196 virtual bool isValid() const;
01197
01199 virtual bool isEmpty() const=0;
01200
01202 virtual int getDimension() const=0;
01203
01209 virtual Geometry* getBoundary() const=0;
01210
01212 virtual int getBoundaryDimension() const=0;
01213
01215 virtual Geometry* getEnvelope() const;
01216
01221 virtual const Envelope* getEnvelopeInternal() const;
01222
01228 virtual bool disjoint(const Geometry *other) const;
01229
01234 virtual bool touches(const Geometry *other) const;
01235
01237 virtual bool intersects(const Geometry *g) const;
01238
01245 virtual bool crosses(const Geometry *g) const;
01246
01251 virtual bool within(const Geometry *g) const;
01252
01254 virtual bool contains(const Geometry *g) const;
01255
01261 virtual bool overlaps(const Geometry *g) const;
01262
01274 virtual bool relate(const Geometry *g, string intersectionPattern) const;
01276 virtual IntersectionMatrix* relate(const Geometry *g) const;
01277
01283 virtual bool equals(const Geometry *g) const;
01284
01286 virtual string toString() const;
01287
01288 virtual string toText() const;
01289
01291 virtual Geometry* buffer(double distance) const;
01292
01294 virtual Geometry* buffer(double distance,int quadrantSegments) const;
01295
01297 virtual Geometry* convexHull() const;
01298
01303 virtual Geometry* intersection(const Geometry *other) const;
01304
01309 virtual Geometry* Union(const Geometry *other) const;
01310
01311
01317 virtual Geometry* difference(const Geometry *other) const;
01318
01323 virtual Geometry* symDifference(const Geometry *other) const;
01324
01329 virtual bool equalsExact(const Geometry *other, double tolerance)
01330 const=0;
01331
01332 virtual void apply_rw(CoordinateFilter *filter)=0;
01333 virtual void apply_ro(CoordinateFilter *filter) const=0;
01334 virtual void apply_rw(GeometryFilter *filter);
01335 virtual void apply_ro(GeometryFilter *filter) const;
01336 virtual void apply_rw(GeometryComponentFilter *filter);
01337 virtual void apply_ro(GeometryComponentFilter *filter) const;
01338
01340 virtual void normalize()=0;
01341
01342 virtual int compareTo(const Geometry *geom) const;
01343
01348 virtual double distance(const Geometry *g) const;
01349
01351 virtual double getArea() const;
01352
01354 virtual double getLength() const;
01355
01360 virtual bool isWithinDistance(const Geometry *geom,double cDistance);
01361
01363 virtual Point* getCentroid() const;
01364
01366 virtual Point* getInteriorPoint();
01367
01368
01369
01370
01371
01372
01373 virtual void geometryChanged();
01374
01375
01376
01377
01378
01379
01380 void geometryChangedAction();
01381
01382 protected:
01383 mutable Envelope* envelope;
01384
01386 static bool hasNonEmptyElements(const vector<Geometry *>* geometries);
01387
01389 static bool hasNullElements(const CoordinateSequence* list);
01390
01392 static bool hasNullElements(const vector<Geometry *>* lrs);
01393
01394
01395
01396
01397
01398
01403 virtual bool isEquivalentClass(const Geometry *other) const;
01404
01405 static void checkNotGeometryCollection(const Geometry *g);
01406
01407
01408 virtual Envelope* computeEnvelopeInternal() const=0;
01409 virtual int compareToSameClass(const Geometry *geom) const=0;
01410 int compare(vector<Coordinate> a, vector<Coordinate> b) const;
01411 int compare(vector<Geometry *> a, vector<Geometry *> b) const;
01412 bool equal(const Coordinate& a, const Coordinate& b,double tolerance) const;
01413 int SRID;
01414
01427 Geometry* toInternalGeometry(const Geometry *g) const;
01428 Geometry* fromInternalGeometry(const Geometry *g) const;
01429 private:
01430 virtual int getClassSortIndex() const;
01431 static GeometryComponentFilter geometryChangedFilter;
01432 #ifdef INT64_CONST_IS_I64
01433 static const int64 serialVersionUID = 8763622679187376702I64;
01434 #else
01435 static const int64 serialVersionUID = 8763622679187376702LL;
01436 #endif
01437 const GeometryFactory *factory;
01438 static const GeometryFactory* INTERNAL_GEOMETRY_FACTORY;
01439 void* userData;
01440 Point* createPointFromInternalCoord(const Coordinate* coord,const Geometry *exemplar) const;
01441 };
01442
01443
01444
01445
01446
01447
01448
01449
01450
01451
01452 class GeometryFilter {
01453 public:
01454
01455
01456
01457
01458
01459
01460 virtual void filter_ro(const Geometry *geom)=0;
01461 virtual void filter_rw(Geometry *geom)=0;
01462 };
01463
01464
01465
01466
01467
01468
01469
01470
01471
01472
01473
01474
01475
01476 class LineSegment {
01477 public:
01478 Coordinate p0;
01479 Coordinate p1;
01480 LineSegment(void);
01481 LineSegment(const LineSegment &ls);
01482 LineSegment(const Coordinate& c0, const Coordinate& c1);
01483 virtual ~LineSegment(void);
01484 virtual void setCoordinates(const Coordinate& c0, const Coordinate& c1);
01485 virtual const Coordinate& getCoordinate(int i) const;
01486 virtual void setCoordinates(const LineSegment ls);
01487 virtual double getLength() const;
01493 virtual bool isHorizontal() const;
01499 virtual bool isVertical() const;
01519 virtual int orientationIndex(LineSegment *seg) const;
01520 virtual void reverse();
01521 virtual void normalize();
01522 virtual double angle() const;
01523 virtual double distance(const LineSegment ls) const;
01527 virtual double distance(const Coordinate& p) const;
01532 virtual double distancePerpendicular(const Coordinate& p) const;
01533 virtual double projectionFactor(const Coordinate& p) const;
01534 virtual Coordinate* project(const Coordinate& p) const;
01535 virtual LineSegment* project(const LineSegment *seg) const;
01536 virtual Coordinate* closestPoint(const Coordinate& p) const;
01537 virtual int compareTo(const LineSegment other) const;
01538 virtual bool equalsTopo(const LineSegment other) const;
01539
01546 virtual CoordinateSequence* closestPoints(const LineSegment *line);
01547
01559 Coordinate* intersection(const LineSegment *line) const;
01560 virtual string toString() const;
01561 private:
01562 #ifdef INT64_CONST_IS_I64
01563 static const int64 serialVersionUID=3252005833466256227I64;
01564 #else
01565 static const int64 serialVersionUID=3252005833466256227LL;
01566 #endif
01567
01568 };
01569
01570 class IntersectionMatrix {
01571 public:
01572 IntersectionMatrix();
01573 IntersectionMatrix(string elements);
01574 IntersectionMatrix(const IntersectionMatrix &im);
01575 virtual ~IntersectionMatrix();
01576 static bool matches(int actualDimensionValue, char requiredDimensionSymbol);
01577 static bool matches(string actualDimensionSymbols, string requiredDimensionSymbols);
01578 void add(IntersectionMatrix *im);
01579 void set(int row, int column, int dimensionValue);
01580 void set(string dimensionSymbols);
01581 void setAtLeast(int row, int column, int minimumDimensionValue);
01582 void setAtLeastIfValid(int row, int column, int minimumDimensionValue);
01583 void setAtLeast(string minimumDimensionSymbols);
01584 void setAll(int dimensionValue);
01585 int get(int row, int column);
01586 bool isDisjoint();
01587 bool isIntersects();
01588 bool isTouches(int dimensionOfGeometryA, int dimensionOfGeometryB);
01589 bool isCrosses(int dimensionOfGeometryA, int dimensionOfGeometryB);
01590 bool isWithin();
01591 bool isContains();
01592 bool isEquals(int dimensionOfGeometryA, int dimensionOfGeometryB);
01593 bool isOverlaps(int dimensionOfGeometryA, int dimensionOfGeometryB);
01594 bool matches(string requiredDimensionSymbols);
01595 IntersectionMatrix* transpose();
01596 string toString();
01597 private:
01598 int matrix[3][3];
01599 };
01600
01601
01602
01603
01604
01605
01606
01607
01608 class Location {
01609 public:
01610 enum {
01614 UNDEF=-1,
01615
01620 INTERIOR,
01626 BOUNDARY,
01632 EXTERIOR = 2
01633 };
01634
01635
01636
01637
01638 static char toLocationSymbol(int locationValue);
01639 };
01640
01641
01642
01643 bool operator==(const Coordinate& a, const Coordinate& b);
01644 bool operator!=(const Coordinate& a, const Coordinate& b);
01645 bool operator==(const Envelope a, const Envelope b);
01646 bool operator==(const PrecisionModel a, const PrecisionModel b);
01647 bool operator==(const LineSegment a, const LineSegment b);
01648
01649 bool lessThen(Coordinate& a,Coordinate& b);
01650 bool greaterThen(Geometry *first, Geometry *second);
01651
01661 class GeometryCollection : public Geometry{
01662 public:
01663 GeometryCollection(const GeometryCollection &gc);
01664
01689 GeometryCollection(vector<Geometry *> *newGeoms, const GeometryFactory *newFactory);
01690
01691 virtual Geometry *clone() const;
01692
01693 virtual ~GeometryCollection();
01694
01708 virtual CoordinateSequence* getCoordinates() const;
01709
01710 virtual bool isEmpty() const;
01711
01717 virtual int getDimension() const;
01718
01719 virtual Geometry* getBoundary() const;
01720
01726 virtual int getBoundaryDimension() const;
01727
01728 virtual int getNumPoints() const;
01729 virtual string getGeometryType() const;
01730 virtual GeometryTypeId getGeometryTypeId() const;
01731 virtual bool isSimple() const;
01732 virtual bool equalsExact(const Geometry *other, double tolerance) const;
01733
01734 virtual void apply_ro(CoordinateFilter *filter) const;
01735 virtual void apply_rw(CoordinateFilter *filter);
01736 virtual void apply_ro(GeometryFilter *filter) const;
01737 virtual void apply_rw(GeometryFilter *filter);
01738 virtual void apply_ro(GeometryComponentFilter *filter) const;
01739 virtual void apply_rw(GeometryComponentFilter *filter);
01740 virtual void normalize();
01741 virtual const Coordinate* getCoordinate() const;
01743 virtual double getArea() const;
01745 virtual double getLength() const;
01747 virtual int getNumGeometries() const;
01749 virtual const Geometry* getGeometryN(int n) const;
01750 protected:
01751 vector<Geometry *>* geometries;
01752 virtual Envelope* computeEnvelopeInternal() const;
01753 virtual int compareToSameClass(const Geometry *gc) const;
01754 private:
01755 #ifdef INT64_CONST_IS_I64
01756 static const int64 serialVersionUID = -5694727726395021467I64;
01757 #else
01758 static const int64 serialVersionUID = -5694727726395021467LL;
01759 #endif
01760 };
01761
01762 class GeometryCollectionIterator {
01763 public:
01764 GeometryCollectionIterator();
01765 GeometryCollectionIterator(const GeometryCollectionIterator &gci);
01766 GeometryCollectionIterator(const GeometryCollection *newParent);
01767 virtual ~GeometryCollectionIterator();
01768 bool hasNext() const;
01769 const Geometry *next();
01770 void remove();
01771 private:
01772 const GeometryCollection* parent;
01773 bool atStart;
01774 int max;
01775 int index;
01776 GeometryCollectionIterator* subcollectionIterator;
01777 };
01778
01783 class Point : public Geometry{
01784 public:
01785
01798 Point(CoordinateSequence *newCoords, const GeometryFactory *newFactory);
01799
01800 Point(const Point &p);
01801 virtual ~Point();
01802 Geometry *clone() const;
01803 CoordinateSequence* getCoordinates(void) const;
01804 int getNumPoints() const;
01805 bool isEmpty() const;
01806 bool isSimple() const;
01807
01808
01810 int getDimension() const;
01811
01813 int getBoundaryDimension() const;
01814
01816 Geometry* getBoundary() const;
01817
01818 double getX() const;
01819 double getY() const;
01820 const Coordinate* getCoordinate() const;
01821 string getGeometryType() const;
01822 virtual GeometryTypeId getGeometryTypeId() const;
01823 void apply_ro(CoordinateFilter *filter) const;
01824 void apply_rw(CoordinateFilter *filter);
01825 void apply_ro(GeometryFilter *filter) const;
01826 void apply_rw(GeometryFilter *filter);
01827 void apply_rw(GeometryComponentFilter *filter);
01828 void apply_ro(GeometryComponentFilter *filter) const;
01829 bool equalsExact(const Geometry *other, double tolerance) const;
01830 void normalize(void) { };
01831 protected:
01832 Envelope* computeEnvelopeInternal() const;
01833 int compareToSameClass(const Geometry *p) const;
01834 private:
01838 CoordinateSequence *coordinates;
01839 #ifdef INT64_CONST_IS_I64
01840 static const int64 serialVersionUID = 4902022702746614570I64;
01841 #else
01842 static const int64 serialVersionUID = 4902022702746614570LL;
01843 #endif
01844 };
01845
01850 class LineString: public Geometry {
01851 public:
01852 LineString(const LineString &ls);
01853
01855 LineString(CoordinateSequence *pts, const GeometryFactory *newFactory);
01856
01857 virtual ~LineString();
01858 virtual Geometry *clone() const;
01859 virtual CoordinateSequence* getCoordinates() const;
01860
01862 const CoordinateSequence* getCoordinatesRO() const;
01863
01864 virtual const Coordinate& getCoordinateN(int n) const;
01865
01867 virtual int getDimension() const;
01868
01874 virtual int getBoundaryDimension() const;
01875
01881 virtual Geometry* getBoundary() const;
01882
01883 virtual bool isEmpty() const;
01884 virtual int getNumPoints() const;
01885 virtual Point* getPointN(int n) const;
01886 virtual Point* getStartPoint() const;
01887 virtual Point* getEndPoint() const;
01888 virtual bool isClosed() const;
01889 virtual bool isRing() const;
01890 virtual string getGeometryType() const;
01891 virtual GeometryTypeId getGeometryTypeId() const;
01892 virtual bool isSimple() const;
01893 virtual bool isCoordinate(Coordinate& pt) const;
01894 virtual bool equalsExact(const Geometry *other, double tolerance) const;
01895 virtual void apply_rw(CoordinateFilter *filter);
01896 virtual void apply_ro(CoordinateFilter *filter) const;
01897 virtual void apply_rw(GeometryFilter *filter);
01898 virtual void apply_ro(GeometryFilter *filter) const;
01899 virtual void apply_rw(GeometryComponentFilter *filter);
01900 virtual void apply_ro(GeometryComponentFilter *filter) const;
01901
01903 virtual void normalize();
01904
01905
01906 virtual int compareToSameClass(const Geometry *ls) const;
01907 virtual int compareTo(const LineString *ls) const;
01908 virtual const Coordinate* getCoordinate() const;
01909 virtual double getLength() const;
01910 protected:
01911 virtual Envelope* computeEnvelopeInternal() const;
01912 CoordinateSequence* points;
01913 private:
01914 #ifdef INT64_CONST_IS_I64
01915 static const int64 serialVersionUID = 3110669828065365560I64;
01916 #else
01917 static const int64 serialVersionUID = 3110669828065365560LL;
01918 #endif
01919 };
01920
01931 class LinearRing : public LineString{
01932
01933 public:
01934
01935 LinearRing(const LinearRing &lr);
01936
01948 LinearRing(CoordinateSequence* points, const GeometryFactory *newFactory);
01949
01950 virtual Geometry *clone() const;
01951 virtual ~LinearRing();
01952 bool isSimple() const;
01953 string getGeometryType() const;
01954 virtual GeometryTypeId getGeometryTypeId() const;
01955 bool isClosed() const;
01956 void setPoints(CoordinateSequence* cl);
01957 private:
01958 #ifdef INT64_CONST_IS_I64
01959 static const int64 serialVersionUID = -4261142084085851829I64;
01960 #else
01961 static const int64 serialVersionUID = -4261142084085851829LL;
01962 #endif
01963 void validateConstruction();
01964 };
01965
01981 class Polygon: public Geometry{
01982 public:
01983 Polygon(const Polygon &p);
01984 virtual ~Polygon();
01985
02004 Polygon(LinearRing *newShell, vector<Geometry *> *newHoles,
02005 const GeometryFactory *newFactory);
02006
02007 virtual Geometry *clone() const;
02008 CoordinateSequence* getCoordinates() const;
02009 int getNumPoints() const;
02010
02012 int getDimension() const;
02013
02015 int getBoundaryDimension() const;
02016
02023 Geometry* getBoundary() const;
02024
02025 bool isEmpty() const;
02026 bool isSimple() const;
02027
02029 const LineString* getExteriorRing() const;
02030
02032 int getNumInteriorRing() const;
02033
02035 const LineString* getInteriorRingN(int n) const;
02036
02037 string getGeometryType() const;
02038 virtual GeometryTypeId getGeometryTypeId() const;
02039 bool equalsExact(const Geometry *other, double tolerance) const;
02040 void apply_rw(CoordinateFilter *filter);
02041 void apply_ro(CoordinateFilter *filter) const;
02042 void apply_rw(GeometryFilter *filter);
02043 void apply_ro(GeometryFilter *filter) const;
02044 Geometry* convexHull() const;
02045 void normalize();
02046 int compareToSameClass(const Geometry *p) const;
02047 const Coordinate* getCoordinate() const;
02048
02049 double getArea() const;
02050
02052 double getLength() const;
02053
02054 void apply_rw(GeometryComponentFilter *filter);
02055 void apply_ro(GeometryComponentFilter *filter) const;
02056 protected:
02057 LinearRing *shell;
02058 vector<Geometry *> *holes;
02059 Envelope* computeEnvelopeInternal() const;
02060 private:
02061 void normalize(LinearRing *ring, bool clockwise);
02062 #ifdef INT64_CONST_IS_I64
02063 static const int64 serialVersionUID = -3494792200821764533I64;
02064 #else
02065 static const int64 serialVersionUID = -3494792200821764533LL;
02066 #endif
02067 };
02068
02073 class MultiPoint: public GeometryCollection{
02074 public:
02075
02094 MultiPoint(vector<Geometry *> *newPoints, const GeometryFactory *newFactory);
02095
02096 virtual ~MultiPoint();
02097
02099 int getDimension() const;
02100
02102 int getBoundaryDimension() const;
02103
02105 Geometry* getBoundary() const;
02106
02107 string getGeometryType() const;
02108 virtual GeometryTypeId getGeometryTypeId() const;
02109
02110 bool isSimple() const;
02111 bool equalsExact(const Geometry *other, double tolerance) const;
02112 protected:
02113 const Coordinate* getCoordinate(int n) const;
02114 private:
02115 #ifdef INT64_CONST_IS_I64
02116 static const int64 serialVersionUID = -8048474874175355449I64;
02117 #else
02118 static const int64 serialVersionUID = -8048474874175355449LL;
02119 #endif
02120 };
02121
02126 class MultiLineString: public GeometryCollection{
02127 public:
02128
02148 MultiLineString(vector<Geometry *> *newLines, const GeometryFactory *newFactory);
02149
02150 virtual ~MultiLineString();
02151
02153 int getDimension() const;
02154
02160 int getBoundaryDimension() const;
02161
02163 Geometry* getBoundary() const;
02164
02165 string getGeometryType() const;
02166 virtual GeometryTypeId getGeometryTypeId() const;
02167 bool isClosed() const;
02168 bool isSimple() const;
02169 bool equalsExact(const Geometry *other, double tolerance) const;
02170 private:
02171 #ifdef INT64_CONST_IS_I64
02172 static const int64 serialVersionUID = 8166665132445433741I64;
02173 #else
02174 static const int64 serialVersionUID = 8166665132445433741LL;
02175 #endif
02176 };
02177
02182 class MultiPolygon: public GeometryCollection {
02183
02184 public:
02185
02207 MultiPolygon(vector<Geometry *> *newPolys, const GeometryFactory *newFactory);
02208
02209 virtual ~MultiPolygon();
02210
02212 int getDimension() const;
02213
02215 int getBoundaryDimension() const;
02216
02222 Geometry* getBoundary() const;
02223
02224 string getGeometryType() const;
02225 virtual GeometryTypeId getGeometryTypeId() const;
02226 bool isSimple() const;
02227 bool equalsExact(const Geometry *other, double tolerance) const;
02228 private:
02229 #ifdef INT64_CONST_IS_I64
02230 static const int64 serialVersionUID = -551033529766975875I64;
02231 #else
02232 static const int64 serialVersionUID = -551033529766975875LL;
02233 #endif
02234 };
02235
02241 class GeometryFactory {
02242 public:
02248 GeometryFactory();
02249
02256 GeometryFactory(const PrecisionModel *pm, int newSRID, CoordinateSequenceFactory *nCoordinateSequenceFactory);
02257
02264 GeometryFactory(CoordinateSequenceFactory *nCoordinateSequenceFactory);
02265
02274 GeometryFactory(const PrecisionModel *pm);
02275
02285 GeometryFactory(const PrecisionModel* pm, int newSRID);
02286
02292 GeometryFactory(const GeometryFactory &gf);
02293
02295 virtual ~GeometryFactory();
02296
02297
02298
02299 Point* createPointFromInternalCoord(const Coordinate* coord, const Geometry *exemplar) const;
02300
02302 Geometry* toGeometry(const Envelope* envelope) const;
02303
02305 const PrecisionModel* getPrecisionModel() const;
02306
02308 Point* createPoint() const;
02309
02311 Point* createPoint(const Coordinate& coordinate) const;
02312
02314 Point* createPoint(CoordinateSequence *coordinates) const;
02315
02317 Point* createPoint(const CoordinateSequence &coordinates) const;
02318
02320 GeometryCollection* createGeometryCollection() const;
02321
02323 GeometryCollection* createGeometryCollection(vector<Geometry *> *newGeoms) const;
02324
02326 GeometryCollection* createGeometryCollection(const vector<Geometry *> &newGeoms) const;
02327
02329 MultiLineString* createMultiLineString() const;
02330
02332 MultiLineString* createMultiLineString(vector<Geometry *> *newLines) const;
02333
02335 MultiLineString* createMultiLineString(const vector<Geometry *> &fromLines) const;
02336
02338 MultiPolygon* createMultiPolygon() const;
02339
02341 MultiPolygon* createMultiPolygon(vector<Geometry *> *newPolys) const;
02342
02344 MultiPolygon* createMultiPolygon(const vector<Geometry *> &fromPolys) const;
02345
02347 LinearRing* createLinearRing() const;
02348
02350 LinearRing* createLinearRing(CoordinateSequence* newCoords) const;
02351
02353 LinearRing* createLinearRing(const CoordinateSequence& coordinates) const;
02354
02356 MultiPoint* createMultiPoint() const;
02357
02359 MultiPoint* createMultiPoint(vector<Geometry *> *newPoints) const;
02360
02362 MultiPoint* createMultiPoint(const vector<Geometry *> &fromPoints) const;
02363
02365 MultiPoint* createMultiPoint(const CoordinateSequence &fromCoords) const;
02366
02368 Polygon* createPolygon() const;
02369
02371 Polygon* createPolygon(LinearRing *shell, vector<Geometry *> *holes) const;
02372
02374 Polygon* createPolygon(const LinearRing &shell, const vector<Geometry *> &holes) const;
02375
02377 LineString* createLineString() const;
02378
02380 LineString* createLineString(CoordinateSequence* coordinates) const;
02381
02383 LineString* createLineString(const CoordinateSequence& coordinates) const;
02384
02386 Geometry* buildGeometry(vector<Geometry *> *geoms) const;
02387
02389 Geometry* buildGeometry(const vector<Geometry *> &geoms) const;
02390
02391 int getSRID() const {return SRID;};
02392
02393 const CoordinateSequenceFactory* getCoordinateSequenceFactory() const {return coordinateListFactory;};
02394
02396 Geometry* createGeometry(const Geometry *g) const;
02397
02399 void destroyGeometry(Geometry *g) const;
02400
02401 private:
02402 const PrecisionModel* precisionModel;
02403 int SRID;
02404 #ifdef INT64_CONST_IS_I64
02405 static const int64 serialVersionUID = -6820524753094095635I64;
02406 #else
02407 static const int64 serialVersionUID = -6820524753094095635LL;
02408 #endif
02409 const CoordinateSequenceFactory *coordinateListFactory;
02410 };
02411
02412
02413
02414
02415
02416 class Triangle {
02417 public:
02418 Coordinate p0,p1,p2;
02419 Triangle(const Coordinate& nP0,const Coordinate& nP1,const Coordinate& nP2);
02427 Coordinate* inCentre();
02428 };
02429
02430 }
02431 #endif
02432
02433
02434
02435
02436
02437
02438
02439
02440
02441
02442
02443
02444
02445
02446
02447
02448
02449
02450
02451
02452
02453
02454
02455
02456
02457
02458
02459
02460
02461
02462
02463
02464
02465
02466
02467
02468
02469
02470
02471
02472
02473
02474
02475
02476
02477
02478
02479
02480
02481
02482
02483
02484
02485
02486
02487
02488