GEOS 3.16.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
86
87 bool contains(const EdgeRing& otherRing) const;
88 bool isPointInOrOut(const EdgeRing& otherRing) const;
89
90public:
96 void add(const PolygonizeDirectedEdge* de);
97
116 EdgeRing* findEdgeRingContaining(const std::vector<EdgeRing*> & erList) const;
117
128 static std::vector<PolygonizeDirectedEdge*> findDirEdgesInRing(PolygonizeDirectedEdge* startDE);
129
140 static const geom::CoordinateXY& ptNotInList(
141 const geom::CoordinateSequence* testPts,
142 const geom::CoordinateSequence* pts);
143
152 static bool isInList(const geom::CoordinateXY& pt,
153 const geom::CoordinateSequence* pts);
154
155 explicit EdgeRing(const geom::GeometryFactory* newFactory);
156
157 ~EdgeRing() = default;
158
159 void build(PolygonizeDirectedEdge* startDE);
160
161 void computeHole();
162
163 const DeList& getEdges() const {
164 return deList;
165 }
166
174 bool isHole() const {
175 return is_hole;
176 }
177
178 /* Indicates whether we know if the ring should be included in a polygonizer
179 * output of only polygons.
180 */
181 bool isIncludedSet() const {
182 return is_included_set;
183 }
184
185 /* Indicates whether the ring should be included in a polygonizer output of
186 * only polygons.
187 */
188 bool isIncluded() const {
189 return is_included;
190 }
191
192 void setIncluded(bool included) {
193 is_included = included;
194 is_included_set = true;
195 }
196
197 bool isProcessed() const {
198 return is_processed;
199 }
200
201 void setProcessed(bool processed) {
202 is_processed = processed;
203 }
204
210 void setShell(EdgeRing* shellRing) {
211 shell = shellRing;
212 }
213
219 bool hasShell() const {
220 return shell != nullptr;
221 }
222
230 return isHole() ? shell : this;
231 }
232
239 bool isOuterHole() const {
240 if (!isHole()) {
241 return false;
242 }
243
244 return !hasShell();
245 }
246
252 bool isOuterShell() const {
253 return getOuterHole() != nullptr;
254 }
255
266
272
278 void addHole(std::unique_ptr<geom::Curve> hole);
279
280 void addHole(EdgeRing* holeER);
281
290 std::unique_ptr<geom::Surface> getPolygon();
291
296 bool isValid() const;
297
298 void computeValid();
299
306 const geom::Curve* getRingInternal() const;
307
314 std::unique_ptr<geom::Curve> getRingOwnership();
315
316 geom::Location locate(const geom::CoordinateXY& pt) const {
317 return getLocator()->locate(&pt);
318 }
319};
320
321} // namespace geos::operation::polygonize
322} // namespace geos::operation
323} // namespace geos
324
325#ifdef _MSC_VER
326#pragma warning(pop)
327#endif
328
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:72
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:210
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:239
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:252
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:174
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:229
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:219
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