GEOS 3.15.0beta1
TPVWSimplifier.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 <queue>
18
19#include <geos/index/strtree/TemplateSTRtree.h>
20#include <geos/index/VertexSequencePackedRtree.h>
21#include <geos/simplify/LinkedLine.h>
22#include <geos/coverage/Corner.h>
23#include <geos/export.h>
24#include <geos/util/Progress.h>
25
26
27namespace geos {
28namespace geom {
29class Coordinate;
31class Envelope;
32class Geometry;
33class GeometryFactory;
34class LineString;
35class MultiLineString;
36}
37}
38
39namespace geos {
40namespace coverage { // geos::coverage
41
42
61class GEOS_DLL TPVWSimplifier
62{
63 using Corner = geos::coverage::Corner;
64 using Coordinate = geos::geom::Coordinate;
65 using CoordinateSequence = geos::geom::CoordinateSequence;
66 using Envelope = geos::geom::Envelope;
67 using Geometry = geos::geom::Geometry;
68 using GeometryFactory = geos::geom::GeometryFactory;
69 using LineString = geos::geom::LineString;
70 using MultiLineString = geos::geom::MultiLineString;
71 using VertexSequencePackedRtree = geos::index::VertexSequencePackedRtree;
72 template<typename ItemType>
73 using TemplateSTRtree = geos::index::strtree::TemplateSTRtree<ItemType>;
74 using LinkedLine = geos::simplify::LinkedLine;
75
76public:
77
78 // Prototype
79 class EdgeIndex;
80
81 /* private static */
82 class Edge {
83
84 public:
85
86 // Members
87 double areaTolerance;
88 bool isFreeRing;
89 const Envelope* envelope;
90 std::size_t nbPts;
91 LinkedLine linkedLine;
92 VertexSequencePackedRtree vertexIndex;
93 std::size_t minEdgeSize;
94
104 Edge(const LineString* p_inputLine, bool p_isFreeRing, double p_areaTolerance);
105
106 const Coordinate& getCoordinate(std::size_t index) const;
107
108 const Envelope* getEnvelopeInternal() const;
109
110 std::size_t size() const;
111
112 std::unique_ptr<CoordinateSequence> simplify(EdgeIndex& edgeIndex);
113
114 void createQueue(Corner::PriorityQueue& pq);
115
116 void addCorner(std::size_t i, Corner::PriorityQueue& cornerQueue);
117
118 bool isRemovable(Corner& corner, EdgeIndex& edgeIndex) const;
119
129 bool hasIntersectingVertex(const Corner& corner,
130 const Envelope& cornerEnv,
131 const Edge& edge) const;
132
133 std::vector<std::size_t> query(const Envelope& cornerEnv) const;
134
144 void removeCorner(
145 Corner& corner,
146 Corner::PriorityQueue& cornerQueue);
147
148 }; // Edge
149
150 class EdgeIndex
151 {
152 public:
153
154 TemplateSTRtree<const Edge*> index;
155
156 void add(std::vector<Edge>& edges);
157
158 std::vector<const Edge*> query(const Envelope& queryEnv);
159
160 }; // EdgeIndex
161
162
171 static std::unique_ptr<MultiLineString> simplify(
172 const MultiLineString* lines,
173 double distanceTolerance,
174 geos::util::ProgressFunction* progressFunction);
175
190 static std::unique_ptr<MultiLineString> simplify(
191 const MultiLineString* lines,
192 std::vector<bool>& freeRings,
193 const MultiLineString* constraintLines,
194 double distanceTolerance,
195 geos::util::ProgressFunction* progressFunction);
196
197 // Constructor
198 TPVWSimplifier(const MultiLineString* lines,
199 double distanceTolerance);
200
201
202private:
203
204 // Members
205 const MultiLineString* inputLines;
206 std::vector<bool> isFreeRing;
207 double areaTolerance;
208 const GeometryFactory* geomFactory;
209 const MultiLineString* constraintLines;
210
211
212 // Methods
213 void setFreeRingIndices(std::vector<bool>& freeRing);
214
215 void setConstraints(const MultiLineString* constraints);
216
217 std::unique_ptr<MultiLineString> simplify(geos::util::ProgressFunction* progressFunction);
218
219 std::vector<Edge> createEdges(
220 const MultiLineString* lines,
221 std::vector<bool>& freeRing,
222 geos::util::ProgressFunction* progressFunction);
223
224
225}; // TPVWSimplifier
226
227
228} // geos::coverage
229} // geos
static std::unique_ptr< MultiLineString > simplify(const MultiLineString *lines, double distanceTolerance, geos::util::ProgressFunction *progressFunction)
static std::unique_ptr< MultiLineString > simplify(const MultiLineString *lines, std::vector< bool > &freeRings, const MultiLineString *constraintLines, double distanceTolerance, geos::util::ProgressFunction *progressFunction)
The internal representation of a list of coordinates inside a Geometry.
Definition CoordinateSequence.h:56
Coordinate is the lightweight class used to store coordinates.
Definition Coordinate.h:220
An Envelope defines a rectangulare region of the 2D coordinate plane.
Definition Envelope.h:59
Supplies a set of utility methods for building Geometry objects from CoordinateSequence or other Geom...
Definition GeometryFactory.h:72
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition Geometry.h:201
Definition LineString.h:66
Models a collection of LineStrings.
Definition MultiLineString.h:49
Definition VertexSequencePackedRtree.h:49
Definition Angle.h:26
Provides classes for various kinds of spatial indexes.
Definition CleanCoverage.h:39
std::function< void(double, const char *)> ProgressFunction
Definition Progress.h:29
Basic namespace for all GEOS functionalities.
Definition geos.h:38