GEOS 3.9.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
37namespace geos {
38namespace geom { // geos::geom
39class Coordinate;
40class CoordinateArraySequence;
41class CoordinateSequenceFilter;
42class LineString;
43}
44}
45
46namespace geos {
47namespace geom { // geos::geom
48
64class GEOS_DLL Polygon: public Geometry {
65
66public:
67
68 friend class GeometryFactory;
69
71 typedef std::vector<const Polygon*> ConstVect;
72
73 ~Polygon() override = default;
74
81 std::unique_ptr<Geometry>
82 clone() const override
83 {
84 return std::unique_ptr<Geometry>(new Polygon(*this));
85 }
86
87 std::unique_ptr<CoordinateSequence> getCoordinates() const override;
88
89 size_t getNumPoints() const override;
90
93
95 uint8_t getCoordinateDimension() const override;
96
98 int getBoundaryDimension() const override;
99
106 std::unique_ptr<Geometry> getBoundary() const override;
107
108 bool isEmpty() const override;
109
112
114 size_t getNumInteriorRing() const;
115
117 const LinearRing* getInteriorRingN(std::size_t n) const;
118
119 std::string getGeometryType() const override;
121 bool equalsExact(const Geometry* other, double tolerance = 0) const override;
122 void apply_rw(const CoordinateFilter* filter) override;
123 void apply_ro(CoordinateFilter* filter) const override;
124 void apply_rw(GeometryFilter* filter) override;
125 void apply_ro(GeometryFilter* filter) const override;
126 void apply_rw(CoordinateSequenceFilter& filter) override;
127 void apply_ro(CoordinateSequenceFilter& filter) const override;
128 void apply_rw(GeometryComponentFilter* filter) override;
129 void apply_ro(GeometryComponentFilter* filter) const override;
130
131 std::unique_ptr<Geometry> convexHull() const override;
132
133 void normalize() override;
134
135 std::unique_ptr<Geometry> reverse() const override;
136
137 int compareToSameClass(const Geometry* p) const override; //was protected
138
139 const Coordinate* getCoordinate() const override;
140
141 double getArea() const override;
142
144 double getLength() const override;
145
146 bool isRectangle() const override;
147
148protected:
149
150
151 Polygon(const Polygon& p);
152
171 Polygon(LinearRing* newShell, std::vector<LinearRing*>* newHoles,
172 const GeometryFactory* newFactory);
173
174 Polygon(std::unique_ptr<LinearRing> && newShell,
175 const GeometryFactory& newFactory);
176
177 Polygon(std::unique_ptr<LinearRing> && newShell,
178 std::vector<std::unique_ptr<LinearRing>> && newHoles,
179 const GeometryFactory& newFactory);
180
181 std::unique_ptr<LinearRing> shell;
182
183 std::vector<std::unique_ptr<LinearRing>> holes;
184
185 Envelope::Ptr computeEnvelopeInternal() const override;
186
187 int
188 getSortIndex() const override
189 {
190 return SORTINDEX_POLYGON;
191 };
192
193
194private:
195
196 void normalize(LinearRing* ring, bool clockwise);
197};
198
199} // namespace geos::geom
200} // namespace geos
201
202#endif // ndef GEOS_GEOM_POLYGON_H
Geometry classes support the concept of applying a coordinate filter to every coordinate in the Geome...
Definition: CoordinateFilter.h:43
Interface for classes which provide operations that can be applied to the coordinates in a Coordinate...
Definition: CoordinateSequenceFilter.h:57
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:60
DimensionType
Definition: Dimension.h:31
Definition: GeometryComponentFilter.h:43
Supplies a set of utility methods for building Geometry objects from CoordinateSequence or other Geom...
Definition: GeometryFactory.h:68
Geometry classes support the concept of applying a Geometry filter to the Geometry.
Definition: GeometryFilter.h:47
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition: Geometry.h:188
Models an OGC SFS LinearRing. A LinearRing is a LineString which is both closed and simple.
Definition: LinearRing.h:54
Represents a linear polygon, which may include holes.
Definition: Polygon.h:64
void normalize() override
const LinearRing * getExteriorRing() const
Returns the exterior ring (shell)
double getLength() const override
Returns the perimeter of this Polygon
size_t getNumPoints() const override
Returns the count of this Geometrys vertices.
std::unique_ptr< Geometry > reverse() const override
Computes a new geometry which has all component coordinate sequences in reverse order (opposite orien...
uint8_t getCoordinateDimension() const override
Returns coordinate dimension.
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::vector< const Polygon * > ConstVect
A vector of const Polygon pointers.
Definition: Polygon.h:71
double getArea() const override
Returns the area of this Geometry.
const Coordinate * getCoordinate() const override
Returns a vertex of this Geometry, or NULL if this is the empty geometry.
std::unique_ptr< CoordinateSequence > getCoordinates() const override
Returns this Geometry vertices. Caller takes ownership of the returned object.
std::unique_ptr< Geometry > getBoundary() const override
Computes the boundary of this geometry.
bool isRectangle() const override
Polygon overrides to check for actual rectangle.
std::unique_ptr< Geometry > convexHull() const override
Returns the smallest convex Polygon that contains all the points in the Geometry.
std::unique_ptr< Geometry > clone() const override
Definition: Polygon.h:82
void apply_ro(CoordinateSequenceFilter &filter) const override
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...
const LinearRing * getInteriorRingN(std::size_t n) const
Get nth interior ring (hole)
Dimension::DimensionType getDimension() const override
Returns surface dimension (2)
size_t getNumInteriorRing() const
Returns number of interior rings (hole)
GeometryTypeId getGeometryTypeId() const override
Return an integer representation of this Geometry type.
void apply_rw(CoordinateSequenceFilter &filter) override
GeometryTypeId
Geometry types.
Definition: Geometry.h:75
Basic namespace for all GEOS functionalities.
Definition: IndexedNestedRingTester.h:26