GEOS  3.13.0dev
IsSimpleOp.h
1 /**********************************************************************
2  *
3  * GEOS - Geometry Engine Open Source
4  * http://geos.osgeo.org
5  *
6  * Copyright (C) 2001-2002 Vivid Solutions Inc.
7  * Copyright (C) 2009 Sandro Santilli <strk@kbt.io>
8  * Copyright (C) 2005-2006 Refractions Research Inc.
9  * Copyright (C) 2021 Paul Ramsey <pramsey@cleverelephant.ca>
10  *
11  * This is free software; you can redistribute and/or modify it under
12  * the terms of the GNU Lesser General Public Licence as published
13  * by the Free Software Foundation.
14  * See the COPYING file for more information.
15  *
16  **********************************************************************/
17 
18 #pragma once
19 
20 #include <memory>
21 
22 #include <geos/algorithm/LineIntersector.h>
23 #include <geos/algorithm/BoundaryNodeRule.h>
24 #include <geos/noding/SegmentIntersector.h>
25 
26 // Forward declarations
27 namespace geos {
28 namespace noding {
29 class SegmentString;
30 class BasicSegmentString;
31 }
32 namespace algorithm {
33 class BoundaryNodeRule;
34 }
35 namespace geom {
36 class LineString;
37 class LinearRing;
38 class MultiLineString;
39 class MultiPoint;
40 class Geometry;
41 class Polygon;
42 class GeometryCollection;
43 }
44 }
45 
46 
47 namespace geos { // geos
48 namespace operation { // geos.operation
49 namespace valid { // geos.operation.valid
50 
94 class GEOS_DLL IsSimpleOp {
95 
96 private:
97 
98  const geom::Geometry& inputGeom;
99  bool isClosedEndpointsInInterior = true;
100  bool isFindAllLocations = false;
101  bool isSimpleResult = false;
102  std::vector<geom::CoordinateXY> nonSimplePts;
103  bool computed = false;
104 
105  void compute();
106 
107  bool computeSimple(const geom::Geometry& geom);
108 
109  bool isSimpleMultiPoint(const geom::MultiPoint& mp);
110 
119  bool isSimplePolygonal(const geom::Geometry& geom);
120 
128  bool isSimpleGeometryCollection(const geom::Geometry& geom);
129 
130  bool isSimpleLinearGeometry(const geom::Geometry& geom);
131 
132  static std::vector<std::unique_ptr<geos::geom::CoordinateSequence>>
133  removeRepeatedPts(const geom::Geometry& geom);
134 
135  static std::vector<std::unique_ptr<noding::SegmentString>>
136  createSegmentStrings(std::vector<std::unique_ptr<geos::geom::CoordinateSequence>>& seqs);
137 
138  class NonSimpleIntersectionFinder : public noding::SegmentIntersector
139  {
140 
141  private:
142 
143  bool isClosedEndpointsInInterior;
144  bool isFindAll = false;
145 
146  std::vector<geom::CoordinateXY>& intersectionPts;
148 
149  // bool hasInteriorInt;
150  // bool hasInteriorVertexInt;
151  // bool hasEqualSegments;
152  // bool hasInteriorEndpointInt;
153 
154  bool findIntersection(
155  noding::SegmentString* ss0, std::size_t segIndex0,
156  noding::SegmentString* ss1, std::size_t segIndex1,
157  const geom::CoordinateXY& p00, const geom::CoordinateXY& p01,
158  const geom::CoordinateXY& p10, const geom::CoordinateXY& p11);
159 
169  bool isIntersectionEndpoint(
170  const noding::SegmentString* ss, std::size_t ssIndex,
171  const algorithm::LineIntersector& li, std::size_t liSegmentIndex) const;
172 
181  std::size_t intersectionVertexIndex(
182  const algorithm::LineIntersector& li, std::size_t segmentIndex) const;
183 
184  public:
185 
186  NonSimpleIntersectionFinder(
187  bool p_isClosedEndpointsInInterior,
188  bool p_isFindAll,
189  std::vector<geom::CoordinateXY>& p_intersectionPts)
190  : isClosedEndpointsInInterior(p_isClosedEndpointsInInterior)
191  , isFindAll(p_isFindAll)
192  , intersectionPts(p_intersectionPts)
193  {};
194 
200  bool hasIntersection() const;
201 
202  void processIntersections(
203  noding::SegmentString* ss0, std::size_t segIndex0,
204  noding::SegmentString* ss1, std::size_t segIndex1) override;
205 
206  bool isDone() const override;
207 
208  }; // NonSimpleIntersectionFinder
209 
210 
211 public:
212 
213  IsSimpleOp(const geom::Geometry* geom)
214  : IsSimpleOp(*geom)
215  {};
216 
223  : IsSimpleOp(geom, algorithm::BoundaryNodeRule::getBoundaryRuleMod2())
224  {};
225 
232  IsSimpleOp(const geom::Geometry& geom, const algorithm::BoundaryNodeRule& p_boundaryNodeRule)
233  : inputGeom(geom)
234  , isClosedEndpointsInInterior(! p_boundaryNodeRule.isInBoundary(2))
235  , isFindAllLocations(false)
236  , computed(false)
237  {};
238 
245  static bool isSimple(const geom::Geometry& geom);
246 
247  static bool isSimple(const geom::Geometry* geom) {
248  if (!geom) return false;
249  return isSimple(*geom);
250  }
251 
258  geom::CoordinateXY getNonSimpleLocation(const geom::Geometry& geom);
259 
266  void setFindAllLocations(bool isFindAll);
267 
273  bool isSimple();
274 
283  geom::CoordinateXY getNonSimpleLocation();
284 
290  const std::vector<geom::CoordinateXY>& getNonSimpleLocations();
291 
292 
293 
294 }; // IsSimpleOp
295 
296 
297 } // namespace geos.operation.valid
298 } // namespace geos.operation
299 } // namespace geos
An interface for rules which determine whether node points which are in boundaries of lineal geometry...
Definition: BoundaryNodeRule.h:50
A LineIntersector is an algorithm that can both test whether two line segments intersect and compute ...
Definition: LineIntersector.h:53
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition: Geometry.h:186
Definition: MultiPoint.h:50
Processes possible intersections detected by a Noder.
Definition: noding/SegmentIntersector.h:45
An interface for classes which represent a sequence of contiguous line segments.
Definition: SegmentString.h:47
Definition: IsSimpleOp.h:94
void setFindAllLocations(bool isFindAll)
const std::vector< geom::CoordinateXY > & getNonSimpleLocations()
IsSimpleOp(const geom::Geometry &geom)
Definition: IsSimpleOp.h:222
geom::CoordinateXY getNonSimpleLocation()
static bool isSimple(const geom::Geometry &geom)
geom::CoordinateXY getNonSimpleLocation(const geom::Geometry &geom)
IsSimpleOp(const geom::Geometry &geom, const algorithm::BoundaryNodeRule &p_boundaryNodeRule)
Definition: IsSimpleOp.h:232
Basic namespace for all GEOS functionalities.
Definition: Angle.h:25