GEOS 3.11.1
PolygonTopologyAnalyzer.h
1/**********************************************************************
2 *
3 * GEOS - Geometry Engine Open Source
4 * http://geos.osgeo.org
5 *
6 * Copyright (C) 2021 Paul Ramsey <pramsey@cleverelephant.ca>
7 * Copyright (C) 2021 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/export.h>
19
20#include <geos/operation/valid/PolygonIntersectionAnalyzer.h>
21#include <geos/operation/valid/PolygonRing.h>
22#include <geos/noding/BasicSegmentString.h>
23
24#include <memory>
25
26// Forward declarations
27namespace geos {
28namespace geom {
29class Geometry;
30class Coordinate;
31}
32}
33
34namespace geos { // geos.
35namespace operation { // geos.operation
36namespace valid { // geos.operation.valid
37
42
43class GEOS_DLL PolygonTopologyAnalyzer {
44
45private:
46
47 // const Geometry* inputGeom;
48 bool isInvertedRingValid = false;
49 PolygonIntersectionAnalyzer segInt;
50 std::vector<PolygonRing*> polyRings;
51 geom::Coordinate disconnectionPt;
52
53
54 // holding area for PolygonRings and SegmentStrings so we
55 // can pass around pointers with abandon
56 std::deque<PolygonRing> polyRingStore;
57 std::deque<noding::BasicSegmentString> segStringStore;
58 // when building SegmentStrings we sometimes want
59 // to use deduped CoordinateSequences so we will
60 // keep the deduped ones here so they get cleaned
61 // up when processing is complete
62 std::vector<std::unique_ptr<CoordinateSequence>> coordSeqStore;
63
64 PolygonRing* createPolygonRing(const LinearRing* p_ring);
65 PolygonRing* createPolygonRing(const LinearRing* p_ring, int p_index, PolygonRing* p_shell);
66
67 static const Coordinate&
68 findNonEqualVertex(const LinearRing* ring, const Coordinate& p);
69
87 static bool isIncidentSegmentInRing(const Coordinate* p0, const Coordinate* p1,
88 const CoordinateSequence* ringPts);
89
90 static const Coordinate& findRingVertexPrev(const CoordinateSequence* ringPts,
91 std::size_t index, const Coordinate& node);
92
93 static const Coordinate& findRingVertexNext(const CoordinateSequence* ringPts,
94 std::size_t index, const Coordinate& node);
95
96 static std::size_t ringIndexPrev(const CoordinateSequence* ringPts, std::size_t index);
97
98 static std::size_t ringIndexNext(const CoordinateSequence* ringPts, std::size_t index);
99
106 static std::size_t intersectingSegIndex(const CoordinateSequence* ringPts, const Coordinate* pt);
107
108 std::vector<SegmentString*> createSegmentStrings(const Geometry* geom, bool isInvertedRingValid);
109
110 std::vector<PolygonRing*> getPolygonRings(const std::vector<SegmentString*>& segStrings);
111
112 SegmentString* createSegString(const LinearRing* ring, const PolygonRing* polyRing);
113
114 // Declare type as noncopyable
115 PolygonTopologyAnalyzer(const PolygonTopologyAnalyzer& other) = delete;
116 PolygonTopologyAnalyzer& operator=(const PolygonTopologyAnalyzer& rhs) = delete;
117
118public:
119
120 /* public */
121 PolygonTopologyAnalyzer(const Geometry* geom, bool p_isInvertedRingValid);
122
129 static Coordinate findSelfIntersection(const LinearRing* ring);
130
149 static bool
150 isRingNested(const LinearRing* test,
151 const LinearRing* target);
152
153 bool hasInvalidIntersection() {
154 return segInt.isInvalid();
155 }
156
157 int getInvalidCode() {
158 return segInt.getInvalidCode();
159 }
160
161 const Coordinate& getInvalidLocation() {
162 return segInt.getInvalidLocation();
163 }
164
173 bool isInteriorDisconnected();
174
175 const Coordinate& getDisconnectionLocation() const
176 {
177 return disconnectionPt;
178 };
179
180
193 void checkInteriorDisconnectedByHoleCycle();
194
204 void checkInteriorDisconnectedBySelfTouch();
205
206};
207
208
209} // namespace geos.operation.valid
210} // namespace geos.operation
211} // namespace geos
The internal representation of a list of coordinates inside a Geometry.
Definition: CoordinateSequence.h:44
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:58
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition: Geometry.h:186
Models an OGC SFS LinearRing. A LinearRing is a LineString which is both closed and simple.
Definition: LinearRing.h:55
Basic namespace for all GEOS functionalities.
Definition: geos.h:39