GEOS 3.16.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// Forward declarations
26namespace geos {
27namespace geom {
28class Geometry;
29}
30}
31
32namespace geos { // geos.
33namespace operation { // geos.operation
34namespace valid { // geos.operation.valid
35
36class GEOS_DLL PolygonTopologyAnalyzer {
37 using CoordinateXY = geos::geom::CoordinateXY;
38 using CoordinateSequence = geos::geom::CoordinateSequence;
39 using Geometry = geos::geom::Geometry;
40 using LinearRing = geos::geom::LinearRing;
41 using SegmentString = geos::noding::SegmentString;
42
43private:
44
45 // const Geometry* inputGeom;
46 bool isInvertedRingValid = false;
47 PolygonIntersectionAnalyzer segInt;
48 std::vector<PolygonRing*> polyRings;
49 geom::CoordinateXY disconnectionPt;
50
51
52 // holding area for PolygonRings and SegmentStrings so we
53 // can pass around pointers with abandon
54 std::deque<PolygonRing> polyRingStore;
55 std::deque<noding::BasicSegmentString> segStringStore;
56
57 PolygonRing* createPolygonRing(const LinearRing* p_ring);
58 PolygonRing* createPolygonRing(const LinearRing* p_ring, int p_index, PolygonRing* p_shell);
59
60 static const CoordinateXY&
61 findNonEqualVertex(const LinearRing* ring, const CoordinateXY& p);
62
80 static bool isIncidentSegmentInRing(const CoordinateXY* p0, const CoordinateXY* p1,
81 const CoordinateSequence* ringPts);
82
83 static const CoordinateXY& findRingVertexPrev(const CoordinateSequence* ringPts,
84 std::size_t index, const CoordinateXY& node);
85
86 static const CoordinateXY& findRingVertexNext(const CoordinateSequence* ringPts,
87 std::size_t index, const CoordinateXY& node);
88
89 static std::size_t ringIndexPrev(const CoordinateSequence* ringPts, std::size_t index);
90
91 static std::size_t ringIndexNext(const CoordinateSequence* ringPts, std::size_t index);
92
99 static std::size_t intersectingSegIndex(const CoordinateSequence* ringPts, const CoordinateXY* pt);
100
101 std::vector<SegmentString*> createSegmentStrings(const Geometry* geom, bool isInvertedRingValid);
102
103 static std::vector<PolygonRing*> getPolygonRings(const std::vector<SegmentString*>& segStrings);
104
105 SegmentString* createSegString(const LinearRing* ring, const PolygonRing* polyRing);
106
107 // Declare type as noncopyable
108 PolygonTopologyAnalyzer(const PolygonTopologyAnalyzer& other) = delete;
109 PolygonTopologyAnalyzer& operator=(const PolygonTopologyAnalyzer& rhs) = delete;
110
111public:
112
113 /* public */
114 PolygonTopologyAnalyzer(const Geometry* geom, bool p_isInvertedRingValid);
115
122 static CoordinateXY findSelfIntersection(const LinearRing* ring);
123
142 static bool
143 isRingNested(const LinearRing* test,
144 const LinearRing* target);
145
146 bool hasInvalidIntersection() const {
147 return segInt.isInvalid();
148 }
149
150 int getInvalidCode() const {
151 return segInt.getInvalidCode();
152 }
153
154 const CoordinateXY& getInvalidLocation() const {
155 return segInt.getInvalidLocation();
156 }
157
166 bool isInteriorDisconnected();
167
168 const CoordinateXY& getDisconnectionLocation() const
169 {
170 return disconnectionPt;
171 };
172
173
186 void checkInteriorDisconnectedByHoleCycle();
187
197 void checkInteriorDisconnectedBySelfTouch();
198
199};
200
201
202} // namespace geos.operation.valid
203} // namespace geos.operation
204} // 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:201
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:49
Basic namespace for all GEOS functionalities.
Definition geos.h:38