GEOS 3.14.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/geom/CoordinateSequence.h>
23#include <geos/geom/Envelope.h>
24#include <geos/geom/Geometry.h>
25#include <geos/geom/GeometryCollection.h>
26#include <geos/geom/LinearRing.h>
27#include <geos/geom/LineString.h>
28#include <geos/geom/Polygon.h>
29#include <geos/noding/IntersectionAdder.h>
30#include <geos/noding/Noder.h>
31#include <geos/noding/SegmentString.h>
32#include <geos/operation/overlayng/Edge.h>
33#include <geos/operation/overlayng/EdgeSourceInfo.h>
34#include <geos/operation/overlayng/LineLimiter.h>
35#include <geos/operation/overlayng/RingClipper.h>
36
37
38#include <geos/export.h>
39#include <array>
40#include <memory>
41#include <deque>
42
43
44
45namespace geos { // geos.
46namespace operation { // geos.operation
47namespace overlayng { // geos.operation.overlayng
48
64class GEOS_DLL EdgeNodingBuilder {
73
74private:
75
76 // Constants
77 static constexpr int MIN_LIMIT_PTS = 20;
78 static constexpr bool IS_NODING_VALIDATED = true;
79
80 // Members
81 const PrecisionModel* pm;
82 std::unique_ptr<std::vector<noding::SegmentString*>> inputEdges;
83 noding::Noder* customNoder;
84 std::array<bool, 2> hasEdges;
85 const Envelope* clipEnv;
86 std::unique_ptr<RingClipper> clipper;
87 std::unique_ptr<LineLimiter> limiter;
88
89 // For use in createFloatingPrecisionNoder()
92 std::unique_ptr<noding::Noder> internalNoder;
93 std::unique_ptr<noding::Noder> spareInternalNoder;
94 // EdgeSourceInfo*, Edge* owned by EdgeNodingBuilder, stored in deque
95 std::deque<EdgeSourceInfo> edgeSourceInfoQue;
96 std::deque<Edge> edgeQue;
97 bool inputHasZ;
98 bool inputHasM;
99
108 noding::Noder* getNoder();
109 static std::unique_ptr<noding::Noder> createFixedPrecisionNoder(const PrecisionModel* pm);
110 std::unique_ptr<noding::Noder> createFloatingPrecisionNoder(bool doValidation);
111
112
113 void addCollection(const GeometryCollection* gc, uint8_t geomIndex);
114 void addGeometryCollection(const GeometryCollection* gc, uint8_t geomIndex, int expectedDim);
115 void addPolygon(const Polygon* poly, uint8_t geomIndex);
116 void addPolygonRing(const LinearRing* ring, bool isHole, uint8_t geomIndex);
117 void addLine(const LineString* line, uint8_t geomIndex);
118 void addLine(std::unique_ptr<CoordinateSequence>& pts, uint8_t geomIndex);
119 void addEdge(std::unique_ptr<CoordinateSequence>& cas, const EdgeSourceInfo* info);
120
121 // Create a EdgeSourceInfo* owned by EdgeNodingBuilder
122 const EdgeSourceInfo* createEdgeSourceInfo(uint8_t index, int depthDelta, bool isHole);
123 const EdgeSourceInfo* createEdgeSourceInfo(uint8_t index);
124
129 bool isClippedCompletely(const Envelope* env) const;
130
136 bool isToBeLimited(const LineString* line) const;
137
143 std::vector<std::unique_ptr<CoordinateSequence>>& limit(const LineString* line);
144
159 std::unique_ptr<CoordinateSequence> clip(const LinearRing* line);
160
168 static std::unique_ptr<CoordinateSequence> removeRepeatedPoints(const LineString* line);
169
170 static int computeDepthDelta(const LinearRing* ring, bool isHole);
171
172 void add(const Geometry* g, uint8_t geomIndex);
173
180 std::vector<Edge*> node(std::vector<noding::SegmentString*>* segStrings);
181 std::vector<Edge*> createEdges(std::vector<noding::SegmentString*>* segStrings);
182
183
184public:
185
191 EdgeNodingBuilder(const PrecisionModel* p_pm, noding::Noder* p_customNoder)
192 : pm(p_pm)
193 , inputEdges(new std::vector<noding::SegmentString*>)
194 , customNoder(p_customNoder)
195 , hasEdges{{false,false}}
196 , clipEnv(nullptr)
197 , intAdder(lineInt)
198 , inputHasZ(false)
199 , inputHasM(false)
200 {};
201
202 ~EdgeNodingBuilder()
203 {
204 for (noding::SegmentString* ss: *inputEdges) {
205 delete ss;
206 }
207 }
208
209 void setClipEnvelope(const Envelope* clipEnv);
210
211 // returns newly allocated vector and segmentstrings
212 // std::vector<noding::SegmentString*>* node();
213
224 bool hasEdgesFor(uint8_t geomIndex) const;
225
237 std::vector<Edge*> build(const Geometry* geom0, const Geometry* geom1);
238
239
240
241};
242
243
244} // namespace geos.operation.overlayng
245} // namespace geos.operation
246} // namespace geos
247
A LineIntersector is an algorithm that can both test whether two line segments intersect and compute ...
Definition LineIntersector.h:53
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
Represents a collection of heterogeneous Geometry objects.
Definition GeometryCollection.h:51
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition Geometry.h:197
Definition LineString.h:66
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:61
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 EdgeNodingBuilder.h:64
bool hasEdgesFor(uint8_t geomIndex) const
std::vector< Edge * > build(const Geometry *geom0, const Geometry *geom1)
EdgeNodingBuilder(const PrecisionModel *p_pm, noding::Noder *p_customNoder)
Definition EdgeNodingBuilder.h:191
Definition EdgeSourceInfo.h:38
Basic namespace for all GEOS functionalities.
Definition geos.h:39