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 class Coordinate {
00342 public:
00343
00344
00345 virtual ~Coordinate(){};
00346
00347
00348
00349
00350
00351
00352
00353 string toString() const;
00354
00355
00356 static Coordinate nullCoord;
00357
00358 void Coordinate::setNull() {
00359 x=DoubleNotANumber;
00360 y=DoubleNotANumber;
00361 z=DoubleNotANumber;
00362 }
00363
00364 static Coordinate& Coordinate::getNull() {
00365 return nullCoord;
00366 }
00367
00368 Coordinate::Coordinate() {
00369 x=0.0;
00370 y=0.0;
00371 z=DoubleNotANumber;
00372 }
00373
00374 Coordinate::Coordinate(double xNew, double yNew, double zNew) {
00375 x=xNew;
00376 y=yNew;
00377 z=zNew;
00378 }
00379
00380 Coordinate::Coordinate(const Coordinate& c){
00381 x=c.x;
00382 y=c.y;
00383 z=c.z;
00384 }
00385
00386 Coordinate::Coordinate(double xNew, double yNew){
00387 x=xNew;
00388 y=yNew;
00389 z=DoubleNotANumber;
00390 }
00391
00392 void Coordinate::setCoordinate(const Coordinate& other) {
00393 x = other.x;
00394 y = other.y;
00395 z = other.z;
00396 }
00397
00398 bool Coordinate::equals2D(const Coordinate& other) const {
00399 if (x != other.x) {
00400 return false;
00401 }
00402 if (y != other.y) {
00403 return false;
00404 }
00405 return true;
00406 }
00407
00408 int Coordinate::compareTo(const Coordinate& other) const {
00409 if (x < other.x) {
00410 return -1;
00411 }
00412 if (x > other.x) {
00413 return 1;
00414 }
00415 if (y < other.y) {
00416 return -1;
00417 }
00418 if (y > other.y) {
00419 return 1;
00420 }
00421 return 0;
00422 }
00423
00424 bool Coordinate::equals3D(const Coordinate& other) const {
00425 return (x == other.x) && ( y == other.y) && ((z == other.z)||(ISNAN(z) && ISNAN(other.z)));
00426 }
00427
00428 void Coordinate::makePrecise(const PrecisionModel *precisionModel) {
00429 x = precisionModel->makePrecise(x);
00430 y = precisionModel->makePrecise(y);
00431 }
00432
00433 double Coordinate::distance(const Coordinate& p) const {
00434 double dx = x - p.x;
00435 double dy = y - p.y;
00436 return sqrt(dx * dx + dy * dy);
00437 }
00438
00439 int Coordinate::hashCode() {
00440
00441 int result = 17;
00442 result = 37 * result + hashCode(x);
00443 result = 37 * result + hashCode(y);
00444 return result;
00445 }
00446
00451 static int Coordinate::hashCode(double x) {
00452 int64 f = (int64)(x);
00453 return (int)(f^(f>>32));
00454 }
00455
00456
00458 double x;
00460 double y;
00462 double z;
00463
00464 private:
00465 #ifdef INT64_CONST_IS_I64
00466 static const int64 serialVersionUID=6683108902428366910I64;
00467 #else
00468 static const int64 serialVersionUID=6683108902428366910LL;
00469 #endif
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
00538
00558 class CoordinateSequence {
00559 public:
00560 virtual ~CoordinateSequence(){};
00561
00565 virtual CoordinateSequence *clone() const=0;
00566
00573
00574 virtual const Coordinate& getAt(int i) const=0;
00575
00580
00581 virtual int getSize() const=0;
00582
00592 virtual const vector<Coordinate>* toVector() const=0;
00593
00601 void add(const vector<Coordinate>* vc, bool allowRepeated);
00602
00603
00604 void add(CoordinateSequence *cl,bool allowRepeated,bool direction);
00605
00614 void add(const CoordinateSequence *cl,bool allowRepeated,bool direction);
00615
00623 void add(const Coordinate& c,bool allowRepeated);
00624
00626 virtual bool isEmpty() const=0;
00627
00629 virtual void add(const Coordinate& c)=0;
00630
00631
00632
00633
00635
00636
00638 virtual void setAt(const Coordinate& c, int pos)=0;
00639
00641 virtual void deleteAt(int pos)=0;
00642
00644 virtual string toString() const=0;
00645
00647 virtual void setPoints(const vector<Coordinate> &v)=0;
00648
00650 bool hasRepeatedPoints() const;
00651
00653 const Coordinate* minCoordinate() const;
00654
00655
00657 static CoordinateSequence* removeRepeatedPoints(const CoordinateSequence *cl);
00658
00663 static bool hasRepeatedPoints(const CoordinateSequence *cl);
00664
00669 static CoordinateSequence* atLeastNCoordinatesOrNothing(int n, CoordinateSequence *c);
00670
00676 static const Coordinate* minCoordinate(CoordinateSequence *cl);
00677
00679 static int indexOf(const Coordinate *coordinate, const CoordinateSequence *cl);
00685 static bool equals(CoordinateSequence *cl1, CoordinateSequence *cl2);
00686
00688 static void scroll(CoordinateSequence *cl, const Coordinate *firstCoordinate);
00689
00691 static void reverse(CoordinateSequence *cl);
00692
00693 };
00694
00700 class DefaultCoordinateSequence : public CoordinateSequence {
00701 public:
00702
00703 DefaultCoordinateSequence(const DefaultCoordinateSequence &cl);
00704
00705 CoordinateSequence *clone() const;
00706
00707
00708 const Coordinate& getAt(int pos) const;
00709
00710
00711 int getSize() const;
00712 const vector<Coordinate>* toVector() const;
00713
00715 DefaultCoordinateSequence();
00716
00718 DefaultCoordinateSequence(vector<Coordinate> *coords);
00719
00721 DefaultCoordinateSequence(int n);
00722
00723 virtual ~DefaultCoordinateSequence();
00724
00725 bool isEmpty() const;
00726 void add(const Coordinate& c);
00727 void setAt(const Coordinate& c, int pos);
00728 void deleteAt(int pos);
00729 string toString() const;
00730 void setPoints(const vector<Coordinate> &v);
00731 private:
00732 vector<Coordinate> *vect;
00733 };
00734
00735 struct point_3d {
00736 double x;
00737 double y;
00738 double z;
00739 };
00740
00741 class PointCoordinateSequence : public CoordinateSequence {
00742 public:
00743 PointCoordinateSequence();
00744 PointCoordinateSequence(int n);
00745 PointCoordinateSequence(const Coordinate& c);
00746 PointCoordinateSequence(const PointCoordinateSequence &cl);
00747 PointCoordinateSequence(const CoordinateSequence *c);
00748 virtual ~PointCoordinateSequence();
00749 CoordinateSequence *clone() const;
00750 bool isEmpty() const;
00751 void add(const Coordinate& c);
00752 void add(point_3d p);
00753 int getSize() const;
00754 const Coordinate& getAt(int pos) const;
00755 point_3d getPointAt(int pos);
00756 void setAt(const Coordinate& c, int pos);
00757 void setAt(point_3d p, int pos);
00758 void deleteAt(int pos);
00759 const vector<Coordinate>* toVector() const;
00760 vector<point_3d>* toPointVector();
00761 string toString() const;
00762 void setPoints(const vector<Coordinate> &v);
00763 void setPoints(vector<point_3d> &v);
00764 private:
00765 vector<point_3d> *vect;
00766 mutable vector<Coordinate>*cached_vector;
00767 };
00768
00776 class CoordinateSequenceFactory {
00777 public:
00778
00779
00780
00781
00782
00783
00784
00785
00786
00787
00797 virtual CoordinateSequence *create(vector<Coordinate> *coordinates) const=0;
00798 };
00799
00807 class DefaultCoordinateSequenceFactory: public CoordinateSequenceFactory {
00808
00809 public:
00810
00811
00812
00813
00814
00815
00816
00817
00818
00819
00824 CoordinateSequence *create(vector<Coordinate> *coords) const;
00825
00829 static const CoordinateSequenceFactory *instance();
00830 };
00831
00832
00833
00834
00835
00836
00837
00838 class PointCoordinateSequenceFactory: public CoordinateSequenceFactory {
00839 public:
00840
00841 CoordinateSequence *create(vector<Coordinate> *coords) const;
00842 };
00843
00844
00845
00846
00847
00848
00849
00850
00851
00852
00853
00854
00855 class CoordinateFilter {
00856 public:
00857 virtual ~CoordinateFilter() {}
00863 virtual void filter_rw(Coordinate* coord)=0;
00864 virtual void filter_ro(const Coordinate* coord)=0;
00865 };
00866
00867 class Geometry;
00868
00869
00870
00871
00872
00873
00874
00875
00876
00877
00878
00879
00880
00881
00882 class GeometryComponentFilter {
00883 public:
00889
00890 virtual void filter_rw(Geometry *geom);
00891 virtual void filter_ro(const Geometry *geom);
00892 };
00893
00894
00895
00896
00897
00898
00899
00900
00901 class Dimension {
00902 public:
00903 enum {
00904 DONTCARE=-3,
00905 True,
00906 False,
00907 P,
00908 L,
00909 A
00910 };
00911
00912
00913
00914
00915
00916
00917 static char toDimensionSymbol(int dimensionValue);
00918 static int toDimensionValue(char dimensionSymbol);
00919 };
00920
00938 class Envelope {
00939 public:
00940 Envelope(void);
00941 Envelope(double x1, double x2, double y1, double y2);
00942 Envelope(const Coordinate& p1, const Coordinate& p2);
00943 Envelope(const Coordinate& p);
00944 Envelope(const Envelope &env);
00945 virtual ~Envelope(void);
00946 static bool intersects(const Coordinate& p1,const Coordinate& p2,const Coordinate& q);
00947 static bool intersects(const Coordinate& p1,const Coordinate& p2,const Coordinate& q1,const Coordinate& q2);
00948 void init(void);
00949 void init(double x1, double x2, double y1, double y2);
00950 void init(const Coordinate& p1, const Coordinate& p2);
00951 void init(const Coordinate& p);
00952 void init(Envelope env);
00953 void setToNull(void);
00954 bool isNull(void) const;
00955 double getWidth(void) const;
00956 double getHeight(void) const;
00957 double getMaxY() const;
00958 double getMaxX() const;
00959 double getMinY() const;
00960 double getMinX() const;
00961 void expandToInclude(const Coordinate& p);
00962 void expandToInclude(double x, double y);
00963 void expandToInclude(const Envelope* other);
00964 bool contains(const Coordinate& p) const;
00965 bool contains(double x, double y) const;
00966 bool contains(const Envelope* other) const;
00967 bool overlaps(const Coordinate& p) const;
00968 bool overlaps(double x, double y) const;
00969 bool overlaps(const Envelope* other) const;
00970 bool intersects(const Coordinate& p) const;
00971 bool intersects(double x, double y) const;
00972 bool intersects(const Envelope* other) const;
00973 bool equals(const Envelope* other) const;
00974 string toString(void) const;
00975 double distance(const Envelope* env) const;
00976 int hashCode() const;
00977
00978 private:
00979 static double distance(double x0,double y0,double x1,double y1);
00980 double minx;
00981 double maxx;
00982 double miny;
00983 double maxy;
00984 #ifdef INT64_CONST_IS_I64
00985 static const int64 serialVersionUID=5873921885273102420I64;
00986 #else
00987 static const int64 serialVersionUID=5873921885273102420LL;
00988 #endif
00989 };
00990
00991 class Geometry;
00992 class GeometryFilter;
00993 class IntersectionMatrix;
00994
00995
00996 class CGAlgorithms;
00997 class Point;
00998 class GeometryFactory;
00999
01083 class Geometry{
01084 friend class Unload;
01085 public:
01086
01087 Geometry(const Geometry &geom);
01088
01095 Geometry(const GeometryFactory *factory);
01096
01098 virtual ~Geometry();
01099
01101 virtual Geometry* clone() const=0;
01102
01110 const GeometryFactory* getFactory() const;
01111
01125 void setUserData(void* newUserData);
01126
01133 void* getUserData();
01134
01135
01136
01137
01138
01139
01140
01141
01142
01143
01144
01145
01146
01147
01148
01149
01150
01151 virtual int getSRID() const;
01152
01153
01154
01155
01156
01157
01158 virtual void setSRID(int newSRID);
01159
01164 virtual const PrecisionModel* getPrecisionModel() const;
01165
01167 virtual const Coordinate* getCoordinate() const=0;
01168
01174 virtual CoordinateSequence* getCoordinates() const=0;
01175
01177 virtual int getNumPoints() const=0;
01178
01180 virtual bool isSimple() const=0;
01181
01183 virtual string getGeometryType() const=0;
01184
01186 virtual GeometryTypeId getGeometryTypeId() const=0;
01187
01197 virtual bool isValid() const;
01198
01200 virtual bool isEmpty() const=0;
01201
01203 virtual int getDimension() const=0;
01204
01210 virtual Geometry* getBoundary() const=0;
01211
01213 virtual int getBoundaryDimension() const=0;
01214
01216 virtual Geometry* getEnvelope() const;
01217
01222 virtual const Envelope* getEnvelopeInternal() const;
01223
01229 virtual bool disjoint(const Geometry *other) const;
01230
01235 virtual bool touches(const Geometry *other) const;
01236
01238 virtual bool intersects(const Geometry *g) const;
01239
01246 virtual bool crosses(const Geometry *g) const;
01247
01252 virtual bool within(const Geometry *g) const;
01253
01255 virtual bool contains(const Geometry *g) const;
01256
01262 virtual bool overlaps(const Geometry *g) const;
01263
01275 virtual bool relate(const Geometry *g, string intersectionPattern) const;
01277 virtual IntersectionMatrix* relate(const Geometry *g) const;
01278
01284 virtual bool equals(const Geometry *g) const;
01285
01287 virtual string toString() const;
01288
01289 virtual string toText() const;
01290
01292 virtual Geometry* buffer(double distance) const;
01293
01295 virtual Geometry* buffer(double distance,int quadrantSegments) const;
01296
01298 virtual Geometry* convexHull() const;
01299
01304 virtual Geometry* intersection(const Geometry *other) const;
01305
01310 virtual Geometry* Union(const Geometry *other) const;
01311
01312
01318 virtual Geometry* difference(const Geometry *other) const;
01319
01324 virtual Geometry* symDifference(const Geometry *other) const;
01325
01330 virtual bool equalsExact(const Geometry *other, double tolerance)
01331 const=0;
01332
01333 virtual void apply_rw(CoordinateFilter *filter)=0;
01334 virtual void apply_ro(CoordinateFilter *filter) const=0;
01335 virtual void apply_rw(GeometryFilter *filter);
01336 virtual void apply_ro(GeometryFilter *filter) const;
01337 virtual void apply_rw(GeometryComponentFilter *filter);
01338 virtual void apply_ro(GeometryComponentFilter *filter) const;
01339
01341 virtual void normalize()=0;
01342
01343 virtual int compareTo(const Geometry *geom) const;
01344
01349 virtual double distance(const Geometry *g) const;
01350
01352 virtual double getArea() const;
01353
01355 virtual double getLength() const;
01356
01361 virtual bool isWithinDistance(const Geometry *geom,double cDistance);
01362
01364 virtual Point* getCentroid() const;
01365
01367 virtual Point* getInteriorPoint();
01368
01369
01370
01371
01372
01373
01374 virtual void geometryChanged();
01375
01376
01377
01378
01379
01380
01381 void geometryChangedAction();
01382
01383 protected:
01384 mutable Envelope* envelope;
01385
01387 static bool hasNonEmptyElements(const vector<Geometry *>* geometries);
01388
01390 static bool hasNullElements(const CoordinateSequence* list);
01391
01393 static bool hasNullElements(const vector<Geometry *>* lrs);
01394
01395
01396
01397
01398
01399
01404 virtual bool isEquivalentClass(const Geometry *other) const;
01405
01406 static void checkNotGeometryCollection(const Geometry *g);
01407
01408
01409 virtual Envelope* computeEnvelopeInternal() const=0;
01410 virtual int compareToSameClass(const Geometry *geom) const=0;
01411 int compare(vector<Coordinate> a, vector<Coordinate> b) const;
01412 int compare(vector<Geometry *> a, vector<Geometry *> b) const;
01413 bool equal(const Coordinate& a, const Coordinate& b,double tolerance) const;
01414 int SRID;
01415
01428 Geometry* toInternalGeometry(const Geometry *g) const;
01429 Geometry* fromInternalGeometry(const Geometry *g) const;
01430 private:
01431 virtual int getClassSortIndex() const;
01432 static GeometryComponentFilter geometryChangedFilter;
01433 #ifdef INT64_CONST_IS_I64
01434 static const int64 serialVersionUID = 8763622679187376702I64;
01435 #else
01436 static const int64 serialVersionUID = 8763622679187376702LL;
01437 #endif
01438 const GeometryFactory *factory;
01439 static const GeometryFactory* INTERNAL_GEOMETRY_FACTORY;
01440 void* userData;
01441 Point* createPointFromInternalCoord(const Coordinate* coord,const Geometry *exemplar) const;
01442 };
01443
01444
01445
01446
01447
01448
01449
01450
01451
01452
01453 class GeometryFilter {
01454 public:
01455
01456
01457
01458
01459
01460
01461 virtual void filter_ro(const Geometry *geom)=0;
01462 virtual void filter_rw(Geometry *geom)=0;
01463 };
01464
01465
01466
01467
01468
01469
01470
01471
01472
01473
01474
01475
01476
01477 class LineSegment {
01478 public:
01479 Coordinate p0;
01480 Coordinate p1;
01481 LineSegment(void);
01482 LineSegment(const LineSegment &ls);
01483 LineSegment(const Coordinate& c0, const Coordinate& c1);
01484 virtual ~LineSegment(void);
01485 virtual void setCoordinates(const Coordinate& c0, const Coordinate& c1);
01486 virtual const Coordinate& getCoordinate(int i) const;
01487 virtual void setCoordinates(const LineSegment ls);
01488 virtual double getLength() const;
01494 virtual bool isHorizontal() const;
01500 virtual bool isVertical() const;
01520 virtual int orientationIndex(LineSegment *seg) const;
01521 virtual void reverse();
01522 virtual void normalize();
01523 virtual double angle() const;
01524 virtual double distance(const LineSegment ls) const;
01528 virtual double distance(const Coordinate& p) const;
01533 virtual double distancePerpendicular(const Coordinate& p) const;
01534 virtual double projectionFactor(const Coordinate& p) const;
01535 virtual Coordinate* project(const Coordinate& p) const;
01536 virtual LineSegment* project(const LineSegment *seg) const;
01537 virtual Coordinate* closestPoint(const Coordinate& p) const;
01538 virtual int compareTo(const LineSegment other) const;
01539 virtual bool equalsTopo(const LineSegment other) const;
01540
01547 virtual CoordinateSequence* closestPoints(const LineSegment *line);
01548
01560 Coordinate* intersection(const LineSegment *line) const;
01561 virtual string toString() const;
01562 private:
01563 #ifdef INT64_CONST_IS_I64
01564 static const int64 serialVersionUID=3252005833466256227I64;
01565 #else
01566 static const int64 serialVersionUID=3252005833466256227LL;
01567 #endif
01568
01569 };
01570
01571 class IntersectionMatrix {
01572 public:
01573 IntersectionMatrix();
01574 IntersectionMatrix(string elements);
01575 IntersectionMatrix(const IntersectionMatrix &im);
01576 virtual ~IntersectionMatrix();
01577 static bool matches(int actualDimensionValue, char requiredDimensionSymbol);
01578 static bool matches(string actualDimensionSymbols, string requiredDimensionSymbols);
01579 void add(IntersectionMatrix *im);
01580 void set(int row, int column, int dimensionValue);
01581 void set(string dimensionSymbols);
01582 void setAtLeast(int row, int column, int minimumDimensionValue);
01583 void setAtLeastIfValid(int row, int column, int minimumDimensionValue);
01584 void setAtLeast(string minimumDimensionSymbols);
01585 void setAll(int dimensionValue);
01586 int get(int row, int column);
01587 bool isDisjoint();
01588 bool isIntersects();
01589 bool isTouches(int dimensionOfGeometryA, int dimensionOfGeometryB);
01590 bool isCrosses(int dimensionOfGeometryA, int dimensionOfGeometryB);
01591 bool isWithin();
01592 bool isContains();
01593 bool isEquals(int dimensionOfGeometryA, int dimensionOfGeometryB);
01594 bool isOverlaps(int dimensionOfGeometryA, int dimensionOfGeometryB);
01595 bool matches(string requiredDimensionSymbols);
01596 IntersectionMatrix* transpose();
01597 string toString();
01598 private:
01599 int matrix[3][3];
01600 };
01601
01602
01603
01604
01605
01606
01607
01608
01609 class Location {
01610 public:
01611 enum {
01615 UNDEF=-1,
01616
01621 INTERIOR,
01627 BOUNDARY,
01633 EXTERIOR = 2
01634 };
01635
01636
01637
01638
01639 static char toLocationSymbol(int locationValue);
01640 };
01641
01642
01643
01644 bool operator==(const Coordinate& a, const Coordinate& b);
01645 bool operator!=(const Coordinate& a, const Coordinate& b);
01646 bool operator==(const Envelope a, const Envelope b);
01647 bool operator==(const PrecisionModel a, const PrecisionModel b);
01648 bool operator==(const LineSegment a, const LineSegment b);
01649
01650 bool lessThen(Coordinate& a,Coordinate& b);
01651 bool greaterThen(Geometry *first, Geometry *second);
01652
01662 class GeometryCollection : public Geometry{
01663 public:
01664 GeometryCollection(const GeometryCollection &gc);
01665
01690 GeometryCollection(vector<Geometry *> *newGeoms, const GeometryFactory *newFactory);
01691
01692 virtual Geometry *clone() const;
01693
01694 virtual ~GeometryCollection();
01695
01709 virtual CoordinateSequence* getCoordinates() const;
01710
01711 virtual bool isEmpty() const;
01712
01718 virtual int getDimension() const;
01719
01720 virtual Geometry* getBoundary() const;
01721
01727 virtual int getBoundaryDimension() const;
01728
01729 virtual int getNumPoints() const;
01730 virtual string getGeometryType() const;
01731 virtual GeometryTypeId getGeometryTypeId() const;
01732 virtual bool isSimple() const;
01733 virtual bool equalsExact(const Geometry *other, double tolerance) const;
01734
01735 virtual void apply_ro(CoordinateFilter *filter) const;
01736 virtual void apply_rw(CoordinateFilter *filter);
01737 virtual void apply_ro(GeometryFilter *filter) const;
01738 virtual void apply_rw(GeometryFilter *filter);
01739 virtual void apply_ro(GeometryComponentFilter *filter) const;
01740 virtual void apply_rw(GeometryComponentFilter *filter);
01741 virtual void normalize();
01742 virtual const Coordinate* getCoordinate() const;
01744 virtual double getArea() const;
01746 virtual double getLength() const;
01748 virtual int getNumGeometries() const;
01750 virtual const Geometry* getGeometryN(int n) const;
01751 protected:
01752 vector<Geometry *>* geometries;
01753 virtual Envelope* computeEnvelopeInternal() const;
01754 virtual int compareToSameClass(const Geometry *gc) const;
01755 private:
01756 #ifdef INT64_CONST_IS_I64
01757 static const int64 serialVersionUID = -5694727726395021467I64;
01758 #else
01759 static const int64 serialVersionUID = -5694727726395021467LL;
01760 #endif
01761 };
01762
01763 class GeometryCollectionIterator {
01764 public:
01765 GeometryCollectionIterator();
01766 GeometryCollectionIterator(const GeometryCollectionIterator &gci);
01767 GeometryCollectionIterator(const GeometryCollection *newParent);
01768 virtual ~GeometryCollectionIterator();
01769 bool hasNext() const;
01770 const Geometry *next();
01771 void remove();
01772 private:
01773 const GeometryCollection* parent;
01774 bool atStart;
01775 int max;
01776 int index;
01777 GeometryCollectionIterator* subcollectionIterator;
01778 };
01779
01784 class Point : public Geometry{
01785 public:
01786
01799 Point(CoordinateSequence *newCoords, const GeometryFactory *newFactory);
01800
01801 Point(const Point &p);
01802 virtual ~Point();
01803 Geometry *clone() const;
01804 CoordinateSequence* getCoordinates(void) const;
01805 int getNumPoints() const;
01806 bool isEmpty() const;
01807 bool isSimple() const;
01808
01809
01811 int getDimension() const;
01812
01814 int getBoundaryDimension() const;
01815
01817 Geometry* getBoundary() const;
01818
01819 double getX() const;
01820 double getY() const;
01821 const Coordinate* getCoordinate() const;
01822 string getGeometryType() const;
01823 virtual GeometryTypeId getGeometryTypeId() const;
01824 void apply_ro(CoordinateFilter *filter) const;
01825 void apply_rw(CoordinateFilter *filter);
01826 void apply_ro(GeometryFilter *filter) const;
01827 void apply_rw(GeometryFilter *filter);
01828 void apply_rw(GeometryComponentFilter *filter);
01829 void apply_ro(GeometryComponentFilter *filter) const;
01830 bool equalsExact(const Geometry *other, double tolerance) const;
01831 void normalize(void) { };
01832 protected:
01833 Envelope* computeEnvelopeInternal() const;
01834 int compareToSameClass(const Geometry *p) const;
01835 private:
01839 CoordinateSequence *coordinates;
01840 #ifdef INT64_CONST_IS_I64
01841 static const int64 serialVersionUID = 4902022702746614570I64;
01842 #else
01843 static const int64 serialVersionUID = 4902022702746614570LL;
01844 #endif
01845 };
01846
01851 class LineString: public Geometry {
01852 public:
01853 LineString(const LineString &ls);
01854
01856 LineString(CoordinateSequence *pts, const GeometryFactory *newFactory);
01857
01858 virtual ~LineString();
01859 virtual Geometry *clone() const;
01860 virtual CoordinateSequence* getCoordinates() const;
01861
01863 const CoordinateSequence* getCoordinatesRO() const;
01864
01865 virtual const Coordinate& getCoordinateN(int n) const;
01866
01868 virtual int getDimension() const;
01869
01875 virtual int getBoundaryDimension() const;
01876
01882 virtual Geometry* getBoundary() const;
01883
01884 virtual bool isEmpty() const;
01885 virtual int getNumPoints() const;
01886 virtual Point* getPointN(int n) const;
01887 virtual Point* getStartPoint() const;
01888 virtual Point* getEndPoint() const;
01889 virtual bool isClosed() const;
01890 virtual bool isRing() const;
01891 virtual string getGeometryType() const;
01892 virtual GeometryTypeId getGeometryTypeId() const;
01893 virtual bool isSimple() const;
01894 virtual bool isCoordinate(Coordinate& pt) const;
01895 virtual bool equalsExact(const Geometry *other, double tolerance) const;
01896 virtual void apply_rw(CoordinateFilter *filter);
01897 virtual void apply_ro(CoordinateFilter *filter) const;
01898 virtual void apply_rw(GeometryFilter *filter);
01899 virtual void apply_ro(GeometryFilter *filter) const;
01900 virtual void apply_rw(GeometryComponentFilter *filter);
01901 virtual void apply_ro(GeometryComponentFilter *filter) const;
01902
01904 virtual void normalize();
01905
01906
01907 virtual int compareToSameClass(const Geometry *ls) const;
01908 virtual int compareTo(const LineString *ls) const;
01909 virtual const Coordinate* getCoordinate() const;
01910 virtual double getLength() const;
01911 protected:
01912 virtual Envelope* computeEnvelopeInternal() const;
01913 CoordinateSequence* points;
01914 private:
01915 #ifdef INT64_CONST_IS_I64
01916 static const int64 serialVersionUID = 3110669828065365560I64;
01917 #else
01918 static const int64 serialVersionUID = 3110669828065365560LL;
01919 #endif
01920 };
01921
01932 class LinearRing : public LineString{
01933
01934 public:
01935
01936 LinearRing(const LinearRing &lr);
01937
01949 LinearRing(CoordinateSequence* points, const GeometryFactory *newFactory);
01950
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