GEOS  3.13.0dev
EdgeNodingBuilder.h
1 /**********************************************************************
2  *
3  * GEOS - Geometry Engine Open Source
4  * http://geos.osgeo.org
5  *
6  * Copyright (C) 2020 Paul Ramsey <pramsey@cleverelephant.ca>
7  *
8  * This is free software; you can redistribute and/or modify it under
9  * the terms of the GNU Lesser General Public Licence as published
10  * by the Free Software Foundation.
11  * See the COPYING file for more information.
12  *
13  **********************************************************************
14  *
15  * Last port: operation/overlayng/EdgeNodingBuilder.java 6ef89b096
16  *
17  **********************************************************************/
18 
19 #pragma once
20 
21 #include <geos/algorithm/LineIntersector.h>
22 #include <geos/algorithm/Orientation.h>
23 #include <geos/geom/Coordinate.h>
24 #include <geos/geom/CoordinateSequence.h>
25 #include <geos/geom/CoordinateSequence.h>
26 #include <geos/geom/Envelope.h>
27 #include <geos/geom/Geometry.h>
28 #include <geos/geom/GeometryCollection.h>
29 #include <geos/geom/LinearRing.h>
30 #include <geos/geom/LineString.h>
31 #include <geos/geom/MultiLineString.h>
32 #include <geos/geom/MultiPolygon.h>
33 #include <geos/geom/Polygon.h>
34 #include <geos/noding/IntersectionAdder.h>
35 #include <geos/noding/MCIndexNoder.h>
36 #include <geos/noding/Noder.h>
37 #include <geos/noding/NodedSegmentString.h>
38 #include <geos/noding/SegmentString.h>
39 #include <geos/noding/ValidatingNoder.h>
40 #include <geos/noding/snapround/SnapRoundingNoder.h>
41 #include <geos/operation/overlayng/Edge.h>
42 #include <geos/operation/overlayng/EdgeSourceInfo.h>
43 #include <geos/operation/overlayng/InputGeometry.h>
44 #include <geos/operation/overlayng/LineLimiter.h>
45 #include <geos/operation/overlayng/OverlayUtil.h>
46 #include <geos/operation/overlayng/RingClipper.h>
47 #include <geos/operation/valid/RepeatedPointRemover.h>
48 
49 
50 #include <geos/export.h>
51 #include <array>
52 #include <memory>
53 #include <deque>
54 
55 using namespace geos::geom;
56 using namespace geos::noding;
59 
60 
61 namespace geos { // geos.
62 namespace operation { // geos.operation
63 namespace overlayng { // geos.operation.overlayng
64 
80 class GEOS_DLL EdgeNodingBuilder {
81 
82 private:
83 
84  // Constants
85  static constexpr int MIN_LIMIT_PTS = 20;
86  static constexpr bool IS_NODING_VALIDATED = true;
87 
88  // Members
89  const PrecisionModel* pm;
90  std::unique_ptr<std::vector<SegmentString*>> inputEdges;
91  Noder* customNoder;
92  std::array<bool, 2> hasEdges;
93  const Envelope* clipEnv;
94  std::unique_ptr<RingClipper> clipper;
95  std::unique_ptr<LineLimiter> limiter;
96 
97  // For use in createFloatingPrecisionNoder()
98  LineIntersector lineInt;
99  IntersectionAdder intAdder;
100  std::unique_ptr<Noder> internalNoder;
101  std::unique_ptr<Noder> spareInternalNoder;
102  // EdgeSourceInfo*, Edge* owned by EdgeNodingBuilder, stored in deque
103  std::deque<EdgeSourceInfo> edgeSourceInfoQue;
104  std::deque<Edge> edgeQue;
105  bool inputHasZ;
106  bool inputHasM;
107 
116  Noder* getNoder();
117  static std::unique_ptr<Noder> createFixedPrecisionNoder(const PrecisionModel* pm);
118  std::unique_ptr<Noder> createFloatingPrecisionNoder(bool doValidation);
119 
120 
121  void addCollection(const GeometryCollection* gc, uint8_t geomIndex);
122  void addGeometryCollection(const GeometryCollection* gc, uint8_t geomIndex, int expectedDim);
123  void addPolygon(const Polygon* poly, uint8_t geomIndex);
124  void addPolygonRing(const LinearRing* ring, bool isHole, uint8_t geomIndex);
125  void addLine(const LineString* line, uint8_t geomIndex);
126  void addLine(std::unique_ptr<CoordinateSequence>& pts, uint8_t geomIndex);
127  void addEdge(std::unique_ptr<CoordinateSequence>& cas, const EdgeSourceInfo* info);
128 
129  // Create a EdgeSourceInfo* owned by EdgeNodingBuilder
130  const EdgeSourceInfo* createEdgeSourceInfo(uint8_t index, int depthDelta, bool isHole);
131  const EdgeSourceInfo* createEdgeSourceInfo(uint8_t index);
132 
137  bool isClippedCompletely(const Envelope* env) const;
138 
144  bool isToBeLimited(const LineString* line) const;
145 
151  std::vector<std::unique_ptr<CoordinateSequence>>& limit(const LineString* line);
152 
167  std::unique_ptr<CoordinateSequence> clip(const LinearRing* line);
168 
176  static std::unique_ptr<CoordinateSequence> removeRepeatedPoints(const LineString* line);
177 
178  static int computeDepthDelta(const LinearRing* ring, bool isHole);
179 
180  void add(const Geometry* g, uint8_t geomIndex);
181 
188  std::vector<Edge*> node(std::vector<SegmentString*>* segStrings);
189  std::vector<Edge*> createEdges(std::vector<SegmentString*>* segStrings);
190 
191 
192 public:
193 
199  EdgeNodingBuilder(const PrecisionModel* p_pm, Noder* p_customNoder)
200  : pm(p_pm)
201  , inputEdges(new std::vector<SegmentString*>)
202  , customNoder(p_customNoder)
203  , hasEdges{{false,false}}
204  , clipEnv(nullptr)
205  , intAdder(lineInt)
206  , inputHasZ(false)
207  , inputHasM(false)
208  {};
209 
210  ~EdgeNodingBuilder()
211  {
212  for (SegmentString* ss: *inputEdges) {
213  delete ss;
214  }
215  }
216 
217  void setClipEnvelope(const Envelope* clipEnv);
218 
219  // returns newly allocated vector and segmentstrings
220  // std::vector<SegmentString*>* node();
221 
232  bool hasEdgesFor(uint8_t geomIndex) const;
233 
245  std::vector<Edge*> build(const Geometry* geom0, const Geometry* geom1);
246 
247 
248 
249 };
250 
251 
252 } // namespace geos.operation.overlayng
253 } // namespace geos.operation
254 } // namespace geos
255 
A LineIntersector is an algorithm that can both test whether two line segments intersect and compute ...
Definition: LineIntersector.h:53
An Envelope defines a rectangulare region of the 2D coordinate plane.
Definition: Envelope.h:58
Represents a collection of heterogeneous Geometry objects.
Definition: GeometryCollection.h:51
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition: Geometry.h:186
Definition: LineString.h:65
Models an OGC SFS LinearRing. A LinearRing is a LineString which is both closed and simple.
Definition: LinearRing.h:54
Represents a linear polygon, which may include holes.
Definition: Polygon.h:60
Specifies the precision model of the Coordinate in a Geometry.
Definition: PrecisionModel.h:88
Computes the intersections between two line segments in SegmentString and adds them to each string.
Definition: IntersectionAdder.h:54
Computes all intersections between segments in a set of SegmentString.
Definition: Noder.h:46
An interface for classes which represent a sequence of contiguous line segments.
Definition: SegmentString.h:47
Definition: SnapRoundingNoder.h:71
Definition: EdgeNodingBuilder.h:80
bool hasEdgesFor(uint8_t geomIndex) const
std::vector< Edge * > build(const Geometry *geom0, const Geometry *geom1)
EdgeNodingBuilder(const PrecisionModel *p_pm, Noder *p_customNoder)
Definition: EdgeNodingBuilder.h:199
Definition: EdgeSourceInfo.h:38
Definition: Angle.h:26
Classes to compute nodings for arrangements of line segments and line segment sequences.
Definition: InvalidSegmentDetector.h:25
Basic namespace for all GEOS functionalities.
Definition: Angle.h:25