00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef GEOS_GEOM_GEOMETRY_H
00023 #define GEOS_GEOM_GEOMETRY_H
00024
00025 #include <geos/export.h>
00026 #include <geos/platform.h>
00027 #include <geos/inline.h>
00028 #include <geos/geom/Envelope.h>
00029 #include <geos/geom/Dimension.h>
00030 #include <geos/geom/GeometryComponentFilter.h>
00031
00032 #include <string>
00033 #include <iostream>
00034 #include <vector>
00035 #include <memory>
00036
00037
00038 namespace geos {
00039 namespace geom {
00040 class Coordinate;
00041 class CoordinateFilter;
00042 class CoordinateSequence;
00043 class CoordinateSequenceFilter;
00044 class Envelope;
00045 class GeometryComponentFilter;
00046 class GeometryFactory;
00047 class GeometryFilter;
00048 class IntersectionMatrix;
00049 class PrecisionModel;
00050 class Point;
00051 }
00052 namespace io {
00053 class Unload;
00054 }
00055 }
00056
00057 namespace geos {
00058 namespace geom {
00059
00061 enum GeometryTypeId {
00063 GEOS_POINT,
00065 GEOS_LINESTRING,
00067 GEOS_LINEARRING,
00069 GEOS_POLYGON,
00071 GEOS_MULTIPOINT,
00073 GEOS_MULTILINESTRING,
00075 GEOS_MULTIPOLYGON,
00077 GEOS_GEOMETRYCOLLECTION
00078 };
00079
00163 class GEOS_DLL Geometry {
00164
00165 public:
00166
00167 friend class GeometryFactory;
00168
00169 friend std::ostream& operator<< (std::ostream& os, const Geometry& geom);
00170
00172 typedef std::vector<const Geometry *> ConstVect;
00173
00175 typedef std::vector<Geometry *> NonConstVect;
00176
00178 typedef std::auto_ptr<Geometry> AutoPtr;
00179
00181 virtual Geometry* clone() const=0;
00182
00184 virtual ~Geometry();
00185
00186
00194 const GeometryFactory* getFactory() const { return factory; }
00195
00209 void setUserData(void* newUserData) { userData=newUserData; }
00210
00217 void* getUserData() { return userData; }
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234 virtual int getSRID() const { return SRID; }
00235
00236
00237
00238
00239
00240 virtual void setSRID(int newSRID) { SRID=newSRID; }
00241
00246 const PrecisionModel* getPrecisionModel() const;
00247
00252 virtual const Coordinate* getCoordinate() const=0;
00253
00259 virtual CoordinateSequence* getCoordinates() const=0;
00260
00262 virtual size_t getNumPoints() const=0;
00263
00265 virtual bool isSimple() const;
00266
00268 virtual std::string getGeometryType() const=0;
00269
00271 virtual GeometryTypeId getGeometryTypeId() const=0;
00272
00275 virtual size_t getNumGeometries() const { return 1; }
00276
00279 virtual const Geometry* getGeometryN(size_t ) const { return this; }
00280
00290 virtual bool isValid() const;
00291
00293 virtual bool isEmpty() const=0;
00294
00296 virtual bool isRectangle() const { return false; }
00297
00299 virtual Dimension::DimensionType getDimension() const=0;
00300
00317 virtual Geometry* getBoundary() const=0;
00318
00320 virtual int getBoundaryDimension() const=0;
00321
00323 virtual Geometry* getEnvelope() const;
00324
00329 virtual const Envelope* getEnvelopeInternal() const;
00330
00347 virtual bool disjoint(const Geometry *other) const;
00348
00353 virtual bool touches(const Geometry *other) const;
00354
00356 virtual bool intersects(const Geometry *g) const;
00357
00380 virtual bool crosses(const Geometry *g) const;
00381
00386 virtual bool within(const Geometry *g) const;
00387
00389 virtual bool contains(const Geometry *g) const;
00390
00396 virtual bool overlaps(const Geometry *g) const;
00397
00412 virtual bool relate(const Geometry *g,
00413 const std::string& intersectionPattern) const;
00414
00415 bool relate(const Geometry& g, const std::string& intersectionPattern) const
00416 {
00417 return relate(&g, intersectionPattern);
00418 }
00419
00421 virtual IntersectionMatrix* relate(const Geometry *g) const;
00422 IntersectionMatrix* relate(const Geometry &g) const {
00423 return relate(&g);
00424 }
00425
00431 virtual bool equals(const Geometry *g) const;
00432
00471 bool covers(const Geometry* g) const;
00472
00503 bool coveredBy(const Geometry* g) const {
00504 return g->covers(this);
00505 }
00506
00507
00509 virtual std::string toString() const;
00510
00511 virtual std::string toText() const;
00512
00514
00517 virtual Geometry* buffer(double distance) const;
00518
00523
00526 virtual Geometry* buffer(double distance,int quadrantSegments) const;
00527
00564 virtual Geometry* buffer(double distance, int quadrantSegments,
00565 int endCapStyle) const;
00566
00570 virtual Geometry* convexHull() const;
00571
00581 virtual Geometry* intersection(const Geometry *other) const;
00582
00592 virtual Geometry* Union(const Geometry *other) const;
00593
00594
00605 virtual Geometry* difference(const Geometry *other) const;
00606
00616 virtual Geometry* symDifference(const Geometry *other) const;
00617
00622 virtual bool equalsExact(const Geometry *other, double tolerance=0)
00623 const=0;
00624
00625 virtual void apply_rw(const CoordinateFilter *filter)=0;
00626 virtual void apply_ro(CoordinateFilter *filter) const=0;
00627 virtual void apply_rw(GeometryFilter *filter);
00628 virtual void apply_ro(GeometryFilter *filter) const;
00629 virtual void apply_rw(GeometryComponentFilter *filter);
00630 virtual void apply_ro(GeometryComponentFilter *filter) const;
00631
00640 virtual void apply_rw(CoordinateSequenceFilter& filter)=0;
00641
00648 virtual void apply_ro(CoordinateSequenceFilter& filter) const=0;
00649
00659 template <class T>
00660 void applyComponentFilter(T& f) const
00661 {
00662 for(size_t i=0, n=getNumGeometries(); i<n; ++i)
00663 f.filter(getGeometryN(i));
00664 }
00665
00667 virtual void normalize()=0;
00668
00669 virtual int compareTo(const Geometry *geom) const;
00670
00675 virtual double distance(const Geometry *g) const;
00676
00678 virtual double getArea() const;
00679
00681 virtual double getLength() const;
00682
00687 virtual bool isWithinDistance(const Geometry *geom,double cDistance);
00688
00698 virtual Point* getCentroid() const;
00699
00701
00704 virtual bool getCentroid(Coordinate& ret) const;
00705
00716 virtual Point* getInteriorPoint() const;
00717
00718
00719
00720
00721
00722
00723 virtual void geometryChanged();
00724
00730 void geometryChangedAction();
00731
00732 protected:
00733
00735 mutable std::auto_ptr<Envelope> envelope;
00736
00738 static bool hasNonEmptyElements(const std::vector<Geometry *>* geometries);
00739
00741 static bool hasNullElements(const CoordinateSequence* list);
00742
00744 static bool hasNullElements(const std::vector<Geometry *>* lrs);
00745
00746
00747
00748
00749
00750
00755 virtual bool isEquivalentClass(const Geometry *other) const;
00756
00757 static void checkNotGeometryCollection(const Geometry *g);
00758
00759
00760
00761
00762
00763
00764 virtual Envelope::AutoPtr computeEnvelopeInternal() const=0;
00765
00766 virtual int compareToSameClass(const Geometry *geom) const=0;
00767
00768 int compare(std::vector<Coordinate> a, std::vector<Coordinate> b) const;
00769
00770 int compare(std::vector<Geometry *> a, std::vector<Geometry *> b) const;
00771
00772 bool equal(const Coordinate& a, const Coordinate& b,
00773 double tolerance) const;
00774 int SRID;
00775
00777
00778
00780
00781
00783
00784
00785 Geometry(const Geometry &geom);
00786
00796 Geometry(const GeometryFactory *factory);
00797
00798 private:
00799
00800
00801
00802 int getClassSortIndex() const;
00803
00804 class GeometryChangedFilter : public GeometryComponentFilter
00805 {
00806 public:
00807 void filter_rw(Geometry* geom)
00808 {
00809 geom->geometryChangedAction();
00810 }
00811 };
00812
00813 static GeometryChangedFilter geometryChangedFilter;
00814
00816
00819 const GeometryFactory *factory;
00820
00821 static const GeometryFactory* INTERNAL_GEOMETRY_FACTORY;
00822
00823 void* userData;
00824 };
00825
00830 std::ostream& operator<< (std::ostream& os, const Geometry& geom);
00831
00832 struct GEOS_DLL GeometryGreaterThen {
00833 bool operator()(const Geometry *first, const Geometry *second);
00834 };
00835
00836
00838 std::string geosversion();
00839
00845 std::string jtsport();
00846
00847
00848 }
00849 }
00850
00851 #ifdef GEOS_INLINE
00852 # include <geos/geom/Geometry.inl>
00853 #endif
00854
00855 #endif // ndef GEOS_GEOM_GEOMETRY_H
00856
00857
00858
00859
00860
00861
00862
00863
00864
00865
00866
00867
00868
00869
00870
00871
00872
00873
00874
00875
00876
00877
00878
00879
00880
00881
00882
00883
00884
00885
00886
00887
00888
00889
00890
00891
00892
00893
00894
00895
00896
00897
00898
00899
00900
00901
00902
00903
00904
00905
00906
00907
00908
00909
00910
00911
00912
00913
00914
00915
00916
00917
00918
00919