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/IndexedPointInAreaLocator.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 LineString;
42class CoordinateSequence;
43class GeometryFactory;
44class Coordinate;
45}
46namespace planargraph {
47class DirectedEdge;
48}
49}
50
51namespace geos {
52namespace operation { // geos::operation
53namespace polygonize { // geos::operation::polygonize
54
59class GEOS_DLL EdgeRing {
60private:
61 const geom::GeometryFactory* factory;
62
63 typedef std::vector<const PolygonizeDirectedEdge*> DeList;
64 DeList deList;
65
66 // cache the following data for efficiency
67 mutable std::unique_ptr<geom::LinearRing> ring;
68 mutable std::shared_ptr<geom::CoordinateSequence> ringPts;
69 mutable std::unique_ptr<algorithm::locate::PointOnGeometryLocator> ringLocator;
70
71 std::unique_ptr<std::vector<std::unique_ptr<geom::LinearRing>>> 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
87 const geom::CoordinateSequence* getCoordinates() const;
88
89 const geom::Envelope& getEnvelope() const {
90 return *getRingInternal()->getEnvelopeInternal();
91 }
92
93 static void addEdge(const geom::CoordinateSequence* coords,
94 bool isForward,
95 geom::CoordinateSequence* coordList);
96
98 if (ringLocator == nullptr) {
99 ringLocator.reset(new algorithm::locate::IndexedPointInAreaLocator(*getRingInternal()));
100 }
101 return ringLocator.get();
102 }
103
104 bool contains(const EdgeRing& otherRing) const;
105 bool isPointInOrOut(const EdgeRing& otherRing) const;
106
107public:
114
133 EdgeRing* findEdgeRingContaining(const std::vector<EdgeRing*> & erList);
134
145 static std::vector<PolygonizeDirectedEdge*> findDirEdgesInRing(PolygonizeDirectedEdge* startDE);
146
158 const geom::CoordinateSequence* testPts,
159 const geom::CoordinateSequence* pts);
160
169 static bool isInList(const geom::Coordinate& pt,
170 const geom::CoordinateSequence* pts);
171
172 explicit EdgeRing(const geom::GeometryFactory* newFactory);
173
174 ~EdgeRing() = default;
175
176 void build(PolygonizeDirectedEdge* startDE);
177
178 void computeHole();
179
180 const DeList& getEdges() const {
181 return deList;
182 }
183
191 bool isHole() const {
192 return is_hole;
193 }
194
195 /* Indicates whether we know if the ring should be included in a polygonizer
196 * output of only polygons.
197 */
198 bool isIncludedSet() const {
199 return is_included_set;
200 }
201
202 /* Indicates whether the ring should be included in a polygonizer output of
203 * only polygons.
204 */
205 bool isIncluded() const {
206 return is_included;
207 }
208
209 void setIncluded(bool included) {
210 is_included = included;
211 is_included_set = true;
212 }
213
214 bool isProcessed() const {
215 return is_processed;
216 }
217
218 void setProcessed(bool processed) {
219 is_processed = processed;
220 }
221
227 void setShell(EdgeRing* shellRing) {
228 shell = shellRing;
229 }
230
236 bool hasShell() const {
237 return shell != nullptr;
238 }
239
247 return isHole() ? shell : this;
248 }
249
256 bool isOuterHole() const {
257 if (!isHole()) {
258 return false;
259 }
260
261 return !hasShell();
262 }
263
269 bool isOuterShell() const {
270 return getOuterHole() != nullptr;
271 }
272
283
289
296
297 void addHole(EdgeRing* holeER);
298
307 std::unique_ptr<geom::Polygon> getPolygon();
308
313 bool isValid() const;
314
315 void computeValid();
316
325 std::unique_ptr<geom::LineString> getLineString();
326
335
343 std::unique_ptr<geom::LinearRing> getRingOwnership();
344
345 geom::Location locate(const geom::CoordinateXY& pt) const {
346 return getLocator()->locate(&pt);
347 }
348};
349
350} // namespace geos::operation::polygonize
351} // namespace geos::operation
352} // namespace geos
353
354#ifdef _MSC_VER
355#pragma warning(pop)
356#endif
357
Determines the location of Coordinates relative to an areal geometry, using indexing for efficiency.
Definition IndexedPointInAreaLocator.h:54
An interface for classes which determine the Location of points in Polygon or MultiPolygon geometries...
Definition PointOnGeometryLocator.h:36
The internal representation of a list of coordinates inside a Geometry.
Definition CoordinateSequence.h:56
Coordinate is the lightweight class used to store coordinates.
Definition Coordinate.h:217
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
Models an OGC SFS LinearRing. A LinearRing is a LineString which is both closed and simple.
Definition LinearRing.h:54
Represents a ring of PolygonizeDirectedEdge which form a ring of a polygon. The ring may be either an...
Definition operation/polygonize/EdgeRing.h:59
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:227
static bool isInList(const geom::Coordinate &pt, const geom::CoordinateSequence *pts)
Tests whether a given point is in an array of points. Uses a value-based test.
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...
const geom::LinearRing * getRingInternal() const
Returns this ring as a LinearRing, or null if an Exception occurs while creating it (such as a topolo...
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:256
bool isOuterShell() const
Tests whether this ring is an outer shell.
Definition operation/polygonize/EdgeRing.h:269
std::unique_ptr< geom::LinearRing > getRingOwnership()
Returns this ring as a LinearRing, or null if an Exception occurs while creating it (such as a topolo...
void addHole(geom::LinearRing *hole)
Adds a hole to the polygon formed by this ring.
std::unique_ptr< geom::Polygon > getPolygon()
Computes the Polygon formed by this ring and any contained holes.
static const geom::Coordinate & 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.
EdgeRing * findEdgeRingContaining(const std::vector< EdgeRing * > &erList)
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:191
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:246
bool isValid() const
Tests if the LinearRing ring formed by this edge ring is topologically valid.
std::unique_ptr< geom::LineString > getLineString()
Gets the coordinates for this ring as a LineString.
void updateIncludedRecursive()
Updates the included status for currently non-included shells based on whether they are adjacent to a...
bool hasShell() const
Tests whether this ring has a shell assigned to it.
Definition operation/polygonize/EdgeRing.h:236
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