GEOS  3.10.2
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 
21 #ifndef GEOS_OP_POLYGONIZE_EDGERING_H
22 #define GEOS_OP_POLYGONIZE_EDGERING_H
23 
24 #include <geos/export.h>
25 #include <geos/algorithm/locate/IndexedPointInAreaLocator.h>
26 #include <geos/operation/polygonize/PolygonizeDirectedEdge.h>
27 #include <geos/geom/Geometry.h>
28 #include <geos/geom/LinearRing.h>
29 #include <geos/geom/Polygon.h>
30 
31 #include <memory>
32 #include <vector>
33 #include <geos/geom/Location.h>
34 
35 #ifdef _MSC_VER
36 #pragma warning(push)
37 #pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
38 #endif
39 
40 // Forward declarations
41 namespace geos {
42 namespace geom {
43 class LineString;
44 class CoordinateSequence;
45 class GeometryFactory;
46 class Coordinate;
47 }
48 namespace planargraph {
49 class DirectedEdge;
50 }
51 }
52 
53 namespace geos {
54 namespace operation { // geos::operation
55 namespace polygonize { // geos::operation::polygonize
56 
61 class GEOS_DLL EdgeRing {
62 private:
63  const geom::GeometryFactory* factory;
64 
65  typedef std::vector<const PolygonizeDirectedEdge*> DeList;
66  DeList deList;
67 
68  // cache the following data for efficiency
69  std::unique_ptr<geom::LinearRing> ring;
70  std::unique_ptr<geom::CoordinateArraySequence> ringPts;
71  std::unique_ptr<algorithm::locate::PointOnGeometryLocator> ringLocator;
72 
73  std::unique_ptr<std::vector<std::unique_ptr<geom::LinearRing>>> holes;
74 
75  EdgeRing* shell = nullptr;
76  bool is_hole;
77  bool is_processed = false;
78  bool is_included_set = false;
79  bool is_included = false;
80  bool visitedByUpdateIncludedRecursive = false;
81 
88  const geom::CoordinateSequence* getCoordinates();
89 
90  static void addEdge(const geom::CoordinateSequence* coords,
91  bool isForward,
93 
95  if (ringLocator == nullptr) {
96  ringLocator.reset(new algorithm::locate::IndexedPointInAreaLocator(*getRingInternal()));
97  }
98  return ringLocator.get();
99  }
100 
101 public:
107  void add(const PolygonizeDirectedEdge* de);
108 
127  EdgeRing* findEdgeRingContaining(const std::vector<EdgeRing*> & erList);
128 
139  static std::vector<PolygonizeDirectedEdge*> findDirEdgesInRing(PolygonizeDirectedEdge* startDE);
140 
152  const geom::CoordinateSequence* testPts,
153  const geom::CoordinateSequence* pts);
154 
163  static bool isInList(const geom::Coordinate& pt,
164  const geom::CoordinateSequence* pts);
165 
166  explicit EdgeRing(const geom::GeometryFactory* newFactory);
167 
168  ~EdgeRing() = default;
169 
170  void build(PolygonizeDirectedEdge* startDE);
171 
172  void computeHole();
173 
181  bool isHole() const {
182  return is_hole;
183  }
184 
185  /* Indicates whether we know if the ring should be included in a polygonizer
186  * output of only polygons.
187  */
188  bool isIncludedSet() const {
189  return is_included_set;
190  }
191 
192  /* Indicates whether the ring should be included in a polygonizer output of
193  * only polygons.
194  */
195  bool isIncluded() const {
196  return is_included;
197  }
198 
199  void setIncluded(bool included) {
200  is_included = included;
201  is_included_set = true;
202  }
203 
204  bool isProcessed() const {
205  return is_processed;
206  }
207 
208  void setProcessed(bool processed) {
209  is_processed = processed;
210  }
211 
217  void setShell(EdgeRing* shellRing) {
218  shell = shellRing;
219  }
220 
226  bool hasShell() const {
227  return shell != nullptr;
228  }
229 
237  return isHole() ? shell : this;
238  }
239 
246  bool isOuterHole() const {
247  if (!isHole()) {
248  return false;
249  }
250 
251  return !hasShell();
252  }
253 
259  bool isOuterShell() const {
260  return getOuterHole() != nullptr;
261  }
262 
273 
279 
286 
287  void addHole(EdgeRing* holeER);
288 
297  std::unique_ptr<geom::Polygon> getPolygon();
298 
303  bool isValid();
304 
313  std::unique_ptr<geom::LineString> getLineString();
314 
323 
331  std::unique_ptr<geom::LinearRing> getRingOwnership();
332 
333  bool isInRing(const geom::Coordinate & pt) {
334  return geom::Location::EXTERIOR != getLocator()->locate(&pt);
335  }
336 };
337 
338 } // namespace geos::operation::polygonize
339 } // namespace geos::operation
340 } // namespace geos
341 
342 #ifdef _MSC_VER
343 #pragma warning(pop)
344 #endif
345 
346 #endif // GEOS_OP_POLYGONIZE_EDGERING_H
Determines the location of Coordinates relative to an areal geometry, using indexing for efficiency.
Definition: IndexedPointInAreaLocator.h:55
An interface for classes which determine the Location of points in Polygon or MultiPolygon geometries...
Definition: PointOnGeometryLocator.h:37
The default implementation of CoordinateSequence.
Definition: CoordinateArraySequence.h:37
The internal representation of a list of coordinates inside a Geometry.
Definition: CoordinateSequence.h:58
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:60
Supplies a set of utility methods for building Geometry objects from CoordinateSequence or other Geom...
Definition: GeometryFactory.h:68
Models an OGC SFS LinearRing. A LinearRing is a LineString which is both closed and simple.
Definition: LinearRing.h:57
Represents a ring of PolygonizeDirectedEdge which form a ring of a polygon. The ring may be either an...
Definition: operation/polygonize/EdgeRing.h:61
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:217
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 * 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:236
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:246
bool isOuterShell() const
Tests whether this ring is an outer shell.
Definition: operation/polygonize/EdgeRing.h:259
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.
std::unique_ptr< geom::LineString > getLineString()
Gets the coordinates for this ring as a LineString.
bool isHole() const
Tests whether this ring is a hole.
Definition: operation/polygonize/EdgeRing.h:181
static std::vector< PolygonizeDirectedEdge * > findDirEdgesInRing(PolygonizeDirectedEdge *startDE)
Traverses a ring of DirectedEdges, accumulating them into a list.
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...
void updateIncludedRecursive()
Updates the included status for currently non-included shells based on whether they are adjacent to a...
EdgeRing * findEdgeRingContaining(const std::vector< EdgeRing * > &erList)
Find the innermost enclosing shell EdgeRing containing this, if any.
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...
bool hasShell() const
Tests whether this ring has a shell assigned to it.
Definition: operation/polygonize/EdgeRing.h:226
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.
void add(const PolygonizeDirectedEdge *de)
Adds a DirectedEdge which is known to form part of this ring.
geom::LinearRing * getRingInternal()
Returns this ring as a LinearRing, or null if an Exception occurs while creating it (such as a topolo...
bool isValid()
Tests if the LinearRing ring formed by this edge ring is topologically valid.
A DirectedEdge of a PolygonizeGraph, which represents an edge of a polygon formed by the graph.
Definition: PolygonizeDirectedEdge.h:54
Basic namespace for all GEOS functionalities.
Definition: Angle.h:26