GEOS  3.14.0dev
GeometryFixer.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  *
8  * This is free software; you can redistribute and/or modify it under
9  * the terms of the GNU Lesser General Public Licence as published
10  * by the Free Software Foundation.
11  * See the COPYING file for more information.
12  *
13  **********************************************************************/
14 
15 #pragma once
16 
17 #include <memory>
18 #include <vector>
19 
20 #include <geos/geom/Geometry.h>
21 #include <geos/export.h>
22 
23 // Forward declarations
24 namespace geos {
25 namespace geom {
26 class GeometryFactory;
27 class Point;
28 class Polygon;
29 class LineString;
30 class LinearRing;
31 class MultiPoint;
32 class MultiPolygon;
33 class MultiLineString;
34 class GeometryCollection;
35 }
36 }
37 
38 namespace geos {
39 namespace geom { // geos.geom
40 namespace util { // geos.geom.util
41 
74 class GEOS_DLL GeometryFixer {
75 
76 private:
77 
78  const geom::Geometry* geom;
79  const geom::GeometryFactory* factory;
80  bool isKeepCollapsed; // false
81 
82 public:
83 
84  GeometryFixer(const geom::Geometry* p_geom)
85  : geom(p_geom)
86  , factory(p_geom->getFactory())
87  , isKeepCollapsed(false)
88  {};
89 
90  static std::unique_ptr<geom::Geometry> fix(const geom::Geometry* geom);
91 
100  void setKeepCollapsed(bool p_isKeepCollapsed);
101 
107  std::unique_ptr<geom::Geometry> getResult() const;
108 
109 private:
110 
111  std::unique_ptr<geom::Point> fixPoint(const geom::Point* geom) const;
112  std::unique_ptr<geom::Point> fixPointElement(const geom::Point* geom) const;
113  bool isValidPoint(const geom::Point* pt) const;
114  std::unique_ptr<geom::Geometry> fixMultiPoint(const geom::MultiPoint* geom) const;
115  std::unique_ptr<geom::Geometry> fixLinearRing(const geom::LinearRing* geom) const;
116  std::unique_ptr<geom::Geometry> fixLinearRingElement(const geom::LinearRing* geom) const;
117  std::unique_ptr<geom::Geometry> fixLineString(const geom::LineString* geom) const;
118  std::unique_ptr<geom::Geometry> fixLineStringElement(const geom::LineString* geom) const;
119 
126  std::unique_ptr<geom::Geometry> fixMultiLineString(const MultiLineString* geom) const;
127  std::unique_ptr<geom::Geometry> fixPolygon(const geom::Polygon* geom) const;
128  std::unique_ptr<geom::Geometry> fixPolygonElement(const geom::Polygon* geom) const;
129  std::vector<std::unique_ptr<Geometry>> fixHoles(const geom::Polygon* geom) const;
130  std::unique_ptr<geom::Geometry> removeHoles(const geom::Geometry* shell, const geom::Geometry* holes) const;
131  std::unique_ptr<geom::Geometry> fixRing(const geom::LinearRing* ring) const;
132  std::unique_ptr<geom::Geometry> fixMultiPolygon(const geom::MultiPolygon* geom) const;
133  std::unique_ptr<geom::Geometry> fixCollection(const geom::GeometryCollection* geom) const;
134 
135  void classifyHoles(
136  const Geometry* shell,
137  std::vector<std::unique_ptr<Geometry>>& holesFixed,
138  std::vector<const Geometry*>& holes,
139  std::vector<const Geometry*>& shells) const;
140 
148  std::unique_ptr<Geometry> difference(
149  const Geometry* shell,
150  std::vector<const Geometry*>& holes) const;
151 
160  std::unique_ptr<Geometry> unionGeometry(
161  std::vector<const Geometry*>& polys) const;
162 
163 };
164 
165 } // namespace geos.geom.util
166 } // namespace geos.geom
167 } // namespace geos
168 
169 
Represents a collection of heterogeneous Geometry objects.
Definition: GeometryCollection.h:51
Supplies a set of utility methods for building Geometry objects from CoordinateSequence or other Geom...
Definition: GeometryFactory.h:70
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition: Geometry.h:197
const GeometryFactory * getFactory() const
Gets the factory which contains the context in which this geometry was created.
Definition: Geometry.h:227
Definition: LineString.h:66
Models an OGC SFS LinearRing. A LinearRing is a LineString which is both closed and simple.
Definition: LinearRing.h:54
Models a collection of LineStrings.
Definition: MultiLineString.h:49
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: GeometryFixer.h:74
std::unique_ptr< geom::Geometry > getResult() const
void setKeepCollapsed(bool p_isKeepCollapsed)
Basic namespace for all GEOS functionalities.
Definition: Angle.h:25