00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef GEOS_GEOM_GEOMETRY_H
00022 #define GEOS_GEOM_GEOMETRY_H
00023
00024 #include <geos/platform.h>
00025 #include <geos/inline.h>
00026 #include <geos/geom/Envelope.h>
00027 #include <geos/geom/Dimension.h>
00028
00029 #include <string>
00030 #include <iostream>
00031 #include <vector>
00032 #include <memory>
00033
00034
00035 namespace geos {
00036 namespace geom {
00037 class Coordinate;
00038 class CoordinateFilter;
00039 class CoordinateSequence;
00040 class Envelope;
00041 class GeometryComponentFilter;
00042 class GeometryFactory;
00043 class GeometryFilter;
00044 class IntersectionMatrix;
00045 class PrecisionModel;
00046 class Point;
00047 }
00048 namespace io {
00049 class Unload;
00050 }
00051 }
00052
00053 namespace geos {
00054 namespace geom {
00055
00057 enum GeometryTypeId {
00059 GEOS_POINT,
00061 GEOS_LINESTRING,
00063 GEOS_LINEARRING,
00065 GEOS_POLYGON,
00067 GEOS_MULTIPOINT,
00069 GEOS_MULTILINESTRING,
00071 GEOS_MULTIPOLYGON,
00073 GEOS_GEOMETRYCOLLECTION
00074 };
00075
00159 class Geometry {
00160
00161 public:
00162
00163 friend class GeometryFactory;
00164
00165 friend std::ostream& operator<< (std::ostream& os, const Geometry& geom);
00166
00168 typedef std::vector<const Geometry *> ConstVect;
00169
00171 typedef std::vector<Geometry *> NonConstVect;
00172
00174 typedef std::auto_ptr<Geometry> AutoPtr;
00175
00177 virtual Geometry* clone() const=0;
00178
00180 virtual ~Geometry();
00181
00182
00190 const GeometryFactory* getFactory() const { return factory; }
00191
00205 void setUserData(void* newUserData) { userData=newUserData; }
00206
00213 void* getUserData() { return userData; }
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230 virtual int getSRID() const { return SRID; }
00231
00232
00233
00234
00235
00236 virtual void setSRID(int newSRID) { SRID=newSRID; }
00237
00242 const PrecisionModel* getPrecisionModel() const;
00243
00248 virtual const Coordinate* getCoordinate() const=0;
00249
00255 virtual CoordinateSequence* getCoordinates() const=0;
00256
00258 virtual size_t getNumPoints() const=0;
00259
00261 virtual bool isSimple() const=0;
00262
00264 virtual std::string getGeometryType() const=0;
00265
00267 virtual GeometryTypeId getGeometryTypeId() const=0;
00268
00271 virtual size_t getNumGeometries() const { return 1; }
00272
00275 virtual const Geometry* getGeometryN(size_t ) const { return this; }
00276
00286 virtual bool isValid() const;
00287
00289 virtual bool isEmpty() const=0;
00290
00292 virtual bool isRectangle() const { return false; }
00293
00295 virtual Dimension::DimensionType getDimension() const=0;
00296
00303 virtual Geometry* getBoundary() const=0;
00304
00306 virtual int getBoundaryDimension() const=0;
00307
00309 virtual Geometry* getEnvelope() const;
00310
00315 virtual const Envelope* getEnvelopeInternal() const;
00316
00322 virtual bool disjoint(const Geometry *other) const;
00323
00328 virtual bool touches(const Geometry *other) const;
00329
00331 virtual bool intersects(const Geometry *g) const;
00332
00339 virtual bool crosses(const Geometry *g) const;
00340
00345 virtual bool within(const Geometry *g) const;
00346
00348 virtual bool contains(const Geometry *g) const;
00349
00355 virtual bool overlaps(const Geometry *g) const;
00356
00371 virtual bool relate(const Geometry *g,
00372 const std::string& intersectionPattern) const;
00373
00374 bool relate(const Geometry& g, const std::string& intersectionPattern) const
00375 {
00376 return relate(&g, intersectionPattern);
00377 }
00378
00380 virtual IntersectionMatrix* relate(const Geometry *g) const;
00381 IntersectionMatrix* relate(const Geometry &g) const {
00382 return relate(&g);
00383 }
00384
00390 virtual bool equals(const Geometry *g) const;
00391
00429 bool covers(const Geometry* g) const;
00430
00457 bool coveredBy(const Geometry* g) const {
00458 return g->covers(this);
00459 }
00460
00461
00463 virtual std::string toString() const;
00464
00465 virtual std::string toText() const;
00466
00468
00471 virtual Geometry* buffer(double distance) const;
00472
00477
00480 virtual Geometry* buffer(double distance,int quadrantSegments) const;
00481
00518 virtual Geometry* buffer(double distance, int quadrantSegments,
00519 int endCapStyle) const;
00520
00524 virtual Geometry* convexHull() const;
00525
00534 virtual Geometry* intersection(const Geometry *other) const;
00535
00544 virtual Geometry* Union(const Geometry *other) const;
00545
00546
00556 virtual Geometry* difference(const Geometry *other) const;
00557
00566 virtual Geometry* symDifference(const Geometry *other) const;
00567
00572 virtual bool equalsExact(const Geometry *other, double tolerance=0)
00573 const=0;
00574
00575 virtual void apply_rw(const CoordinateFilter *filter)=0;
00576 virtual void apply_ro(CoordinateFilter *filter) const=0;
00577 virtual void apply_rw(GeometryFilter *filter);
00578 virtual void apply_ro(GeometryFilter *filter) const;
00579 virtual void apply_rw(GeometryComponentFilter *filter);
00580 virtual void apply_ro(GeometryComponentFilter *filter) const;
00581
00591 template <class T>
00592 void applyComponentFilter(T& f) const
00593 {
00594 for(size_t i=0, n=getNumGeometries(); i<n; ++i)
00595 f.filter(getGeometryN(i));
00596 }
00597
00599 virtual void normalize()=0;
00600
00601 virtual int compareTo(const Geometry *geom) const;
00602
00607 virtual double distance(const Geometry *g) const;
00608
00610 virtual double getArea() const;
00611
00613 virtual double getLength() const;
00614
00619 virtual bool isWithinDistance(const Geometry *geom,double cDistance);
00620
00630 virtual Point* getCentroid() const;
00631
00633
00636 virtual bool getCentroid(Coordinate& ret) const;
00637
00648 virtual Point* getInteriorPoint() const;
00649
00650
00651
00652
00653
00654
00655 virtual void geometryChanged();
00656
00662 void geometryChangedAction();
00663
00664 protected:
00665 mutable std::auto_ptr<Envelope> envelope;
00666
00668 static bool hasNonEmptyElements(const std::vector<Geometry *>* geometries);
00669
00671 static bool hasNullElements(const CoordinateSequence* list);
00672
00674 static bool hasNullElements(const std::vector<Geometry *>* lrs);
00675
00676
00677
00678
00679
00680
00685 virtual bool isEquivalentClass(const Geometry *other) const;
00686
00687 static void checkNotGeometryCollection(const Geometry *g);
00688
00689
00690
00691
00692
00693
00694 virtual Envelope::AutoPtr computeEnvelopeInternal() const=0;
00695
00696 virtual int compareToSameClass(const Geometry *geom) const=0;
00697
00698 int compare(std::vector<Coordinate> a, std::vector<Coordinate> b) const;
00699
00700 int compare(std::vector<Geometry *> a, std::vector<Geometry *> b) const;
00701
00702 bool equal(const Coordinate& a, const Coordinate& b,
00703 double tolerance) const;
00704 int SRID;
00705
00707
00708
00710
00711
00713
00714
00715 Geometry(const Geometry &geom);
00716
00723 Geometry(const GeometryFactory *factory);
00724
00725 private:
00726 int getClassSortIndex() const;
00727 static GeometryComponentFilter geometryChangedFilter;
00728 const GeometryFactory *factory;
00729 static const GeometryFactory* INTERNAL_GEOMETRY_FACTORY;
00730 void* userData;
00731 };
00732
00737 std::ostream& operator<< (std::ostream& os, const Geometry& geom);
00738
00739 struct GeometryGreaterThen {
00740 bool operator()(const Geometry *first, const Geometry *second);
00741 };
00742
00743
00745 std::string geosversion();
00746
00752 std::string jtsport();
00753
00754
00755 }
00756 }
00757
00758 #ifdef GEOS_INLINE
00759 # include <geos/geom/Geometry.inl>
00760 #endif
00761
00762 #endif // ndef GEOS_GEOM_GEOMETRY_H
00763
00764
00765
00766
00767
00768
00769
00770
00771
00772
00773
00774
00775
00776
00777
00778
00779
00780
00781
00782
00783
00784
00785
00786
00787
00788
00789
00790
00791
00792
00793
00794
00795
00796
00797
00798
00799
00800
00801
00802
00803
00804
00805
00806
00807
00808
00809
00810
00811
00812
00813
00814
00815
00816
00817
00818
00819
00820
00821
00822
00823
00824
00825
00826