GEOS  3.10.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
27 namespace geos {
28 namespace geom {
29 class Geometry;
30 class Coordinate;
31 }
32 }
33 
34 namespace geos { // geos.
35 namespace operation { // geos.operation
36 namespace valid { // geos.operation.valid
37 
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::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 
73  static std::size_t intersectingSegIndex(const CoordinateSequence* ringPts, const Coordinate* pt);
74 
75  static std::size_t ringIndexPrev(const CoordinateSequence* ringPts, std::size_t index);
76 
77  std::vector<SegmentString*> createSegmentStrings(const Geometry* geom, bool isInvertedRingValid);
78 
79  std::vector<PolygonRing*> getPolygonRings(const std::vector<SegmentString*>& segStrings);
80 
81  SegmentString* createSegString(const LinearRing* ring, const PolygonRing* polyRing);
82 
83  // Declare type as noncopyable
84  PolygonTopologyAnalyzer(const PolygonTopologyAnalyzer& other) = delete;
85  PolygonTopologyAnalyzer& operator=(const PolygonTopologyAnalyzer& rhs) = delete;
86 
87 public:
88 
89  /* public */
90  PolygonTopologyAnalyzer(const Geometry* geom, bool p_isInvertedRingValid);
91 
98  static Coordinate findSelfIntersection(const LinearRing* ring);
99 
114  static bool
115  isSegmentInRing(const Coordinate* p0, const Coordinate* p1,
116  const LinearRing* ring);
117 
135  static bool isIncidentSegmentInRing(const Coordinate* p0, const Coordinate* p1,
136  const CoordinateSequence* ringPts);
137 
138 
139  bool hasInvalidIntersection() {
140  return segInt.isInvalid();
141  }
142 
143  int getInvalidCode() {
144  return segInt.getInvalidCode();
145  }
146 
147  const Coordinate& getInvalidLocation() {
148  return segInt.getInvalidLocation();
149  }
150 
159  bool isInteriorDisconnected();
160 
161  const Coordinate& getDisconnectionLocation() const
162  {
163  return disconnectionPt;
164  };
165 
166 
179  void checkInteriorDisconnectedByHoleCycle();
180 
190  void checkInteriorDisconnectedBySelfTouch();
191 
192 };
193 
194 
195 } // namespace geos.operation.valid
196 } // namespace geos.operation
197 } // namespace geos
198 
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:60
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition: Geometry.h:188
Basic namespace for all GEOS functionalities.
Definition: Angle.h:26
Models an OGC SFS LinearRing. A LinearRing is a LineString which is both closed and simple...
Definition: LinearRing.h:57
The internal representation of a list of coordinates inside a Geometry.
Definition: CoordinateSequence.h:58