GEOS  3.10.1
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 #ifndef GEOS_GEOM_POLYGON_H
22 #define GEOS_GEOM_POLYGON_H
23 
24 #include <geos/export.h>
25 #include <string>
26 #include <vector>
27 #include <geos/geom/Geometry.h> // for inheritance
28 #include <geos/geom/Envelope.h> // for proper use of unique_ptr<>
29 #include <geos/geom/LinearRing.h>
30 #include <geos/geom/Dimension.h> // for Dimension::DimensionType
31 
32 #include <geos/inline.h>
33 
34 #include <memory> // for unique_ptr
35 
36 // Forward declarations
37 namespace geos {
38 namespace geom { // geos::geom
39 class Coordinate;
40 class CoordinateArraySequence;
41 class CoordinateSequenceFilter;
42 class LineString;
43 }
44 }
45 
46 namespace geos {
47 namespace geom { // geos::geom
48 
64 class GEOS_DLL Polygon: public Geometry {
65 
66 public:
67 
68  friend class GeometryFactory;
69 
71  typedef std::vector<const Polygon*> ConstVect;
72 
73  ~Polygon() override = default;
74 
81  std::unique_ptr<Polygon> clone() const
82  {
83  return std::unique_ptr<Polygon>(cloneImpl());
84  }
85 
86  std::unique_ptr<CoordinateSequence> getCoordinates() const override;
87 
88  std::size_t getNumPoints() const override;
89 
91  Dimension::DimensionType getDimension() const override;
92 
94  uint8_t getCoordinateDimension() const override;
95 
97  int getBoundaryDimension() const override;
98 
105  std::unique_ptr<Geometry> getBoundary() const override;
106 
107  bool isEmpty() const override;
108 
110  const LinearRing* getExteriorRing() const;
111 
120  std::unique_ptr<LinearRing> releaseExteriorRing();
121 
123  std::size_t getNumInteriorRing() const;
124 
126  const LinearRing* getInteriorRingN(std::size_t n) const;
127 
136  std::vector<std::unique_ptr<LinearRing>> releaseInteriorRings();
137 
138  std::string getGeometryType() const override;
139  GeometryTypeId getGeometryTypeId() const override;
140  bool equalsExact(const Geometry* other, double tolerance = 0) const override;
141  void apply_rw(const CoordinateFilter* filter) override;
142  void apply_ro(CoordinateFilter* filter) const override;
143  void apply_rw(GeometryFilter* filter) override;
144  void apply_ro(GeometryFilter* filter) const override;
145  void apply_rw(CoordinateSequenceFilter& filter) override;
146  void apply_ro(CoordinateSequenceFilter& filter) const override;
147  void apply_rw(GeometryComponentFilter* filter) override;
148  void apply_ro(GeometryComponentFilter* filter) const override;
149 
150  std::unique_ptr<Geometry> convexHull() const override;
151 
152  void normalize() override;
153 
154  std::unique_ptr<Polygon> reverse() const { return std::unique_ptr<Polygon>(reverseImpl()); }
155 
156  const Coordinate* getCoordinate() const override;
157 
158  double getArea() const override;
159 
161  double getLength() const override;
162 
163  bool isRectangle() const override;
164 
165 protected:
166 
167 
168  Polygon(const Polygon& p);
169 
170  int compareToSameClass(const Geometry* p) const override;
171 
190  Polygon(LinearRing* newShell, std::vector<LinearRing*>* newHoles,
191  const GeometryFactory* newFactory);
192 
193  Polygon(std::unique_ptr<LinearRing> && newShell,
194  const GeometryFactory& newFactory);
195 
196  Polygon(std::unique_ptr<LinearRing> && newShell,
197  std::vector<std::unique_ptr<LinearRing>> && newHoles,
198  const GeometryFactory& newFactory);
199 
200  Polygon* cloneImpl() const override { return new Polygon(*this); }
201 
202  Polygon* reverseImpl() const override;
203 
204  std::unique_ptr<LinearRing> shell;
205 
206  std::vector<std::unique_ptr<LinearRing>> holes;
207 
208  Envelope::Ptr computeEnvelopeInternal() const override;
209 
210  int
211  getSortIndex() const override
212  {
213  return SORTINDEX_POLYGON;
214  };
215 
216 
217 private:
218 
219  void normalize(LinearRing* ring, bool clockwise);
220 };
221 
222 } // namespace geos::geom
223 } // namespace geos
224 
225 #endif // ndef GEOS_GEOM_POLYGON_H
Geometry classes support the concept of applying a Geometry filter to the Geometry.
Definition: GeometryFilter.h:47
std::vector< const Polygon * > ConstVect
A vector of const Polygon pointers.
Definition: Polygon.h:71
std::unique_ptr< Polygon > clone() const
Definition: Polygon.h:81
Interface for classes which provide operations that can be applied to the coordinates in a Coordinate...
Definition: CoordinateSequenceFilter.h:57
GeometryTypeId
Geometry types.
Definition: Geometry.h:75
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition: Geometry.h:188
Geometry classes support the concept of applying a coordinate filter to every coordinate in the Geome...
Definition: CoordinateFilter.h:43
Represents a linear polygon, which may include holes.
Definition: Polygon.h:64
Polygon * cloneImpl() const override
Make a deep-copy of this Geometry.
Definition: Polygon.h:200
Supplies a set of utility methods for building Geometry objects from CoordinateSequence or other Geom...
Definition: GeometryFactory.h:68
Basic namespace for all GEOS functionalities.
Definition: Angle.h:26
Models an OGC SFS LinearRing. A LinearRing is a LineString which is both closed and simple...
Definition: LinearRing.h:57
DimensionType
Definition: Dimension.h:31
Definition: GeometryComponentFilter.h:43