GEOS  3.13.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
28 namespace geos {
29 namespace geom {
30 class Geometry;
31 }
32 }
33 
34 namespace geos { // geos.
35 namespace operation { // geos.operation
36 namespace valid { // geos.operation.valid
37 
38 using geos::geom::CoordinateXY;
42 
43 class GEOS_DLL PolygonTopologyAnalyzer {
44 
45 private:
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  // 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 CoordinateXY&
68  findNonEqualVertex(const LinearRing* ring, const CoordinateXY& p);
69 
87  static bool isIncidentSegmentInRing(const CoordinateXY* p0, const CoordinateXY* p1,
88  const CoordinateSequence* ringPts);
89 
90  static const CoordinateXY& findRingVertexPrev(const CoordinateSequence* ringPts,
91  std::size_t index, const CoordinateXY& node);
92 
93  static const CoordinateXY& findRingVertexNext(const CoordinateSequence* ringPts,
94  std::size_t index, const CoordinateXY& 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 CoordinateXY* 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 
118 public:
119 
120  /* public */
121  PolygonTopologyAnalyzer(const Geometry* geom, bool p_isInvertedRingValid);
122 
129  static CoordinateXY 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 CoordinateXY& getInvalidLocation() {
162  return segInt.getInvalidLocation();
163  }
164 
173  bool isInteriorDisconnected();
174 
175  const CoordinateXY& 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:56
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:54
Basic namespace for all GEOS functionalities.
Definition: Angle.h:25