GEOS 3.11.1
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// Forward declarations
28namespace geos {
29namespace noding {
30class SegmentString;
31class BasicSegmentString;
32}
33namespace algorithm {
34class BoundaryNodeRule;
35}
36namespace geom {
37class LineString;
38class LinearRing;
39class MultiLineString;
40class MultiPoint;
41class Geometry;
42class Polygon;
43class GeometryCollection;
44}
45}
46
47
48namespace geos { // geos
49namespace operation { // geos.operation
50namespace valid { // geos.operation.valid
51
95class GEOS_DLL IsSimpleOp {
96
97private:
98
99 const geom::Geometry& inputGeom;
100 bool isClosedEndpointsInInterior = true;
101 bool isFindAllLocations = false;
102 bool isSimpleResult = false;
103 std::vector<geom::Coordinate> nonSimplePts;
104 bool computed = false;
105
106 void compute();
107
108 bool computeSimple(const geom::Geometry& geom);
109
110 bool isSimpleMultiPoint(const geom::MultiPoint& mp);
111
120 bool isSimplePolygonal(const geom::Geometry& geom);
121
129 bool isSimpleGeometryCollection(const geom::Geometry& geom);
130
131 bool isSimpleLinearGeometry(const geom::Geometry& geom);
132
133 static std::vector<std::unique_ptr<geos::geom::CoordinateArraySequence>>
134 removeRepeatedPts(const geom::Geometry& geom);
135
136 static std::vector<std::unique_ptr<noding::SegmentString>>
137 createSegmentStrings(std::vector<std::unique_ptr<geos::geom::CoordinateArraySequence>>& seqs);
138
139 class NonSimpleIntersectionFinder : public noding::SegmentIntersector
140 {
141
142 private:
143
144 bool isClosedEndpointsInInterior;
145 bool isFindAll = false;
146
147 std::vector<geom::Coordinate>& intersectionPts;
149
150 // bool hasInteriorInt;
151 // bool hasInteriorVertexInt;
152 // bool hasEqualSegments;
153 // bool hasInteriorEndpointInt;
154
155 bool findIntersection(
156 noding::SegmentString* ss0, std::size_t segIndex0,
157 noding::SegmentString* ss1, std::size_t segIndex1,
158 const geom::Coordinate& p00, const geom::Coordinate& p01,
159 const geom::Coordinate& p10, const geom::Coordinate& p11);
160
170 bool isIntersectionEndpoint(
171 const noding::SegmentString* ss, std::size_t ssIndex,
172 const algorithm::LineIntersector& li, std::size_t liSegmentIndex) const;
173
182 std::size_t intersectionVertexIndex(
183 const algorithm::LineIntersector& li, std::size_t segmentIndex) const;
184
185 public:
186
187 NonSimpleIntersectionFinder(
188 bool p_isClosedEndpointsInInterior,
189 bool p_isFindAll,
190 std::vector<geom::Coordinate>& p_intersectionPts)
191 : isClosedEndpointsInInterior(p_isClosedEndpointsInInterior)
192 , isFindAll(p_isFindAll)
193 , intersectionPts(p_intersectionPts)
194 {};
195
201 bool hasIntersection() const;
202
203 void processIntersections(
204 noding::SegmentString* ss0, std::size_t segIndex0,
205 noding::SegmentString* ss1, std::size_t segIndex1) override;
206
207 bool isDone() const override;
208
209 }; // NonSimpleIntersectionFinder
210
211
212public:
213
214 IsSimpleOp(const geom::Geometry* geom)
215 : IsSimpleOp(*geom)
216 {};
217
224 : IsSimpleOp(geom, algorithm::BoundaryNodeRule::getBoundaryRuleMod2())
225 {};
226
233 IsSimpleOp(const geom::Geometry& geom, const algorithm::BoundaryNodeRule& p_boundaryNodeRule)
234 : inputGeom(geom)
235 , isClosedEndpointsInInterior(! p_boundaryNodeRule.isInBoundary(2))
236 , isFindAllLocations(false)
237 , computed(false)
238 {};
239
246 static bool isSimple(const geom::Geometry& geom);
247
248 static bool isSimple(const geom::Geometry* geom) {
249 if (!geom) return false;
250 return isSimple(*geom);
251 }
252
260
267 void setFindAllLocations(bool isFindAll);
268
274 bool isSimple();
275
285
291 const std::vector<geom::Coordinate>& getNonSimpleLocations();
292
293
294
295}; // IsSimpleOp
296
297
298} // namespace geos.operation.valid
299} // namespace geos.operation
300} // 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:50
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:58
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition: Geometry.h:186
Definition: MultiPoint.h:51
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:45
Definition: IsSimpleOp.h:95
geom::Coordinate getNonSimpleLocation()
void setFindAllLocations(bool isFindAll)
IsSimpleOp(const geom::Geometry &geom)
Definition: IsSimpleOp.h:223
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:233
Basic namespace for all GEOS functionalities.
Definition: geos.h:39