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 Dimension::DimensionType getDimension() const=0;
00293
00300 virtual Geometry* getBoundary() const=0;
00301
00303 virtual int getBoundaryDimension() const=0;
00304
00306 virtual Geometry* getEnvelope() const;
00307
00312 virtual const Envelope* getEnvelopeInternal() const;
00313
00319 virtual bool disjoint(const Geometry *other) const;
00320
00325 virtual bool touches(const Geometry *other) const;
00326
00328 virtual bool intersects(const Geometry *g) const;
00329
00336 virtual bool crosses(const Geometry *g) const;
00337
00342 virtual bool within(const Geometry *g) const;
00343
00345 virtual bool contains(const Geometry *g) const;
00346
00352 virtual bool overlaps(const Geometry *g) const;
00353
00368 virtual bool relate(const Geometry *g,
00369 const std::string& intersectionPattern) const;
00370
00371 bool relate(const Geometry& g, const std::string& intersectionPattern) const
00372 {
00373 return relate(&g, intersectionPattern);
00374 }
00375
00377 virtual IntersectionMatrix* relate(const Geometry *g) const;
00378 IntersectionMatrix* relate(const Geometry &g) const {
00379 return relate(&g);
00380 }
00381
00387 virtual bool equals(const Geometry *g) const;
00388
00426 bool covers(const Geometry* g) const;
00427
00454 bool coveredBy(const Geometry* g) const {
00455 return g->covers(this);
00456 }
00457
00458
00460 virtual std::string toString() const;
00461
00462 virtual std::string toText() const;
00463
00465
00468 virtual Geometry* buffer(double distance) const;
00469
00474
00477 virtual Geometry* buffer(double distance,int quadrantSegments) const;
00478
00515 virtual Geometry* buffer(double distance, int quadrantSegments,
00516 int endCapStyle) const;
00517
00521 virtual Geometry* convexHull() const;
00522
00531 virtual Geometry* intersection(const Geometry *other) const;
00532
00541 virtual Geometry* Union(const Geometry *other) const;
00542
00543
00553 virtual Geometry* difference(const Geometry *other) const;
00554
00563 virtual Geometry* symDifference(const Geometry *other) const;
00564
00569 virtual bool equalsExact(const Geometry *other, double tolerance=0)
00570 const=0;
00571
00572 virtual void apply_rw(const CoordinateFilter *filter)=0;
00573 virtual void apply_ro(CoordinateFilter *filter) const=0;
00574 virtual void apply_rw(GeometryFilter *filter);
00575 virtual void apply_ro(GeometryFilter *filter) const;
00576 virtual void apply_rw(GeometryComponentFilter *filter);
00577 virtual void apply_ro(GeometryComponentFilter *filter) const;
00578
00588 template <class T>
00589 void applyComponentFilter(T& f) const
00590 {
00591 for(size_t i=0, n=getNumGeometries(); i<n; ++i)
00592 f.filter(getGeometryN(i));
00593 }
00594
00596 virtual void normalize()=0;
00597
00598 virtual int compareTo(const Geometry *geom) const;
00599
00604 virtual double distance(const Geometry *g) const;
00605
00607 virtual double getArea() const;
00608
00610 virtual double getLength() const;
00611
00616 virtual bool isWithinDistance(const Geometry *geom,double cDistance);
00617
00627 virtual Point* getCentroid() const;
00628
00630
00633 virtual bool getCentroid(Coordinate& ret) const;
00634
00645 virtual Point* getInteriorPoint() const;
00646
00647
00648
00649
00650
00651
00652 virtual void geometryChanged();
00653
00659 void geometryChangedAction();
00660
00661 protected:
00662 mutable std::auto_ptr<Envelope> envelope;
00663
00665 static bool hasNonEmptyElements(const std::vector<Geometry *>* geometries);
00666
00668 static bool hasNullElements(const CoordinateSequence* list);
00669
00671 static bool hasNullElements(const std::vector<Geometry *>* lrs);
00672
00673
00674
00675
00676
00677
00682 virtual bool isEquivalentClass(const Geometry *other) const;
00683
00684 static void checkNotGeometryCollection(const Geometry *g);
00685
00686
00687
00688
00689
00690
00691 virtual Envelope::AutoPtr computeEnvelopeInternal() const=0;
00692
00693 virtual int compareToSameClass(const Geometry *geom) const=0;
00694
00695 int compare(std::vector<Coordinate> a, std::vector<Coordinate> b) const;
00696
00697 int compare(std::vector<Geometry *> a, std::vector<Geometry *> b) const;
00698
00699 bool equal(const Coordinate& a, const Coordinate& b,
00700 double tolerance) const;
00701 int SRID;
00702
00704
00705
00707
00708
00710 virtual bool isRectangle() const { return false; }
00711
00712 Geometry(const Geometry &geom);
00713
00720 Geometry(const GeometryFactory *factory);
00721
00722 private:
00723 int getClassSortIndex() const;
00724 static GeometryComponentFilter geometryChangedFilter;
00725 const GeometryFactory *factory;
00726 static const GeometryFactory* INTERNAL_GEOMETRY_FACTORY;
00727 void* userData;
00728 };
00729
00734 std::ostream& operator<< (std::ostream& os, const Geometry& geom);
00735
00736 struct GeometryGreaterThen {
00737 bool operator()(const Geometry *first, const Geometry *second);
00738 };
00739
00740
00742 std::string geosversion();
00743
00749 std::string jtsport();
00750
00751
00752 }
00753 }
00754
00755 #ifdef GEOS_INLINE
00756 # include <geos/geom/Geometry.inl>
00757 #endif
00758
00759 #endif // ndef GEOS_GEOM_GEOMETRY_H
00760
00761
00762
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