GEOS  3.11.0
Polygon.h
1 /**********************************************************************
2  *
3  * GEOS - Geometry Engine Open Source
4  * http://geos.osgeo.org
5  *
6  * Copyright (C) 2011 Sandro Santilli <strk@kbt.io>
7  * Copyright (C) 2005 2006 Refractions Research Inc.
8  * Copyright (C) 2001-2002 Vivid Solutions Inc.
9  *
10  * This is free software; you can redistribute and/or modify it under
11  * the terms of the GNU Lesser General Public Licence as published
12  * by the Free Software Foundation.
13  * See the COPYING file for more information.
14  *
15  **********************************************************************
16  *
17  * Last port: geom/Polygon.java r320 (JTS-1.12)
18  *
19  **********************************************************************/
20 
21 #pragma once
22 
23 #include <geos/export.h>
24 #include <string>
25 #include <vector>
26 #include <geos/geom/Geometry.h> // for inheritance
27 #include <geos/geom/Envelope.h> // for proper use of unique_ptr<>
28 #include <geos/geom/LinearRing.h>
29 #include <geos/geom/Dimension.h> // for Dimension::DimensionType
30 
31 #include <memory> // for unique_ptr
32 
33 // Forward declarations
34 namespace geos {
35 namespace geom { // geos::geom
36 class Coordinate;
37 class CoordinateArraySequence;
38 class CoordinateSequenceFilter;
39 class LineString;
40 }
41 }
42 
43 namespace geos {
44 namespace geom { // geos::geom
45 
61 class GEOS_DLL Polygon: public Geometry {
62 
63 public:
64 
65  friend class GeometryFactory;
66 
68  typedef std::vector<const Polygon*> ConstVect;
69 
70  ~Polygon() override = default;
71 
78  std::unique_ptr<Polygon> clone() const
79  {
80  return std::unique_ptr<Polygon>(cloneImpl());
81  }
82 
83  std::unique_ptr<CoordinateSequence> getCoordinates() const override;
84 
85  std::size_t getNumPoints() const override;
86 
89 
91  uint8_t getCoordinateDimension() const override;
92 
94  int getBoundaryDimension() const override;
95 
102  std::unique_ptr<Geometry> getBoundary() const override;
103 
104  bool isEmpty() const override;
105 
107  const LinearRing* getExteriorRing() const;
108 
117  std::unique_ptr<LinearRing> releaseExteriorRing();
118 
120  std::size_t getNumInteriorRing() const;
121 
123  const LinearRing* getInteriorRingN(std::size_t n) const;
124 
133  std::vector<std::unique_ptr<LinearRing>> releaseInteriorRings();
134 
135  std::string getGeometryType() const override;
137  bool equalsExact(const Geometry* other, double tolerance = 0) const override;
138  void apply_rw(const CoordinateFilter* filter) override;
139  void apply_ro(CoordinateFilter* filter) const override;
140  void apply_rw(GeometryFilter* filter) override;
141  void apply_ro(GeometryFilter* filter) const override;
142  void apply_rw(CoordinateSequenceFilter& filter) override;
143  void apply_ro(CoordinateSequenceFilter& filter) const override;
144  void apply_rw(GeometryComponentFilter* filter) override;
145  void apply_ro(GeometryComponentFilter* filter) const override;
146 
147  std::unique_ptr<Geometry> convexHull() const override;
148 
149  void normalize() override;
150 
151  std::unique_ptr<Polygon> reverse() const { return std::unique_ptr<Polygon>(reverseImpl()); }
152 
153  const Coordinate* getCoordinate() const override;
154 
155  double getArea() const override;
156 
158  double getLength() const override;
159 
160  bool isRectangle() const override;
161 
162 protected:
163 
164 
165  Polygon(const Polygon& p);
166 
167  int compareToSameClass(const Geometry* p) const override;
168 
187  Polygon(LinearRing* newShell, std::vector<LinearRing*>* newHoles,
188  const GeometryFactory* newFactory);
189 
190  Polygon(std::unique_ptr<LinearRing> && newShell,
191  const GeometryFactory& newFactory);
192 
193  Polygon(std::unique_ptr<LinearRing> && newShell,
194  std::vector<std::unique_ptr<LinearRing>> && newHoles,
195  const GeometryFactory& newFactory);
196 
197  Polygon* cloneImpl() const override { return new Polygon(*this); }
198 
199  Polygon* reverseImpl() const override;
200 
201  std::unique_ptr<LinearRing> shell;
202 
203  std::vector<std::unique_ptr<LinearRing>> holes;
204 
205  Envelope::Ptr computeEnvelopeInternal() const override;
206 
207  int
208  getSortIndex() const override
209  {
210  return SORTINDEX_POLYGON;
211  };
212 
213 
214 private:
215 
216  void normalize(LinearRing* ring, bool clockwise);
217 
218 };
219 
220 } // namespace geos::geom
221 } // namespace geos
222 
Geometry classes support the concept of applying a coordinate filter to every coordinate in the Geome...
Definition: CoordinateFilter.h:41
Interface for classes which provide operations that can be applied to the coordinates in a Coordinate...
Definition: CoordinateSequenceFilter.h:55
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:58
DimensionType
Definition: Dimension.h:29
Definition: GeometryComponentFilter.h:41
Supplies a set of utility methods for building Geometry objects from CoordinateSequence or other Geom...
Definition: GeometryFactory.h:66
Geometry classes support the concept of applying a Geometry filter to the Geometry.
Definition: GeometryFilter.h:45
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition: Geometry.h:186
Models an OGC SFS LinearRing. A LinearRing is a LineString which is both closed and simple.
Definition: LinearRing.h:55
Represents a linear polygon, which may include holes.
Definition: Polygon.h:61
std::size_t getNumPoints() const override
Returns the count of this Geometrys vertices.
std::vector< std::unique_ptr< LinearRing > > releaseInteriorRings()
Take ownership of this Polygon's interior rings. After releasing the rings, the Polygon should be con...
void normalize() override
std::unique_ptr< Polygon > clone() const
Definition: Polygon.h:78
double getLength() const override
Returns the perimeter of this Polygon
const LinearRing * getInteriorRingN(std::size_t n) const
Get nth interior ring (hole)
uint8_t getCoordinateDimension() const override
Returns coordinate dimension.
const Coordinate * getCoordinate() const override
Returns a vertex of this Geometry, or NULL if this is the empty geometry.
int getBoundaryDimension() const override
Returns 1 (Polygon boundary is a MultiLineString)
Polygon(LinearRing *newShell, std::vector< LinearRing * > *newHoles, const GeometryFactory *newFactory)
std::string getGeometryType() const override
Return a string representation of this Geometry type.
std::unique_ptr< Geometry > convexHull() const override
Returns the smallest convex Polygon that contains all the points in the Geometry.
std::vector< const Polygon * > ConstVect
A vector of const Polygon pointers.
Definition: Polygon.h:68
std::size_t getNumInteriorRing() const
Returns number of interior rings (hole)
Polygon * cloneImpl() const override
Make a deep-copy of this Geometry.
Definition: Polygon.h:197
double getArea() const override
Returns the area of this Geometry.
Polygon * reverseImpl() const override
Make a geometry with coordinates in reverse order.
std::unique_ptr< CoordinateSequence > getCoordinates() const override
Returns this Geometry vertices. Caller takes ownership of the returned object.
bool isRectangle() const override
Polygon overrides to check for actual rectangle.
void apply_ro(CoordinateSequenceFilter &filter) const override
std::unique_ptr< LinearRing > releaseExteriorRing()
Take ownership of this Polygon's exterior ring. After releasing the exterior ring,...
bool isEmpty() const override
Returns whether or not the set of points in this Geometry is empty.
bool equalsExact(const Geometry *other, double tolerance=0) const override
Returns true iff the two Geometrys are of the same type and their vertices corresponding by index are...
Dimension::DimensionType getDimension() const override
Returns surface dimension (2)
const LinearRing * getExteriorRing() const
Returns the exterior ring (shell)
std::unique_ptr< Geometry > getBoundary() const override
Computes the boundary of this geometry.
GeometryTypeId getGeometryTypeId() const override
Return an integer representation of this Geometry type.
void apply_rw(CoordinateSequenceFilter &filter) override
GeometryTypeId
Geometry types.
Definition: Geometry.h:73
Basic namespace for all GEOS functionalities.
Definition: Angle.h:25