GEOS 3.15.0dev
operation/polygonize/EdgeRing.h
1/**********************************************************************
2 *
3 * GEOS - Geometry Engine Open Source
4 * http://geos.osgeo.org
5 *
6 * Copyright (C) 2006 Refractions Research Inc.
7 * Copyright (C) 2001-2002 Vivid Solutions Inc.
8 *
9 * This is free software; you can redistribute and/or modify it under
10 * the terms of the GNU Lesser General Public Licence as published
11 * by the Free Software Foundation.
12 * See the COPYING file for more information.
13 *
14 **********************************************************************
15 *
16 * Last port: operation/polygonize/EdgeRing.java 0b3c7e3eb0d3e
17 *
18 **********************************************************************/
19
20#pragma once
21
22#include <geos/export.h>
23#include <geos/algorithm/locate/PointOnGeometryLocator.h>
24#include <geos/operation/polygonize/PolygonizeDirectedEdge.h>
25#include <geos/geom/Geometry.h>
26#include <geos/geom/LinearRing.h>
27#include <geos/geom/Polygon.h>
28
29#include <memory>
30#include <vector>
31#include <geos/geom/Location.h>
32
33#ifdef _MSC_VER
34#pragma warning(push)
35#pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
36#endif
37
38// Forward declarations
39namespace geos {
40namespace geom {
41class Curve;
42class LineString;
43class CoordinateSequence;
44class GeometryFactory;
45class Coordinate;
46}
47namespace planargraph {
48class DirectedEdge;
49}
50}
51
52namespace geos {
53namespace operation { // geos::operation
54namespace polygonize { // geos::operation::polygonize
55
60class GEOS_DLL EdgeRing {
61private:
62 const geom::GeometryFactory* factory;
63
64 typedef std::vector<const PolygonizeDirectedEdge*> DeList;
65 DeList deList;
66
67 // cache the following data for efficiency
68 mutable std::unique_ptr<geom::Curve> ring;
69 mutable std::unique_ptr<algorithm::locate::PointOnGeometryLocator> ringLocator;
70
71 std::vector<std::unique_ptr<geom::Curve>> holes;
72
73 EdgeRing* shell = nullptr;
74 bool is_hole;
75 bool is_valid = false;
76 bool is_processed = false;
77 bool is_included_set = false;
78 bool is_included = false;
79 bool visitedByUpdateIncludedRecursive = false;
80
81 const geom::Envelope& getEnvelope() const {
82 return *getRingInternal()->getEnvelopeInternal();
83 }
84
85 static void addEdge(const geom::CoordinateSequence* coords,
86 bool isForward,
87 geom::CoordinateSequence* coordList);
88
90
91 bool contains(const EdgeRing& otherRing) const;
92 bool isPointInOrOut(const EdgeRing& otherRing) const;
93
94public:
101
120 EdgeRing* findEdgeRingContaining(const std::vector<EdgeRing*> & erList) const;
121
132 static std::vector<PolygonizeDirectedEdge*> findDirEdgesInRing(PolygonizeDirectedEdge* startDE);
133
144 static const geom::CoordinateXY& ptNotInList(
145 const geom::CoordinateSequence* testPts,
146 const geom::CoordinateSequence* pts);
147
156 static bool isInList(const geom::CoordinateXY& pt,
157 const geom::CoordinateSequence* pts);
158
159 explicit EdgeRing(const geom::GeometryFactory* newFactory);
160
161 ~EdgeRing() = default;
162
163 void build(PolygonizeDirectedEdge* startDE);
164
165 void computeHole();
166
167 const DeList& getEdges() const {
168 return deList;
169 }
170
178 bool isHole() const {
179 return is_hole;
180 }
181
182 /* Indicates whether we know if the ring should be included in a polygonizer
183 * output of only polygons.
184 */
185 bool isIncludedSet() const {
186 return is_included_set;
187 }
188
189 /* Indicates whether the ring should be included in a polygonizer output of
190 * only polygons.
191 */
192 bool isIncluded() const {
193 return is_included;
194 }
195
196 void setIncluded(bool included) {
197 is_included = included;
198 is_included_set = true;
199 }
200
201 bool isProcessed() const {
202 return is_processed;
203 }
204
205 void setProcessed(bool processed) {
206 is_processed = processed;
207 }
208
214 void setShell(EdgeRing* shellRing) {
215 shell = shellRing;
216 }
217
223 bool hasShell() const {
224 return shell != nullptr;
225 }
226
234 return isHole() ? shell : this;
235 }
236
243 bool isOuterHole() const {
244 if (!isHole()) {
245 return false;
246 }
247
248 return !hasShell();
249 }
250
256 bool isOuterShell() const {
257 return getOuterHole() != nullptr;
258 }
259
270
276
282 void addHole(std::unique_ptr<geom::Curve> hole);
283
284 void addHole(EdgeRing* holeER);
285
294 std::unique_ptr<geom::Surface> getPolygon();
295
300 bool isValid() const;
301
302 void computeValid();
303
310 const geom::Curve* getRingInternal() const;
311
318 std::unique_ptr<geom::Curve> getRingOwnership();
319
320 geom::Location locate(const geom::CoordinateXY& pt) const {
321 return getLocator()->locate(&pt);
322 }
323};
324
325} // namespace geos::operation::polygonize
326} // namespace geos::operation
327} // namespace geos
328
329#ifdef _MSC_VER
330#pragma warning(pop)
331#endif
332
An interface for classes which determine the Location of points in Polygon or MultiPolygon geometries...
Definition PointOnGeometryLocator.h:36
virtual geom::Location locate(const geom::CoordinateXY *p)=0
The internal representation of a list of coordinates inside a Geometry.
Definition CoordinateSequence.h:56
An Envelope defines a rectangulare region of the 2D coordinate plane.
Definition Envelope.h:59
Supplies a set of utility methods for building Geometry objects from CoordinateSequence or other Geom...
Definition GeometryFactory.h:71
Represents a ring of PolygonizeDirectedEdge which form a ring of a polygon. The ring may be either an...
Definition operation/polygonize/EdgeRing.h:60
void setShell(EdgeRing *shellRing)
Sets the containing shell ring of a ring that has been determined to be a hole.
Definition operation/polygonize/EdgeRing.h:214
EdgeRing * getOuterHole() const
Gets the outer hole of a shell, if it has one. An outer hole is one that is not contained in any othe...
std::unique_ptr< geom::Surface > getPolygon()
Computes the Polygon formed by this ring and any contained holes.
std::unique_ptr< geom::Curve > getRingOwnership()
Returns this ring or null if an Exception occurs while creating it (such as a topology problem).
bool isOuterHole() const
Tests whether this ring is an outer hole. A hole is an outer hole if it is not contained by any shell...
Definition operation/polygonize/EdgeRing.h:243
void addHole(std::unique_ptr< geom::Curve > hole)
Adds a hole to the polygon formed by this ring.
bool isOuterShell() const
Tests whether this ring is an outer shell.
Definition operation/polygonize/EdgeRing.h:256
const geom::Curve * getRingInternal() const
Returns this ring or null if an Exception occurs while creating it (such as a topology problem).
EdgeRing * findEdgeRingContaining(const std::vector< EdgeRing * > &erList) const
Find the innermost enclosing shell EdgeRing containing this, if any.
bool isHole() const
Tests whether this ring is a hole.
Definition operation/polygonize/EdgeRing.h:178
EdgeRing * getShell()
Gets the shell for this ring. The shell is the ring itself if it is not a hole, otherwise it is the p...
Definition operation/polygonize/EdgeRing.h:233
bool isValid() const
Tests if the LinearRing ring formed by this edge ring is topologically valid.
void updateIncludedRecursive()
Updates the included status for currently non-included shells based on whether they are adjacent to a...
static bool isInList(const geom::CoordinateXY &pt, const geom::CoordinateSequence *pts)
Tests whether a given point is in an array of points. Uses a value-based test.
bool hasShell() const
Tests whether this ring has a shell assigned to it.
Definition operation/polygonize/EdgeRing.h:223
static const geom::CoordinateXY & ptNotInList(const geom::CoordinateSequence *testPts, const geom::CoordinateSequence *pts)
Finds a point in a list of points which is not contained in another list of points.
static std::vector< PolygonizeDirectedEdge * > findDirEdgesInRing(PolygonizeDirectedEdge *startDE)
Traverses a ring of DirectedEdges, accumulating them into a list.
void add(const PolygonizeDirectedEdge *de)
Adds a DirectedEdge which is known to form part of this ring.
A DirectedEdge of a PolygonizeGraph, which represents an edge of a polygon formed by the graph.
Definition PolygonizeDirectedEdge.h:52
Location
Constants representing the location of a point relative to a geometry.
Definition Location.h:32
Basic namespace for all GEOS functionalities.
Definition geos.h:38