GEOS  3.14.0dev
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
26 namespace geos {
27 namespace geom {
28 class CoordinateXY;
29 class Geometry;
30 class Point;
31 class MultiPoint;
32 class LineString;
33 class LinearRing;
34 class Polygon;
35 class MultiPolygon;
36 class GeometryCollection;
37 }
38 namespace algorithm {
39 namespace locate {
40 class IndexedPointInAreaLocator;
41 }
42 }
43 }
44 
45 
46 namespace geos { // geos.
47 namespace operation { // geos.operation
48 namespace valid { // geos.operation.valid
49 
57 class GEOS_DLL IsValidOp {
58  using CoordinateXY = geos::geom::CoordinateXY;
59 
60 private:
61 
62  static constexpr int MIN_SIZE_LINESTRING = 2;
63  static constexpr int MIN_SIZE_RING = 4;
64 
68  const geom::Geometry* inputGeometry;
73  bool isInvertedRingValid = false;
74  std::unique_ptr<TopologyValidationError> validErr;
75 
76  bool hasInvalidError()
77  {
78  return validErr != nullptr;
79  }
80 
81  void logInvalid(int code, const geom::CoordinateXY& pt);
82 
83  bool isValidGeometry(const geom::Geometry* g);
84 
88  bool isValid(const geom::Point* g);
89 
93  bool isValid(const geom::MultiPoint* g);
94 
99  bool isValid(const geom::LineString* g);
100 
104  bool isValid(const geom::LinearRing* g);
105 
110  bool isValid(const geom::Polygon* g);
111 
118  bool isValid(const geom::MultiPolygon* g);
119 
126  bool isValid(const geom::GeometryCollection* gc);
127 
128  void checkCoordinatesValid(const geom::CoordinateSequence* coords);
129  void checkCoordinatesValid(const geom::Polygon* poly);
130  void checkRingClosed(const geom::LinearRing* ring);
131  void checkRingsClosed(const geom::Polygon* poly);
132  void checkRingsPointSize(const geom::Polygon* poly);
133  void checkRingPointSize(const geom::LinearRing* ring);
134 
141  void checkTooFewPoints(const geom::LineString* line, std::size_t minSize);
142 
151  bool isNonRepeatedSizeAtLeast(const geom::LineString* line, std::size_t minSize);
152 
153  void checkAreaIntersections(PolygonTopologyAnalyzer& areaAnalyzer);
154 
160  void checkRingSimple(const geom::LinearRing* ring);
161 
162 
173  void checkHolesInShell(const geom::Polygon* poly);
174 
186  const CoordinateXY* findHoleOutsideShellPoint(
187  const geom::LinearRing* hole,
188  const geom::LinearRing* shell);
189 
197  void checkHolesNotNested(const geom::Polygon* poly);
198 
210  void checkShellsNotNested(const geom::MultiPolygon* mp);
211 
212  void checkInteriorConnected(PolygonTopologyAnalyzer& areaAnalyzer);
213 
214 
215 public:
216 
222  IsValidOp(const geom::Geometry* p_inputGeometry)
223  : inputGeometry(p_inputGeometry)
224  , validErr(nullptr)
225  {};
226 
255  {
256  isInvertedRingValid = p_isValid;
257  };
258 
264  static bool isValid(const geom::Geometry* geom)
265  {
266  IsValidOp ivo(geom);
267  return ivo.isValid();
268  };
269 
270  static bool isValid(const geom::CoordinateXY& coord)
271  {
272  return isValid(&coord);
273  }
274 
280  bool isValid();
281 
290  static bool isValid(const geom::CoordinateXY* coord);
291 
301 
302 
303 };
304 
305 
306 } // namespace geos.operation.valid
307 } // namespace geos.operation
308 } // 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:222
static bool isValid(const geom::CoordinateXY *coord)
const TopologyValidationError * getValidationError()
void setSelfTouchingRingFormingHoleValid(bool p_isValid)
Definition: IsValidOp.h:254
static bool isValid(const geom::Geometry *geom)
Definition: IsValidOp.h:264
Contains information about the nature and location of a geom::Geometry validation error.
Definition: TopologyValidationError.h:39
Basic namespace for all GEOS functionalities.
Definition: Angle.h:25