GEOS  3.12.0dev
PolygonHullSimplifier.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.
12  *
13  **********************************************************************/
14
15 #pragma once
16
17 #include <geos/geom/Geometry.h>
18 #include <geos/util/IllegalArgumentException.h>
19 #include <geos/simplify/RingHull.h>
20
21
22 namespace geos {
23 namespace geom {
24 class GeometryFactory;
25 class LinearRing;
26 class MultiPolygon;
27 class Polygon;
28 }
29 namespace algorithm {
30 namespace hull {
31 class RingHullIndex;
32 }
33 }
34 }
35
36
43
44
45 namespace geos {
46 namespace simplify { // geos::simplify
47
85 class GEOS_DLL PolygonHullSimplifier
86 {
87
88 public:
89
99  PolygonHullSimplifier(const Geometry* geom, bool bOuter)
100  : inputGeom(geom)
101  , geomFactory(geom->getFactory())
102  , isOuter(bOuter)
103  , vertexNumFraction(-1.0)
105  {
106  if (!geom->isPolygonal()) {
107  throw util::IllegalArgumentException("Input geometry must be polygonal");
108  }
109  };
110
124  static std::unique_ptr<Geometry> hull(
125  const Geometry* geom,
126  bool isOuter,
127  double vertexNumFraction);
128
143  const Geometry* geom,
144  bool isOuter,
146
147
155  void setVertexNumFraction(double p_vertexNumFraction);
163
169  std::unique_ptr<Geometry> getResult();
170
171
172
173 private:
174
175  // Members
176  const Geometry* inputGeom;
177  const GeometryFactory* geomFactory;
178  bool isOuter;
179  double vertexNumFraction;
181  // Allocate the RingHull* in here so they are cleaned
182  // up with PolygonHullSimplifier
183  std::vector<std::unique_ptr<RingHull>> ringStore;
184
192  std::unique_ptr<Geometry> computeMultiPolygonAll(const MultiPolygon* multiPoly);
193  std::unique_ptr<Geometry> computeMultiPolygonEach(const MultiPolygon* multiPoly);
194  std::unique_ptr<Polygon> computePolygon(const Polygon* poly);
195
204  std::vector<RingHull*> initPolygon(const Polygon* poly,
205  RingHullIndex& hullIndex);
206
207  double ringArea(const Polygon* poly) const;
208
209  RingHull* createRingHull(
210  const LinearRing* ring,
211  bool isOuter,
212  double areaTotal,
213  RingHullIndex& hullIndex);
214
215  std::unique_ptr<Polygon> polygonHull(
216  const Polygon* poly,
217  std::vector<RingHull*>& ringHulls,
218  RingHullIndex& hullIndex) const;
219
225  PolygonHullSimplifier& operator=(const PolygonHullSimplifier&) = delete;
226
227 }; // PolygonHullSimplifier
228
229
230 } // geos::simplify
231 } // geos
232
An Envelope defines a rectangulare region of the 2D coordinate plane.
Definition: Envelope.h:58
Supplies a set of utility methods for building Geometry objects from CoordinateSequence or other Geom...
Definition: GeometryFactory.h:65
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition: Geometry.h:186
Models an OGC SFS LinearRing. A LinearRing is a LineString which is both closed and simple.
Definition: LinearRing.h:54
Definition: MultiPolygon.h:58
Represents a linear polygon, which may include holes.
Definition: Polygon.h:60
Definition: PolygonHullSimplifier.h:86