GEOS 3.11.1
LineSequencer.h
1/**********************************************************************
2 *
3 * GEOS - Geometry Engine Open Source
4 * http://geos.osgeo.org
5 *
6 * Copyright (C) 2011 Sandro Santilli <strk@kbt.io>
7 * Copyright (C) 2006 Refractions Research Inc.
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 * Last port: operation/linemerge/LineSequencer.java r378 (JTS-1.12)
17 *
18 **********************************************************************/
19
20#pragma once
21
22#include <geos/export.h>
23
24#include <geos/operation/linemerge/LineMergeGraph.h> // for composition
25#include <geos/geom/Geometry.h> // for inlines
26#include <geos/geom/LineString.h> // for inlines
27
28#include <vector>
29#include <list>
30#include <memory> // for unique_ptr
31
32#ifdef _MSC_VER
33#pragma warning(push)
34#pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
35#endif
36
37// Forward declarations
38namespace geos {
39namespace geom {
40class GeometryFactory;
41class Geometry;
42class LineString;
43}
44namespace planargraph {
45class DirectedEdge;
46class Subgraph;
47class Node;
48}
49}
50
51
52namespace geos {
53namespace operation { // geos::operation
54namespace linemerge { // geos::operation::linemerge
55
92class GEOS_DLL LineSequencer {
93
94private:
95 typedef std::list<planargraph::DirectedEdge*> DirEdgeList;
96 typedef std::vector< DirEdgeList* > Sequences;
97
98 LineMergeGraph graph;
99 const geom::GeometryFactory* factory;
100 unsigned int lineCount;
101 bool isRun;
102 std::unique_ptr<geom::Geometry> sequencedGeometry;
103 bool isSequenceableVar;
104
105 void addLine(const geom::LineString* lineString);
106 void computeSequence();
107 Sequences* findSequences();
108 DirEdgeList* findSequence(planargraph::Subgraph& graph);
109
110 void delAll(Sequences&);
111
124 geom::Geometry* buildSequencedGeometry(const Sequences& sequences);
125
126 static const planargraph::Node* findLowestDegreeNode(
127 const planargraph::Subgraph& graph);
128
129 void addReverseSubpath(const planargraph::DirectedEdge* de,
130 DirEdgeList& deList,
131 DirEdgeList::iterator lit,
132 bool expectedClosed);
133
142 static const planargraph::DirectedEdge* findUnvisitedBestOrientedDE(
143 const planargraph::Node* node);
144
163 DirEdgeList* orient(DirEdgeList* seq);
164
173 DirEdgeList* reverse(DirEdgeList& seq);
174
182 bool hasSequence(planargraph::Subgraph& graph);
183
184public:
185
186 static geom::Geometry*
187 sequence(const geom::Geometry& geom)
188 {
189 LineSequencer sequencer;
190 sequencer.add(geom);
191 return sequencer.getSequencedLineStrings();
192 }
193
195 :
196 factory(nullptr),
197 lineCount(0),
198 isRun(false),
199 sequencedGeometry(nullptr),
200 isSequenceableVar(false)
201 {}
202
214 static bool isSequenced(const geom::Geometry* geom);
215
222 bool
224 {
225 computeSequence();
226 return isSequenceableVar;
227 }
228
238 void
239 add(const geom::Geometry& geometry)
240 {
241 geometry.applyComponentFilter(*this);
242 }
243
244 template <class TargetContainer>
245 void
246 add(TargetContainer& geoms)
247 {
248 for(typename TargetContainer::const_iterator i = geoms.begin(),
249 e = geoms.end(); i != e; ++i) {
250 const geom::Geometry* g = *i;
251 add(*g);
252 }
253 }
254
259 void
261 {
262 if(const geom::LineString* ls = dynamic_cast<const geom::LineString*>(g)) {
263 addLine(ls);
264 }
265 }
266
277 getSequencedLineStrings(bool release = 1)
278 {
279 computeSequence();
280 if(release) {
281 return sequencedGeometry.release();
282 }
283 else {
284 return sequencedGeometry.get();
285 }
286 }
287};
288
289} // namespace geos::operation::linemerge
290} // namespace geos::operation
291} // namespace geos
292
293#ifdef _MSC_VER
294#pragma warning(pop)
295#endif
Supplies a set of utility methods for building Geometry objects from CoordinateSequence or other Geom...
Definition: GeometryFactory.h:66
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition: Geometry.h:186
void applyComponentFilter(T &f) const
Apply a filter to each component of this geometry. The filter is expected to provide a ....
Definition: Geometry.h:763
Definition: LineString.h:66
A planar graph of edges that is analyzed to sew the edges together.
Definition: LineMergeGraph.h:58
Builds a sequence from a set of LineStrings so that they are ordered end to end.
Definition: LineSequencer.h:92
bool isSequenceable()
Tests whether the arrangement of linestrings has a valid sequence.
Definition: LineSequencer.h:223
void add(const geom::Geometry &geometry)
Adds a Geometry to be sequenced.
Definition: LineSequencer.h:239
geom::Geometry * getSequencedLineStrings(bool release=1)
Returns the LineString or MultiLineString built by the sequencing process, if one exists.
Definition: LineSequencer.h:277
void filter(const geom::Geometry *g)
Act as a GeometryComponentFilter so to extract the linearworks.
Definition: LineSequencer.h:260
static bool isSequenced(const geom::Geometry *geom)
Tests whether a Geometry is sequenced correctly.
Represents a directed edge in a PlanarGraph.
Definition: planargraph/DirectedEdge.h:45
A node in a PlanarGraph is a location where 0 or more Edge meet.
Definition: planargraph/Node.h:44
A subgraph of a PlanarGraph.
Definition: Subgraph.h:52
Basic namespace for all GEOS functionalities.
Definition: geos.h:39