GEOS  3.13.0dev
CoverageRingEdges.h
1 /**********************************************************************
2  *
3  * GEOS - Geometry Engine Open Source
4  * http://geos.osgeo.org
5  *
6  * Copyright (C) 2023 Paul Ramsey <pramsey@cleverelephant.ca>
7  * Copyright (c) 2023 Martin Davis.
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 #pragma once
17 
18 #include <geos/geom/Coordinate.h>
19 #include <geos/geom/LineSegment.h>
20 
21 #include <set>
22 #include <map>
23 
24 // Forward declarations
25 namespace geos {
26 namespace geom {
27 class CoordinateSequence;
28 class Geometry;
29 class LinearRing;
30 class MultiPolygon;
31 class Polygon;
32 }
33 namespace coverage {
34 class CoverageEdge;
35 }
36 }
37 
45 
46 namespace geos { // geos
47 namespace coverage { // geos.coverage
48 
59 class GEOS_DLL CoverageRingEdges {
60 
61 private:
62 
63  // Members
64  const std::vector<const Geometry*>& m_coverage;
65  std::map<const LinearRing*, std::vector<CoverageEdge*>> m_ringEdgesMap;
66  std::vector<CoverageEdge*> m_edges;
67  std::vector<std::unique_ptr<CoverageEdge>> m_edgeStore;
68 
69  /* Turn off copy constructors for MSVC */
70  CoverageRingEdges(const CoverageRingEdges&) = delete;
71  CoverageRingEdges& operator=(const CoverageRingEdges&) = delete;
72 
73 public:
74 
75  CoverageRingEdges(const std::vector<const Geometry*>& coverage)
76  : m_coverage(coverage)
77  {
78  build();
79  };
80 
81 
82  std::vector<CoverageEdge*>& getEdges()
83  {
84  return m_edges;
85  };
86 
93  std::vector<CoverageEdge*> selectEdges(
94  std::size_t ringCount) const;
95 
101  std::vector<std::unique_ptr<Geometry>> buildCoverage() const;
102 
103 
104 private:
105 
106  void build();
107 
108  void addRingEdges(
109  const LinearRing* ring,
110  Coordinate::UnorderedSet& nodes,
111  LineSegment::UnorderedSet& boundarySegs,
112  std::map<LineSegment, CoverageEdge*>& uniqueEdgeMap);
113 
114  void addBoundaryInnerNodes(
115  const LinearRing* ring,
116  LineSegment::UnorderedSet& boundarySegs,
117  Coordinate::UnorderedSet& nodes);
118 
119  std::vector<CoverageEdge*> extractRingEdges(
120  const LinearRing* ring,
121  std::map<LineSegment, CoverageEdge*>& uniqueEdgeMap,
122  Coordinate::UnorderedSet& nodes);
123 
124  CoverageEdge* createEdge(
125  const CoordinateSequence& ring,
126  std::map<LineSegment, CoverageEdge*>& uniqueEdgeMap);
127 
128  CoverageEdge* createEdge(
129  const CoordinateSequence& ring,
130  std::size_t start, std::size_t end,
131  std::map<LineSegment, CoverageEdge*>& uniqueEdgeMap);
132 
133  std::size_t findNextNodeIndex(
134  const CoordinateSequence& ring,
135  std::size_t start,
136  Coordinate::UnorderedSet& nodes) const;
137 
138  static std::size_t next(
139  std::size_t index,
140  const CoordinateSequence& ring);
141 
142  Coordinate::UnorderedSet findMultiRingNodes(
143  const std::vector<const Geometry*>& coverage);
144 
145  Coordinate::UnorderedSet findBoundaryNodes(
146  LineSegment::UnorderedSet& lineSegments);
147 
148  std::unique_ptr<Geometry> buildPolygonal(
149  const Geometry* geom) const;
150 
151  std::unique_ptr<Geometry> buildMultiPolygon(
152  const MultiPolygon* geom) const;
153 
154  std::unique_ptr<Polygon> buildPolygon(
155  const Polygon* polygon) const;
156 
157  std::unique_ptr<LinearRing> buildRing(
158  const LinearRing* ring) const;
159 
160  bool isEdgeDirForward(
161  const std::vector<CoverageEdge*>& ringEdges,
162  std::size_t index,
163  const Coordinate& prevPt) const;
164 
165 
166 };
167 
168 } // namespace geos.coverage
169 } // namespace geos
Definition: CoverageEdge.h:54
Definition: CoverageRingEdges.h:59
std::vector< CoverageEdge * > selectEdges(std::size_t ringCount) const
std::vector< std::unique_ptr< Geometry > > buildCoverage() const
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:216
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition: Geometry.h:196
Definition: LineSegment.h:61
Models an OGC SFS LinearRing. A LinearRing is a LineString which is both closed and simple.
Definition: LinearRing.h:54
Definition: MultiPolygon.h:58
Represents a linear polygon, which may include holes.
Definition: Polygon.h:61
Basic namespace for all GEOS functionalities.
Definition: Angle.h:25