GEOS  3.12.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 CoordinateSequenceFilter;
38 class LineString;
39 }
40 }
41 
42 namespace geos {
43 namespace geom { // geos::geom
44 
60 class GEOS_DLL Polygon: public Geometry {
61 
62 public:
63 
64  friend class GeometryFactory;
65 
67  typedef std::vector<const Polygon*> ConstVect;
68 
69  ~Polygon() override = default;
70 
77  std::unique_ptr<Polygon> clone() const
78  {
79  return std::unique_ptr<Polygon>(cloneImpl());
80  }
81 
82  std::unique_ptr<CoordinateSequence> getCoordinates() const override;
83 
84  std::size_t getNumPoints() const override;
85 
88 
90  uint8_t getCoordinateDimension() const override;
91 
92  bool hasM() const override;
93 
94  bool hasZ() 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;
140  bool equalsExact(const Geometry* other, double tolerance = 0) const override;
141  bool equalsIdentical(const Geometry* other) const override;
142  void apply_rw(const CoordinateFilter* filter) override;
143  void apply_ro(CoordinateFilter* filter) const override;
144  void apply_rw(GeometryFilter* filter) override;
145  void apply_ro(GeometryFilter* filter) const override;
146  void apply_rw(CoordinateSequenceFilter& filter) override;
147  void apply_ro(CoordinateSequenceFilter& filter) const override;
148  void apply_rw(GeometryComponentFilter* filter) override;
149  void apply_ro(GeometryComponentFilter* filter) const override;
150 
151  std::unique_ptr<Geometry> convexHull() const override;
152 
153  void normalize() override;
154 
163  void orientRings(bool exteriorCW);
164 
165  std::unique_ptr<Polygon> reverse() const { return std::unique_ptr<Polygon>(reverseImpl()); }
166 
167  const CoordinateXY* getCoordinate() const override;
168 
169  double getArea() const override;
170 
172  double getLength() const override;
173 
174  bool isRectangle() const override;
175 
176  const Envelope* getEnvelopeInternal() const override {
177  return shell->getEnvelopeInternal();
178  }
179 
180 protected:
181 
182 
183  Polygon(const Polygon& p);
184 
185  int compareToSameClass(const Geometry* p) const override;
186 
205  Polygon(std::unique_ptr<LinearRing> && newShell,
206  std::vector<std::unique_ptr<LinearRing>> && newHoles,
207  const GeometryFactory& newFactory);
208 
209  Polygon(std::unique_ptr<LinearRing> && newShell,
210  const GeometryFactory& newFactory);
211 
212  Polygon* cloneImpl() const override { return new Polygon(*this); }
213 
214  Polygon* reverseImpl() const override;
215 
216  std::unique_ptr<LinearRing> shell;
217 
218  std::vector<std::unique_ptr<LinearRing>> holes;
219 
220  void geometryChangedAction() override {}
221 
222  int
223  getSortIndex() const override
224  {
225  return SORTINDEX_POLYGON;
226  };
227 
228 
229 private:
230 
231  void normalize(LinearRing* ring, bool clockwise);
232 
233 };
234 
235 } // namespace geos::geom
236 } // namespace geos
237 
geos::geom::Polygon::getNumInteriorRing
std::size_t getNumInteriorRing() const
Returns number of interior rings (hole)
geos::geom::Polygon::getExteriorRing
const LinearRing * getExteriorRing() const
Returns the exterior ring (shell)
geos::geom::Polygon::getEnvelopeInternal
const Envelope * getEnvelopeInternal() const override
Returns the minimum and maximum x and y values in this Geometry, or a null Envelope if this Geometry ...
Definition: Polygon.h:176
geos::geom::Polygon::orientRings
void orientRings(bool exteriorCW)
Apply a ring ordering convention to this polygon, with interior rings having an opposite orientation ...
geos::geom::Polygon::normalize
void normalize() override
geos::geom::LinearRing
Models an OGC SFS LinearRing. A LinearRing is a LineString which is both closed and simple.
Definition: LinearRing.h:54
geos
Basic namespace for all GEOS functionalities.
Definition: Angle.h:25
geos::geom::GeometryComponentFilter
Definition: GeometryComponentFilter.h:41
geos::geom::Polygon::cloneImpl
Polygon * cloneImpl() const override
Make a deep-copy of this Geometry.
Definition: Polygon.h:212
geos::geom::Polygon::getGeometryType
std::string getGeometryType() const override
Return a string representation of this Geometry type.
geos::geom::Polygon::clone
std::unique_ptr< Polygon > clone() const
Definition: Polygon.h:77
geos::geom::Polygon::equalsExact
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...
geos::geom::Polygon::convexHull
std::unique_ptr< Geometry > convexHull() const override
Returns the smallest convex Polygon that contains all the points in the Geometry.
geos::geom::Polygon::getNumPoints
std::size_t getNumPoints() const override
Returns the count of this Geometrys vertices.
geos::geom::Polygon::getLength
double getLength() const override
Returns the perimeter of this Polygon
geos::geom::Dimension::DimensionType
DimensionType
Definition: Dimension.h:29
geos::geom::Polygon::getCoordinateDimension
uint8_t getCoordinateDimension() const override
Returns coordinate dimension.
geos::geom::Polygon::getCoordinates
std::unique_ptr< CoordinateSequence > getCoordinates() const override
Returns this Geometry vertices. Caller takes ownership of the returned object.
geos::geom::Polygon::equalsIdentical
bool equalsIdentical(const Geometry *other) const override
Returns true if the two geometries are of the same type and their vertices corresponding by index are...
geos::geom::Polygon::getBoundary
std::unique_ptr< Geometry > getBoundary() const override
Computes the boundary of this geometry.
geos::geom::Polygon::getDimension
Dimension::DimensionType getDimension() const override
Returns surface dimension (2)
geos::geom::Polygon
Represents a linear polygon, which may include holes.
Definition: Polygon.h:60
geos::geom::Geometry
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition: Geometry.h:186
geos::geom::Polygon::reverseImpl
Polygon * reverseImpl() const override
Make a geometry with coordinates in reverse order.
geos::geom::Polygon::apply_ro
void apply_ro(CoordinateSequenceFilter &filter) const override
geos::geom::Polygon::isEmpty
bool isEmpty() const override
Returns whether or not the set of points in this Geometry is empty.
geos::geom::Polygon::Polygon
Polygon(std::unique_ptr< LinearRing > &&newShell, std::vector< std::unique_ptr< LinearRing >> &&newHoles, const GeometryFactory &newFactory)
geos::geom::Polygon::getBoundaryDimension
int getBoundaryDimension() const override
Returns 1 (Polygon boundary is a MultiLineString)
geos::geom::Polygon::getArea
double getArea() const override
Returns the area of this Geometry.
geos::geom::CoordinateSequenceFilter
Interface for classes which provide operations that can be applied to the coordinates in a Coordinate...
Definition: CoordinateSequenceFilter.h:55
geos::geom::Polygon::isRectangle
bool isRectangle() const override
Polygon overrides to check for actual rectangle.
geos::geom::Polygon::geometryChangedAction
void geometryChangedAction() override
Notifies this Geometry that its Coordinates have been changed by an external party.
Definition: Polygon.h:220
geos::geom::Polygon::ConstVect
std::vector< const Polygon * > ConstVect
A vector of const Polygon pointers.
Definition: Polygon.h:67
geos::geom::Polygon::getGeometryTypeId
GeometryTypeId getGeometryTypeId() const override
Return an integer representation of this Geometry type.
geos::geom::Polygon::getCoordinate
const CoordinateXY * getCoordinate() const override
Returns a vertex of this Geometry, or NULL if this is the empty geometry.
geos::geom::Polygon::getInteriorRingN
const LinearRing * getInteriorRingN(std::size_t n) const
Get nth interior ring (hole)
geos::geom::Envelope
An Envelope defines a rectangulare region of the 2D coordinate plane.
Definition: Envelope.h:58
geos::geom::GeometryTypeId
GeometryTypeId
Geometry types.
Definition: Geometry.h:73
geos::geom::CoordinateFilter
Geometry classes support the concept of applying a coordinate filter to every coordinate in the Geome...
Definition: CoordinateFilter.h:43
geos::geom::GeometryFactory
Supplies a set of utility methods for building Geometry objects from CoordinateSequence or other Geom...
Definition: GeometryFactory.h:65
geos::geom::Polygon::releaseInteriorRings
std::vector< std::unique_ptr< LinearRing > > releaseInteriorRings()
Take ownership of this Polygon's interior rings. After releasing the rings, the Polygon should be con...
geos::geom::GeometryFilter
Geometry classes support the concept of applying a Geometry filter to the Geometry.
Definition: GeometryFilter.h:45
geos::geom::Polygon::releaseExteriorRing
std::unique_ptr< LinearRing > releaseExteriorRing()
Take ownership of this Polygon's exterior ring. After releasing the exterior ring,...
geos::geom::Polygon::apply_rw
void apply_rw(CoordinateSequenceFilter &filter) override