21 #ifndef GEOS_GEOM_GEOMETRY_H
22 #define GEOS_GEOM_GEOMETRY_H
24 #ifndef USE_UNSTABLE_GEOS_CPP_API
26 # warning "The GEOS C++ API is unstable, please use the C API instead"
27 # warning "HINT: #include geos_c.h"
29 #pragma message("The GEOS C++ API is unstable, please use the C API instead")
30 #pragma message("HINT: #include geos_c.h")
34 #include <geos/export.h>
35 #include <geos/inline.h>
36 #include <geos/geom/Envelope.h>
37 #include <geos/geom/Dimension.h>
38 #include <geos/geom/GeometryComponentFilter.h>
39 #include <geos/geom/IntersectionMatrix.h>
49 #pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
50 #pragma warning(disable: 4355) // warning C4355: 'this' : used in base member initializer list
57 class CoordinateFilter;
58 class CoordinateSequence;
59 class CoordinateSequenceFilter;
60 class GeometryComponentFilter;
61 class GeometryFactory;
94 enum GeometrySortIndex {
96 SORTINDEX_MULTIPOINT = 1,
97 SORTINDEX_LINESTRING = 2,
98 SORTINDEX_LINEARRING = 3,
99 SORTINDEX_MULTILINESTRING = 4,
100 SORTINDEX_POLYGON = 5,
101 SORTINDEX_MULTIPOLYGON = 6,
102 SORTINDEX_GEOMETRYCOLLECTION = 7
188 class GEOS_DLL Geometry {
192 friend class GeometryFactory;
195 using ConstVect = std::vector<const Geometry*>;
198 using NonConstVect = std::vector<Geometry*>;
201 using Ptr = std::unique_ptr<Geometry> ;
204 virtual std::unique_ptr<Geometry> clone()
const = 0;
237 setUserData(
void* newUserData)
239 _userData = newUserData;
286 virtual const Coordinate* getCoordinate()
const = 0;
293 virtual std::unique_ptr<CoordinateSequence> getCoordinates()
const = 0;
296 virtual std::size_t getNumPoints()
const = 0;
299 virtual bool isSimple()
const;
302 virtual std::string getGeometryType()
const = 0;
310 getNumGeometries()
const
318 getGeometryN(std::size_t )
const
332 virtual bool isValid()
const;
335 virtual bool isEmpty()
const = 0;
349 return d == getDimension();
352 bool isPuntal()
const {
356 bool isLineal()
const {
360 bool isPolygonal()
const {
365 virtual int getCoordinateDimension()
const = 0;
383 virtual std::unique_ptr<Geometry> getBoundary()
const = 0;
386 virtual int getBoundaryDimension()
const = 0;
389 virtual std::unique_ptr<Geometry> getEnvelope()
const;
395 virtual const Envelope* getEnvelopeInternal()
const;
413 virtual bool disjoint(
const Geometry* other)
const;
419 virtual bool touches(
const Geometry* other)
const;
422 virtual bool intersects(
const Geometry* g)
const;
446 virtual bool crosses(
const Geometry* g)
const;
452 virtual bool within(
const Geometry* g)
const;
455 virtual bool contains(
const Geometry* g)
const;
462 virtual bool overlaps(
const Geometry* g)
const;
478 bool relate(
const Geometry* g,
479 const std::string& intersectionPattern)
const;
482 relate(
const Geometry& g,
const std::string& intersectionPattern)
const
484 return relate(&g, intersectionPattern);
488 std::unique_ptr<IntersectionMatrix> relate(
const Geometry* g)
const;
490 std::unique_ptr<IntersectionMatrix> relate(
const Geometry& g)
const
500 virtual bool equals(
const Geometry* g)
const;
540 bool covers(
const Geometry* g)
const;
580 virtual std::string toString()
const;
582 virtual std::string toText()
const;
588 std::unique_ptr<Geometry> buffer(
double distance)
const;
597 std::unique_ptr<Geometry> buffer(
double distance,
int quadrantSegments)
const;
635 std::unique_ptr<Geometry> buffer(
double distance,
int quadrantSegments,
636 int endCapStyle)
const;
641 virtual std::unique_ptr<Geometry> convexHull()
const;
649 virtual std::unique_ptr<Geometry> reverse()
const = 0;
660 std::unique_ptr<Geometry> intersection(
const Geometry* other)
const;
671 std::unique_ptr<Geometry> Union(
const Geometry* other)
const;
704 std::unique_ptr<Geometry> difference(
const Geometry* other)
const;
715 std::unique_ptr<Geometry> symDifference(
const Geometry* other)
const;
721 virtual bool equalsExact(
const Geometry* other,
double tolerance = 0)
760 applyComponentFilter(T& f)
const
762 for(std::size_t i = 0, n = getNumGeometries(); i < n; ++i) {
763 f.filter(getGeometryN(i));
768 virtual void normalize() = 0;
770 virtual int compareTo(
const Geometry* geom)
const;
776 virtual double distance(
const Geometry* g)
const;
779 virtual double getArea()
const;
782 virtual double getLength()
const;
795 virtual bool isWithinDistance(
const Geometry* geom,
796 double cDistance)
const;
807 virtual std::unique_ptr<Point> getCentroid()
const;
813 virtual bool getCentroid(
Coordinate& ret)
const;
825 std::unique_ptr<Point> getInteriorPoint()
const;
832 virtual void geometryChanged();
839 void geometryChangedAction();
844 mutable std::unique_ptr<Envelope> envelope;
848 static bool hasNonEmptyElements(
const std::vector<T>* geometries) {
849 return std::any_of(geometries->begin(), geometries->end(), [](
const T& g) {
return !g->isEmpty(); });
857 static bool hasNullElements(
const std::vector<T>* geometries) {
858 return std::any_of(geometries->begin(), geometries->end(), [](
const T& g) {
return g ==
nullptr; });
870 virtual bool isEquivalentClass(
const Geometry* other)
const;
872 static void checkNotGeometryCollection(
const Geometry* g);
879 virtual Envelope::Ptr computeEnvelopeInternal()
const = 0;
881 virtual int compareToSameClass(
const Geometry* geom)
const = 0;
883 int compare(std::vector<Coordinate> a, std::vector<Coordinate> b)
const;
885 int compare(std::vector<Geometry*> a, std::vector<Geometry*> b)
const;
887 int compare(
const std::vector<std::unique_ptr<Geometry>> & a,
const std::vector<std::unique_ptr<Geometry>> & b)
const;
890 double tolerance)
const;
907 static std::vector<std::unique_ptr<Geometry>> toGeometryArray(std::vector<std::unique_ptr<T>> && v) {
908 static_assert(std::is_base_of<Geometry, T>::value,
"");
909 std::vector<std::unique_ptr<Geometry>> gv(v.size());
910 for (
size_t i = 0; i < v.size(); i++) {
911 gv[i] = std::move(v[i]);
918 virtual int getSortIndex()
const = 0;
923 class GEOS_DLL GeometryChangedFilter :
public GeometryComponentFilter {
925 void filter_rw(Geometry* geom)
override;
928 static GeometryChangedFilter geometryChangedFilter;
934 const GeometryFactory* _factory;
943 GEOS_DLL std::ostream&
operator<< (std::ostream& os,
const Geometry& geom);
945 struct GEOS_DLL GeometryGreaterThen {
946 bool operator()(
const Geometry* first,
const Geometry* second);
958 GEOS_DLL std::string
jtsport();
964 typedef std::unique_ptr<Geometry> GeomPtr;
976 #endif // ndef GEOS_GEOM_GEOMETRY_H