GEOS 3.15.0dev
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/geom/Coordinate.h>
21#include <geos/operation/valid/PolygonIntersectionAnalyzer.h>
22#include <geos/operation/valid/PolygonRing.h>
23#include <geos/noding/BasicSegmentString.h>
24
25#include <memory>
26
27// Forward declarations
28namespace geos {
29namespace geom {
30class Geometry;
31}
32}
33
34namespace geos { // geos.
35namespace operation { // geos.operation
36namespace valid { // geos.operation.valid
37
38class GEOS_DLL PolygonTopologyAnalyzer {
39 using CoordinateXY = geos::geom::CoordinateXY;
40 using CoordinateSequence = geos::geom::CoordinateSequence;
41 using Geometry = geos::geom::Geometry;
42 using LinearRing = geos::geom::LinearRing;
43 using SegmentString = geos::noding::SegmentString;
44
45private:
46
47 // const Geometry* inputGeom;
48 bool isInvertedRingValid = false;
49 PolygonIntersectionAnalyzer segInt;
50 std::vector<PolygonRing*> polyRings;
51 geom::CoordinateXY 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
59 PolygonRing* createPolygonRing(const LinearRing* p_ring);
60 PolygonRing* createPolygonRing(const LinearRing* p_ring, int p_index, PolygonRing* p_shell);
61
62 static const CoordinateXY&
63 findNonEqualVertex(const LinearRing* ring, const CoordinateXY& p);
64
82 static bool isIncidentSegmentInRing(const CoordinateXY* p0, const CoordinateXY* p1,
83 const CoordinateSequence* ringPts);
84
85 static const CoordinateXY& findRingVertexPrev(const CoordinateSequence* ringPts,
86 std::size_t index, const CoordinateXY& node);
87
88 static const CoordinateXY& findRingVertexNext(const CoordinateSequence* ringPts,
89 std::size_t index, const CoordinateXY& node);
90
91 static std::size_t ringIndexPrev(const CoordinateSequence* ringPts, std::size_t index);
92
93 static std::size_t ringIndexNext(const CoordinateSequence* ringPts, std::size_t index);
94
101 static std::size_t intersectingSegIndex(const CoordinateSequence* ringPts, const CoordinateXY* pt);
102
103 std::vector<SegmentString*> createSegmentStrings(const Geometry* geom, bool isInvertedRingValid);
104
105 std::vector<PolygonRing*> getPolygonRings(const std::vector<SegmentString*>& segStrings);
106
107 SegmentString* createSegString(const LinearRing* ring, const PolygonRing* polyRing);
108
109 // Declare type as noncopyable
110 PolygonTopologyAnalyzer(const PolygonTopologyAnalyzer& other) = delete;
111 PolygonTopologyAnalyzer& operator=(const PolygonTopologyAnalyzer& rhs) = delete;
112
113public:
114
115 /* public */
116 PolygonTopologyAnalyzer(const Geometry* geom, bool p_isInvertedRingValid);
117
124 static CoordinateXY findSelfIntersection(const LinearRing* ring);
125
144 static bool
145 isRingNested(const LinearRing* test,
146 const LinearRing* target);
147
148 bool hasInvalidIntersection() {
149 return segInt.isInvalid();
150 }
151
152 int getInvalidCode() {
153 return segInt.getInvalidCode();
154 }
155
156 const CoordinateXY& getInvalidLocation() {
157 return segInt.getInvalidLocation();
158 }
159
168 bool isInteriorDisconnected();
169
170 const CoordinateXY& getDisconnectionLocation() const
171 {
172 return disconnectionPt;
173 };
174
175
188 void checkInteriorDisconnectedByHoleCycle();
189
199 void checkInteriorDisconnectedBySelfTouch();
200
201};
202
203
204} // namespace geos.operation.valid
205} // namespace geos.operation
206} // namespace geos
The internal representation of a list of coordinates inside a Geometry.
Definition CoordinateSequence.h:56
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition Geometry.h:196
Models an OGC SFS LinearRing. A LinearRing is a LineString which is both closed and simple.
Definition LinearRing.h:54
An interface for classes which represent a sequence of contiguous line segments.
Definition SegmentString.h:47
Basic namespace for all GEOS functionalities.
Definition geos.h:38