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 GeometryComponentFilter;
00045 class GeometryFactory;
00046 class GeometryFilter;
00047 class IntersectionMatrix;
00048 class PrecisionModel;
00049 class Point;
00050 }
00051 namespace io {
00052 class Unload;
00053 }
00054 }
00055
00056 namespace geos {
00057 namespace geom {
00058
00060 enum GeometryTypeId {
00062 GEOS_POINT,
00064 GEOS_LINESTRING,
00066 GEOS_LINEARRING,
00068 GEOS_POLYGON,
00070 GEOS_MULTIPOINT,
00072 GEOS_MULTILINESTRING,
00074 GEOS_MULTIPOLYGON,
00076 GEOS_GEOMETRYCOLLECTION
00077 };
00078
00162 class GEOS_DLL Geometry {
00163
00164 public:
00165
00166 friend class GeometryFactory;
00167
00168 friend std::ostream& operator<< (std::ostream& os, const Geometry& geom);
00169
00171 typedef std::vector<const Geometry *> ConstVect;
00172
00174 typedef std::vector<Geometry *> NonConstVect;
00175
00177 typedef std::auto_ptr<Geometry> AutoPtr;
00178
00180 virtual Geometry* clone() const=0;
00181
00183 virtual ~Geometry();
00184
00185
00193 const GeometryFactory* getFactory() const { return factory; }
00194
00208 void setUserData(void* newUserData) { userData=newUserData; }
00209
00216 void* getUserData() { return userData; }
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233 virtual int getSRID() const { return SRID; }
00234
00235
00236
00237
00238
00239 virtual void setSRID(int newSRID) { SRID=newSRID; }
00240
00245 const PrecisionModel* getPrecisionModel() const;
00246
00251 virtual const Coordinate* getCoordinate() const=0;
00252
00258 virtual CoordinateSequence* getCoordinates() const=0;
00259
00261 virtual size_t getNumPoints() const=0;
00262
00264 virtual bool isSimple() const;
00265
00267 virtual std::string getGeometryType() const=0;
00268
00270 virtual GeometryTypeId getGeometryTypeId() const=0;
00271
00274 virtual size_t getNumGeometries() const { return 1; }
00275
00278 virtual const Geometry* getGeometryN(size_t ) const { return this; }
00279
00289 virtual bool isValid() const;
00290
00292 virtual bool isEmpty() const=0;
00293
00295 virtual bool isRectangle() const { return false; }
00296
00298 virtual Dimension::DimensionType getDimension() const=0;
00299
00316 virtual Geometry* getBoundary() const=0;
00317
00319 virtual int getBoundaryDimension() const=0;
00320
00322 virtual Geometry* getEnvelope() const;
00323
00328 virtual const Envelope* getEnvelopeInternal() const;
00329
00346 virtual bool disjoint(const Geometry *other) const;
00347
00352 virtual bool touches(const Geometry *other) const;
00353
00355 virtual bool intersects(const Geometry *g) const;
00356
00379 virtual bool crosses(const Geometry *g) const;
00380
00385 virtual bool within(const Geometry *g) const;
00386
00388 virtual bool contains(const Geometry *g) const;
00389
00395 virtual bool overlaps(const Geometry *g) const;
00396
00411 virtual bool relate(const Geometry *g,
00412 const std::string& intersectionPattern) const;
00413
00414 bool relate(const Geometry& g, const std::string& intersectionPattern) const
00415 {
00416 return relate(&g, intersectionPattern);
00417 }
00418
00420 virtual IntersectionMatrix* relate(const Geometry *g) const;
00421 IntersectionMatrix* relate(const Geometry &g) const {
00422 return relate(&g);
00423 }
00424
00430 virtual bool equals(const Geometry *g) const;
00431
00470 bool covers(const Geometry* g) const;
00471
00502 bool coveredBy(const Geometry* g) const {
00503 return g->covers(this);
00504 }
00505
00506
00508 virtual std::string toString() const;
00509
00510 virtual std::string toText() const;
00511
00513
00516 virtual Geometry* buffer(double distance) const;
00517
00522
00525 virtual Geometry* buffer(double distance,int quadrantSegments) const;
00526
00563 virtual Geometry* buffer(double distance, int quadrantSegments,
00564 int endCapStyle) const;
00565
00569 virtual Geometry* convexHull() const;
00570
00580 virtual Geometry* intersection(const Geometry *other) const;
00581
00591 virtual Geometry* Union(const Geometry *other) const;
00592
00593
00604 virtual Geometry* difference(const Geometry *other) const;
00605
00615 virtual Geometry* symDifference(const Geometry *other) const;
00616
00621 virtual bool equalsExact(const Geometry *other, double tolerance=0)
00622 const=0;
00623
00624 virtual void apply_rw(const CoordinateFilter *filter)=0;
00625 virtual void apply_ro(CoordinateFilter *filter) const=0;
00626 virtual void apply_rw(GeometryFilter *filter);
00627 virtual void apply_ro(GeometryFilter *filter) const;
00628 virtual void apply_rw(GeometryComponentFilter *filter);
00629 virtual void apply_ro(GeometryComponentFilter *filter) const;
00630
00639 virtual void apply_rw(CoordinateSequenceFilter& filter)=0;
00640
00647 virtual void apply_ro(CoordinateSequenceFilter& filter) const=0;
00648
00658 template <class T>
00659 void applyComponentFilter(T& f) const
00660 {
00661 for(size_t i=0, n=getNumGeometries(); i<n; ++i)
00662 f.filter(getGeometryN(i));
00663 }
00664
00666 virtual void normalize()=0;
00667
00668 virtual int compareTo(const Geometry *geom) const;
00669
00674 virtual double distance(const Geometry *g) const;
00675
00677 virtual double getArea() const;
00678
00680 virtual double getLength() const;
00681
00686 virtual bool isWithinDistance(const Geometry *geom,double cDistance);
00687
00697 virtual Point* getCentroid() const;
00698
00700
00703 virtual bool getCentroid(Coordinate& ret) const;
00704
00715 virtual Point* getInteriorPoint() const;
00716
00717
00718
00719
00720
00721
00722 virtual void geometryChanged();
00723
00729 void geometryChangedAction();
00730
00731 protected:
00732
00734 mutable std::auto_ptr<Envelope> envelope;
00735
00737 static bool hasNonEmptyElements(const std::vector<Geometry *>* geometries);
00738
00740 static bool hasNullElements(const CoordinateSequence* list);
00741
00743 static bool hasNullElements(const std::vector<Geometry *>* lrs);
00744
00745
00746
00747
00748
00749
00754 virtual bool isEquivalentClass(const Geometry *other) const;
00755
00756 static void checkNotGeometryCollection(const Geometry *g);
00757
00758
00759
00760
00761
00762
00763 virtual Envelope::AutoPtr computeEnvelopeInternal() const=0;
00764
00765 virtual int compareToSameClass(const Geometry *geom) const=0;
00766
00767 int compare(std::vector<Coordinate> a, std::vector<Coordinate> b) const;
00768
00769 int compare(std::vector<Geometry *> a, std::vector<Geometry *> b) const;
00770
00771 bool equal(const Coordinate& a, const Coordinate& b,
00772 double tolerance) const;
00773 int SRID;
00774
00776
00777
00779
00780
00782
00783
00784 Geometry(const Geometry &geom);
00785
00795 Geometry(const GeometryFactory *factory);
00796
00797 private:
00798
00799
00800
00801 int getClassSortIndex() const;
00802
00803 class GeometryChangedFilter : public GeometryComponentFilter
00804 {
00805 public:
00806 void filter_rw(Geometry* geom)
00807 {
00808 geom->geometryChangedAction();
00809 }
00810 };
00811
00812 static GeometryChangedFilter geometryChangedFilter;
00813
00815
00818 const GeometryFactory *factory;
00819
00820 static const GeometryFactory* INTERNAL_GEOMETRY_FACTORY;
00821
00822 void* userData;
00823 };
00824
00829 std::ostream& operator<< (std::ostream& os, const Geometry& geom);
00830
00831 struct GEOS_DLL GeometryGreaterThen {
00832 bool operator()(const Geometry *first, const Geometry *second);
00833 };
00834
00835
00837 std::string geosversion();
00838
00844 std::string jtsport();
00845
00846
00847 }
00848 }
00849
00850 #ifdef GEOS_INLINE
00851 # include <geos/geom/Geometry.inl>
00852 #endif
00853
00854 #endif // ndef GEOS_GEOM_GEOMETRY_H
00855
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