GEOS 3.14.0dev
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
25
26namespace geos {
27namespace geom {
28class Coordinate;
29class CoordinateSequence;
30class Envelope;
31class Geometry;
32class GeometryFactory;
33class LineString;
34class MultiLineString;
35}
36}
37
38namespace geos {
39namespace coverage { // geos::coverage
40
41
60class GEOS_DLL TPVWSimplifier
61{
62 using Corner = geos::coverage::Corner;
71 template<typename ItemType>
72 using TemplateSTRtree = geos::index::strtree::TemplateSTRtree<ItemType>;
73 using LinkedLine = geos::simplify::LinkedLine;
74
75public:
76
77 // Prototype
78 class EdgeIndex;
79
80 /* private static */
81 class Edge {
82
83 public:
84
85 // Members
86 double areaTolerance;
87 bool isFreeRing;
88 const Envelope* envelope;
89 std::size_t nbPts;
90 LinkedLine linkedLine;
91 VertexSequencePackedRtree vertexIndex;
92 std::size_t minEdgeSize;
93
103 Edge(const LineString* p_inputLine, bool p_isFreeRing, double p_areaTolerance);
104
105 const Coordinate& getCoordinate(std::size_t index) const;
106
107 const Envelope* getEnvelopeInternal() const;
108
109 std::size_t size() const;
110
111 std::unique_ptr<CoordinateSequence> simplify(EdgeIndex& edgeIndex);
112
113 void createQueue(Corner::PriorityQueue& pq);
114
115 void addCorner(std::size_t i, Corner::PriorityQueue& cornerQueue);
116
117 bool isRemovable(Corner& corner, EdgeIndex& edgeIndex) const;
118
128 bool hasIntersectingVertex(const Corner& corner,
129 const Envelope& cornerEnv,
130 const Edge& edge) const;
131
132 std::vector<std::size_t> query(const Envelope& cornerEnv) const;
133
143 void removeCorner(
144 Corner& corner,
145 Corner::PriorityQueue& cornerQueue);
146
147 }; // Edge
148
149 class EdgeIndex
150 {
151 public:
152
153 TemplateSTRtree<const Edge*> index;
154
155 void add(std::vector<Edge>& edges);
156
157 std::vector<const Edge*> query(const Envelope& queryEnv);
158
159 }; // EdgeIndex
160
161
169 static std::unique_ptr<MultiLineString> simplify(
170 const MultiLineString* lines,
171 double distanceTolerance);
172
186 static std::unique_ptr<MultiLineString> simplify(
187 const MultiLineString* lines,
188 std::vector<bool>& freeRings,
189 const MultiLineString* constraintLines,
190 double distanceTolerance);
191
192 // Constructor
193 TPVWSimplifier(const MultiLineString* lines,
194 double distanceTolerance);
195
196
197private:
198
199 // Members
200 const MultiLineString* inputLines;
201 std::vector<bool> isFreeRing;
202 double areaTolerance;
203 const GeometryFactory* geomFactory;
204 const MultiLineString* constraintLines;
205
206
207 // Methods
208 void setFreeRingIndices(std::vector<bool>& freeRing);
209
210 void setConstraints(const MultiLineString* constraints);
211
212 std::unique_ptr<MultiLineString> simplify();
213
214 std::vector<Edge> createEdges(
215 const MultiLineString* lines,
216 std::vector<bool>& freeRing);
217
218
219}; // TPVWSimplifier
220
221
222} // geos::coverage
223} // geos
Definition TPVWSimplifier.h:61
static std::unique_ptr< MultiLineString > simplify(const MultiLineString *lines, double distanceTolerance)
static std::unique_ptr< MultiLineString > simplify(const MultiLineString *lines, std::vector< bool > &freeRings, const MultiLineString *constraintLines, double distanceTolerance)
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:217
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:70
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition Geometry.h:197
Definition LineString.h:66
Models a collection of LineStrings.
Definition MultiLineString.h:49
Definition VertexSequencePackedRtree.h:49
Basic namespace for all GEOS functionalities.
Definition geos.h:39