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 #ifdef _MSC_VER
00038 #pragma warning(push)
00039 #pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
00040 #pragma warning(disable: 4355) // warning C4355: 'this' : used in base member initializer list
00041 #endif
00042
00043
00044 namespace geos {
00045 namespace geom {
00046 class Coordinate;
00047 class CoordinateFilter;
00048 class CoordinateSequence;
00049 class CoordinateSequenceFilter;
00050 class GeometryComponentFilter;
00051 class GeometryFactory;
00052 class GeometryFilter;
00053 class IntersectionMatrix;
00054 class PrecisionModel;
00055 class Point;
00056 }
00057 namespace io {
00058 class Unload;
00059 }
00060 }
00061
00062 namespace geos {
00063 namespace geom {
00064
00066 enum GeometryTypeId {
00068 GEOS_POINT,
00070 GEOS_LINESTRING,
00072 GEOS_LINEARRING,
00074 GEOS_POLYGON,
00076 GEOS_MULTIPOINT,
00078 GEOS_MULTILINESTRING,
00080 GEOS_MULTIPOLYGON,
00082 GEOS_GEOMETRYCOLLECTION
00083 };
00084
00168 class GEOS_DLL Geometry {
00169
00170 public:
00171
00172 friend class GeometryFactory;
00173
00175 typedef std::vector<const Geometry *> ConstVect;
00176
00178 typedef std::vector<Geometry *> NonConstVect;
00179
00181 typedef std::auto_ptr<Geometry> AutoPtr;
00182
00184 virtual Geometry* clone() const=0;
00185
00187 virtual ~Geometry();
00188
00189
00197 const GeometryFactory* getFactory() const { return factory; }
00198
00212 void setUserData(void* newUserData) { userData=newUserData; }
00213
00220 void* getUserData() { return userData; }
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237 virtual int getSRID() const { return SRID; }
00238
00239
00240
00241
00242
00243 virtual void setSRID(int newSRID) { SRID=newSRID; }
00244
00249 const PrecisionModel* getPrecisionModel() const;
00250
00255 virtual const Coordinate* getCoordinate() const=0;
00256
00262 virtual CoordinateSequence* getCoordinates() const=0;
00263
00265 virtual std::size_t getNumPoints() const=0;
00266
00268 virtual bool isSimple() const;
00269
00271 virtual std::string getGeometryType() const=0;
00272
00274 virtual GeometryTypeId getGeometryTypeId() const=0;
00275
00278 virtual std::size_t getNumGeometries() const { return 1; }
00279
00282 virtual const Geometry* getGeometryN(std::size_t ) const { return this; }
00283
00293 virtual bool isValid() const;
00294
00296 virtual bool isEmpty() const=0;
00297
00299 virtual bool isRectangle() const { return false; }
00300
00302 virtual Dimension::DimensionType getDimension() const=0;
00303
00305 virtual int getCoordinateDimension() const=0;
00306
00323 virtual Geometry* getBoundary() const=0;
00324
00326 virtual int getBoundaryDimension() const=0;
00327
00329 virtual Geometry* getEnvelope() const;
00330
00335 virtual const Envelope* getEnvelopeInternal() const;
00336
00353 virtual bool disjoint(const Geometry *other) const;
00354
00359 virtual bool touches(const Geometry *other) const;
00360
00362 virtual bool intersects(const Geometry *g) const;
00363
00386 virtual bool crosses(const Geometry *g) const;
00387
00392 virtual bool within(const Geometry *g) const;
00393
00395 virtual bool contains(const Geometry *g) const;
00396
00402 virtual bool overlaps(const Geometry *g) const;
00403
00418 virtual bool relate(const Geometry *g,
00419 const std::string& intersectionPattern) const;
00420
00421 bool relate(const Geometry& g, const std::string& intersectionPattern) const
00422 {
00423 return relate(&g, intersectionPattern);
00424 }
00425
00427 virtual IntersectionMatrix* relate(const Geometry *g) const;
00428 IntersectionMatrix* relate(const Geometry &g) const {
00429 return relate(&g);
00430 }
00431
00437 virtual bool equals(const Geometry *g) const;
00438
00477 bool covers(const Geometry* g) const;
00478
00509 bool coveredBy(const Geometry* g) const {
00510 return g->covers(this);
00511 }
00512
00513
00515 virtual std::string toString() const;
00516
00517 virtual std::string toText() const;
00518
00520
00523 virtual Geometry* buffer(double distance) const;
00524
00529
00532 virtual Geometry* buffer(double distance,int quadrantSegments) const;
00533
00570 virtual Geometry* buffer(double distance, int quadrantSegments,
00571 int endCapStyle) const;
00572
00576 virtual Geometry* convexHull() const;
00577
00587 virtual Geometry* intersection(const Geometry *other) const;
00588
00598 Geometry* Union(const Geometry *other) const;
00599
00600
00618 AutoPtr Union() const;
00619
00620
00631 virtual Geometry* difference(const Geometry *other) const;
00632
00642 virtual Geometry* symDifference(const Geometry *other) const;
00643
00648 virtual bool equalsExact(const Geometry *other, double tolerance=0)
00649 const=0;
00650
00651 virtual void apply_rw(const CoordinateFilter *filter)=0;
00652 virtual void apply_ro(CoordinateFilter *filter) const=0;
00653 virtual void apply_rw(GeometryFilter *filter);
00654 virtual void apply_ro(GeometryFilter *filter) const;
00655 virtual void apply_rw(GeometryComponentFilter *filter);
00656 virtual void apply_ro(GeometryComponentFilter *filter) const;
00657
00666 virtual void apply_rw(CoordinateSequenceFilter& filter)=0;
00667
00674 virtual void apply_ro(CoordinateSequenceFilter& filter) const=0;
00675
00685 template <class T>
00686 void applyComponentFilter(T& f) const
00687 {
00688 for(std::size_t i=0, n=getNumGeometries(); i<n; ++i)
00689 f.filter(getGeometryN(i));
00690 }
00691
00693 virtual void normalize()=0;
00694
00695 virtual int compareTo(const Geometry *geom) const;
00696
00701 virtual double distance(const Geometry *g) const;
00702
00704 virtual double getArea() const;
00705
00707 virtual double getLength() const;
00708
00720 virtual bool isWithinDistance(const Geometry *geom,
00721 double cDistance) const;
00722
00732 virtual Point* getCentroid() const;
00733
00735
00738 virtual bool getCentroid(Coordinate& ret) const;
00739
00750 virtual Point* getInteriorPoint() const;
00751
00752
00753
00754
00755
00756
00757 virtual void geometryChanged();
00758
00764 void geometryChangedAction();
00765
00766 protected:
00767
00769 mutable std::auto_ptr<Envelope> envelope;
00770
00772 static bool hasNonEmptyElements(const std::vector<Geometry *>* geometries);
00773
00775 static bool hasNullElements(const CoordinateSequence* list);
00776
00778 static bool hasNullElements(const std::vector<Geometry *>* lrs);
00779
00780
00781
00782
00783
00784
00789 virtual bool isEquivalentClass(const Geometry *other) const;
00790
00791 static void checkNotGeometryCollection(const Geometry *g);
00792
00793
00794
00795
00796
00797
00798 virtual Envelope::AutoPtr computeEnvelopeInternal() const=0;
00799
00800 virtual int compareToSameClass(const Geometry *geom) const=0;
00801
00802 int compare(std::vector<Coordinate> a, std::vector<Coordinate> b) const;
00803
00804 int compare(std::vector<Geometry *> a, std::vector<Geometry *> b) const;
00805
00806 bool equal(const Coordinate& a, const Coordinate& b,
00807 double tolerance) const;
00808 int SRID;
00809
00811
00812
00814
00815
00817
00818
00819 Geometry(const Geometry &geom);
00820
00830 Geometry(const GeometryFactory *factory);
00831
00832 private:
00833
00834 int getClassSortIndex() const;
00835
00836 class GeometryChangedFilter : public GeometryComponentFilter
00837 {
00838 public:
00839 void filter_rw(Geometry* geom)
00840 {
00841 geom->geometryChangedAction();
00842 }
00843 };
00844
00845 static GeometryChangedFilter geometryChangedFilter;
00846
00848
00851 const GeometryFactory *factory;
00852
00853 void* userData;
00854 };
00855
00860 GEOS_DLL std::ostream& operator<< (std::ostream& os, const Geometry& geom);
00861
00862 struct GEOS_DLL GeometryGreaterThen {
00863 bool operator()(const Geometry *first, const Geometry *second);
00864 };
00865
00866
00868 std::string geosversion();
00869
00875 std::string jtsport();
00876
00877
00878
00879
00880 struct GeomPtrPair {
00881 typedef std::auto_ptr<Geometry> GeomPtr;
00882 GeomPtr first;
00883 GeomPtr second;
00884 };
00885
00886 }
00887 }
00888
00889 #ifdef _MSC_VER
00890 #pragma warning(pop)
00891 #endif
00892
00893 #endif // ndef GEOS_GEOM_GEOMETRY_H
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
00920
00921
00922
00923
00924
00925
00926
00927
00928
00929
00930
00931
00932
00933
00934
00935
00936
00937
00938
00939
00940
00941
00942
00943
00944
00945
00946
00947
00948
00949
00950
00951
00952
00953
00954
00955
00956
00957