GEOS  3.10.3
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/geom/CoordinateArraySequence.h>
25 #include <geos/noding/SegmentIntersector.h>
26 
27 
28 // Forward declarations
29 namespace geos {
30 namespace noding {
31 class SegmentString;
32 class BasicSegmentString;
33 }
34 namespace algorithm {
35 class BoundaryNodeRule;
36 }
37 namespace geom {
38 class LineString;
39 class LinearRing;
40 class MultiLineString;
41 class MultiPoint;
42 class Geometry;
43 class Polygon;
44 class GeometryCollection;
45 }
46 }
47 
48 
49 namespace geos { // geos
50 namespace operation { // geos.operation
51 namespace valid { // geos.operation.valid
52 
96 class GEOS_DLL IsSimpleOp {
97 
98 private:
99 
100  const geom::Geometry& inputGeom;
101  bool isClosedEndpointsInInterior = true;
102  bool isFindAllLocations = false;
103  bool isSimpleResult = false;
104  std::vector<geom::Coordinate> nonSimplePts;
105  bool computed = false;
106 
107  void compute();
108 
109  bool computeSimple(const geom::Geometry& geom);
110 
111  bool isSimpleMultiPoint(const geom::MultiPoint& mp);
112 
121  bool isSimplePolygonal(const geom::Geometry& geom);
122 
130  bool isSimpleGeometryCollection(const geom::Geometry& geom);
131 
132  bool isSimpleLinearGeometry(const geom::Geometry& geom);
133 
134  static std::vector<std::unique_ptr<geos::geom::CoordinateArraySequence>>
135  removeRepeatedPts(const geom::Geometry& geom);
136 
137  static std::vector<std::unique_ptr<noding::SegmentString>>
138  createSegmentStrings(std::vector<std::unique_ptr<geos::geom::CoordinateArraySequence>>& seqs);
139 
140  class NonSimpleIntersectionFinder : public noding::SegmentIntersector
141  {
142 
143  private:
144 
145  bool isClosedEndpointsInInterior;
146  bool isFindAll = false;
147 
148  std::vector<geom::Coordinate>& intersectionPts;
150 
151  // bool hasInteriorInt;
152  // bool hasInteriorVertexInt;
153  // bool hasEqualSegments;
154  // bool hasInteriorEndpointInt;
155 
156  bool findIntersection(
157  noding::SegmentString* ss0, std::size_t segIndex0,
158  noding::SegmentString* ss1, std::size_t segIndex1,
159  const geom::Coordinate& p00, const geom::Coordinate& p01,
160  const geom::Coordinate& p10, const geom::Coordinate& p11);
161 
171  bool isIntersectionEndpoint(
172  const noding::SegmentString* ss, std::size_t ssIndex,
173  const algorithm::LineIntersector& li, std::size_t liSegmentIndex) const;
174 
183  std::size_t intersectionVertexIndex(
184  const algorithm::LineIntersector& li, std::size_t segmentIndex) const;
185 
186  public:
187 
188  NonSimpleIntersectionFinder(
189  bool p_isClosedEndpointsInInterior,
190  bool p_isFindAll,
191  std::vector<geom::Coordinate>& p_intersectionPts)
192  : isClosedEndpointsInInterior(p_isClosedEndpointsInInterior)
193  , isFindAll(p_isFindAll)
194  , intersectionPts(p_intersectionPts)
195  {};
196 
202  bool hasIntersection() const;
203 
204  void processIntersections(
205  noding::SegmentString* ss0, std::size_t segIndex0,
206  noding::SegmentString* ss1, std::size_t segIndex1) override;
207 
208  bool isDone() const override;
209 
210  }; // NonSimpleIntersectionFinder
211 
212 
213 public:
214 
215  IsSimpleOp(const geom::Geometry* geom)
216  : IsSimpleOp(*geom)
217  {};
218 
225  : IsSimpleOp(geom, algorithm::BoundaryNodeRule::getBoundaryRuleMod2())
226  {};
227 
234  IsSimpleOp(const geom::Geometry& geom, const algorithm::BoundaryNodeRule& p_boundaryNodeRule)
235  : inputGeom(geom)
236  , isClosedEndpointsInInterior(! p_boundaryNodeRule.isInBoundary(2))
237  , isFindAllLocations(false)
238  , computed(false)
239  {};
240 
247  static bool isSimple(const geom::Geometry& geom);
248 
249  static bool isSimple(const geom::Geometry* geom) {
250  if (!geom) return false;
251  return isSimple(*geom);
252  }
253 
261 
268  void setFindAllLocations(bool isFindAll);
269 
275  bool isSimple();
276 
286 
292  const std::vector<geom::Coordinate>& getNonSimpleLocations();
293 
294 
295 
296 }; // IsSimpleOp
297 
298 
299 } // namespace geos.operation.valid
300 } // namespace geos.operation
301 } // namespace geos
An interface for rules which determine whether node points which are in boundaries of lineal geometry...
Definition: BoundaryNodeRule.h:51
A LineIntersector is an algorithm that can both test whether two line segments intersect and compute ...
Definition: LineIntersector.h:50
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
Definition: MultiPoint.h:54
Processes possible intersections detected by a Noder.
Definition: noding/SegmentIntersector.h:48
An interface for classes which represent a sequence of contiguous line segments.
Definition: SegmentString.h:46
Definition: IsSimpleOp.h:96
geom::Coordinate getNonSimpleLocation()
void setFindAllLocations(bool isFindAll)
IsSimpleOp(const geom::Geometry &geom)
Definition: IsSimpleOp.h:224
static bool isSimple(const geom::Geometry &geom)
geom::Coordinate getNonSimpleLocation(const geom::Geometry &geom)
const std::vector< geom::Coordinate > & getNonSimpleLocations()
IsSimpleOp(const geom::Geometry &geom, const algorithm::BoundaryNodeRule &p_boundaryNodeRule)
Definition: IsSimpleOp.h:234
Basic namespace for all GEOS functionalities.
Definition: Angle.h:26