GEOS 3.13.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#include <geos/util.h>
23
24
25// Forward declarations
26namespace geos {
27namespace geom {
28class CoordinateXY;
29class Geometry;
30class Point;
31class MultiPoint;
32class LineString;
33class LinearRing;
34class Polygon;
35class MultiPolygon;
36class GeometryCollection;
37}
38namespace algorithm {
39namespace locate {
40class IndexedPointInAreaLocator;
41}
42}
43}
44
45
46namespace geos { // geos.
47namespace operation { // geos.operation
48namespace valid { // geos.operation.valid
49
57class GEOS_DLL IsValidOp {
58
59private:
60
61 static constexpr int MIN_SIZE_LINESTRING = 2;
62 static constexpr int MIN_SIZE_RING = 4;
63
67 const geom::Geometry* inputGeometry;
72 bool isInvertedRingValid = false;
73 std::unique_ptr<TopologyValidationError> validErr;
74
75 bool hasInvalidError()
76 {
77 return validErr != nullptr;
78 }
79
80 void logInvalid(int code, const geom::CoordinateXY& 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 CoordinateXY* 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::CoordinateXY& coord)
270 {
271 return isValid(&coord);
272 }
273
279 bool isValid();
280
289 static bool isValid(const geom::CoordinateXY* 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:56
Represents a collection of heterogeneous Geometry objects.
Definition GeometryCollection.h:51
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition Geometry.h:197
Definition LineString.h:66
Models an OGC SFS LinearRing. A LinearRing is a LineString which is both closed and simple.
Definition LinearRing.h:54
Definition MultiPoint.h:50
Definition MultiPolygon.h:58
Definition Point.h:61
Represents a linear polygon, which may include holes.
Definition Polygon.h:61
Definition IsValidOp.h:57
IsValidOp(const geom::Geometry *p_inputGeometry)
Definition IsValidOp.h:221
static bool isValid(const geom::CoordinateXY *coord)
const TopologyValidationError * getValidationError()
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