GEOS 3.11.1
IsValidOp.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/PolygonTopologyAnalyzer.h>
21#include <geos/operation/valid/TopologyValidationError.h>
22
23
24// Forward declarations
25namespace geos {
26namespace geom {
27class Coordinate;
28class Geometry;
29class Point;
30class MultiPoint;
31class LineString;
32class LinearRing;
33class Polygon;
34class MultiPolygon;
35class GeometryCollection;
36}
37namespace algorithm {
38namespace locate {
39class IndexedPointInAreaLocator;
40}
41}
42}
43
44
45namespace geos { // geos.
46namespace operation { // geos.operation
47namespace valid { // geos.operation.valid
48
56class GEOS_DLL IsValidOp {
57
58private:
59
60 static constexpr int MIN_SIZE_LINESTRING = 2;
61 static constexpr int MIN_SIZE_RING = 4;
62
66 const geom::Geometry* inputGeometry;
71 bool isInvertedRingValid = false;
72 std::unique_ptr<TopologyValidationError> validErr;
73
74 bool hasInvalidError()
75 {
76 return validErr != nullptr;
77 }
78
79
80 void logInvalid(int code, const geom::Coordinate* pt);
81
82 bool isValidGeometry(const geom::Geometry* g);
83
87 bool isValid(const geom::Point* g);
88
92 bool isValid(const geom::MultiPoint* g);
93
98 bool isValid(const geom::LineString* g);
99
103 bool isValid(const geom::LinearRing* g);
104
109 bool isValid(const geom::Polygon* g);
110
117 bool isValid(const geom::MultiPolygon* g);
118
125 bool isValid(const geom::GeometryCollection* gc);
126
127 void checkCoordinatesValid(const geom::CoordinateSequence* coords);
128 void checkCoordinatesValid(const geom::Polygon* poly);
129 void checkRingClosed(const geom::LinearRing* ring);
130 void checkRingsClosed(const geom::Polygon* poly);
131 void checkRingsPointSize(const geom::Polygon* poly);
132 void checkRingPointSize(const geom::LinearRing* ring);
133
140 void checkTooFewPoints(const geom::LineString* line, std::size_t minSize);
141
150 bool isNonRepeatedSizeAtLeast(const geom::LineString* line, std::size_t minSize);
151
152 void checkAreaIntersections(PolygonTopologyAnalyzer& areaAnalyzer);
153
159 void checkRingSimple(const geom::LinearRing* ring);
160
161
172 void checkHolesInShell(const geom::Polygon* poly);
173
185 const Coordinate * findHoleOutsideShellPoint(
186 const geom::LinearRing* hole,
187 const geom::LinearRing* shell);
188
196 void checkHolesNotNested(const geom::Polygon* poly);
197
209 void checkShellsNotNested(const geom::MultiPolygon* mp);
210
211 void checkInteriorConnected(PolygonTopologyAnalyzer& areaAnalyzer);
212
213
214public:
215
221 IsValidOp(const geom::Geometry* p_inputGeometry)
222 : inputGeometry(p_inputGeometry)
223 , validErr(nullptr)
224 {};
225
254 {
255 isInvertedRingValid = p_isValid;
256 };
257
263 static bool isValid(const geom::Geometry* geom)
264 {
265 IsValidOp ivo(geom);
266 return ivo.isValid();
267 };
268
269 static bool isValid(const geom::Coordinate& coord)
270 {
271 return isValid(&coord);
272 }
273
279 bool isValid();
280
289 static bool isValid(const geom::Coordinate* coord);
290
300
301
302};
303
304
305} // namespace geos.operation.valid
306} // namespace geos.operation
307} // namespace geos
The internal representation of a list of coordinates inside a Geometry.
Definition: CoordinateSequence.h:44
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:58
Represents a collection of heterogeneous Geometry objects.
Definition: GeometryCollection.h:52
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition: Geometry.h:186
Definition: LineString.h:66
Models an OGC SFS LinearRing. A LinearRing is a LineString which is both closed and simple.
Definition: LinearRing.h:55
Definition: MultiPoint.h:51
Definition: MultiPolygon.h:59
Definition: Point.h:63
Represents a linear polygon, which may include holes.
Definition: Polygon.h:61
Definition: IsValidOp.h:56
IsValidOp(const geom::Geometry *p_inputGeometry)
Definition: IsValidOp.h:221
const TopologyValidationError * getValidationError()
static bool isValid(const geom::Coordinate *coord)
void setSelfTouchingRingFormingHoleValid(bool p_isValid)
Definition: IsValidOp.h:253
static bool isValid(const geom::Geometry *geom)
Definition: IsValidOp.h:263
Contains information about the nature and location of a geom::Geometry validation error.
Definition: TopologyValidationError.h:39
Basic namespace for all GEOS functionalities.
Definition: geos.h:39