GEOS  3.8.0dev
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 #ifndef GEOS_OP_LINEMERGE_LINESEQUENCER_H
21 #define GEOS_OP_LINEMERGE_LINESEQUENCER_H
22 
23 #include <geos/export.h>
24 
25 #include <geos/operation/linemerge/LineMergeGraph.h> // for composition
26 #include <geos/geom/Geometry.h> // for inlines
27 #include <geos/geom/LineString.h> // for inlines
28 
29 #include <vector>
30 #include <list>
31 #include <memory> // for unique_ptr
32 
33 #ifdef _MSC_VER
34 #pragma warning(push)
35 #pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
36 #endif
37 
38 // Forward declarations
39 namespace geos {
40 namespace geom {
41 class GeometryFactory;
42 class Geometry;
43 class LineString;
44 }
45 namespace planargraph {
46 class DirectedEdge;
47 class Subgraph;
48 class Node;
49 }
50 }
51 
52 
53 namespace geos {
54 namespace operation { // geos::operation
55 namespace linemerge { // geos::operation::linemerge
56 
99 class GEOS_DLL LineSequencer {
100 
101 private:
102  typedef std::list<planargraph::DirectedEdge*> DirEdgeList;
103  typedef std::vector< DirEdgeList* > Sequences;
104 
105  LineMergeGraph graph;
106  const geom::GeometryFactory* factory;
107  unsigned int lineCount;
108  bool isRun;
109  std::unique_ptr<geom::Geometry> sequencedGeometry;
110  bool isSequenceableVar;
111 
112  void addLine(const geom::LineString* lineString);
113  void computeSequence();
114  Sequences* findSequences();
115  DirEdgeList* findSequence(planargraph::Subgraph& graph);
116 
117  void delAll(Sequences&);
118 
120  static geom::LineString* reverse(const geom::LineString* line);
121 
134  geom::Geometry* buildSequencedGeometry(const Sequences& sequences);
135 
136  static const planargraph::Node* findLowestDegreeNode(
137  const planargraph::Subgraph& graph);
138 
139  void addReverseSubpath(const planargraph::DirectedEdge* de,
140  DirEdgeList& deList,
141  DirEdgeList::iterator lit,
142  bool expectedClosed);
143 
152  static const planargraph::DirectedEdge* findUnvisitedBestOrientedDE(
153  const planargraph::Node* node);
154 
173  DirEdgeList* orient(DirEdgeList* seq);
174 
183  DirEdgeList* reverse(DirEdgeList& seq);
184 
192  bool hasSequence(planargraph::Subgraph& graph);
193 
194 public:
195 
196  static geom::Geometry*
197  sequence(const geom::Geometry& geom)
198  {
199  LineSequencer sequencer;
200  sequencer.add(geom);
201  return sequencer.getSequencedLineStrings();
202  }
203 
204  LineSequencer()
205  :
206  factory(nullptr),
207  lineCount(0),
208  isRun(false),
209  sequencedGeometry(nullptr),
210  isSequenceableVar(false)
211  {}
212 
223  static bool isSequenced(const geom::Geometry* geom);
224 
231  bool
233  {
234  computeSequence();
235  return isSequenceableVar;
236  }
237 
246  void
247  add(const geom::Geometry& geometry)
248  {
249  geometry.applyComponentFilter(*this);
250  }
251 
252  template <class TargetContainer>
253  void
254  add(TargetContainer& geoms)
255  {
256  for(typename TargetContainer::const_iterator i = geoms.begin(),
257  e = geoms.end(); i != e; ++i) {
258  const geom::Geometry* g = *i;
259  add(*g);
260  }
261  }
262 
267  void
269  {
270  if(const geom::LineString* ls = dynamic_cast<const geom::LineString*>(g)) {
271  addLine(ls);
272  }
273  }
274 
285  getSequencedLineStrings(bool release = 1)
286  {
287  computeSequence();
288  if(release) {
289  return sequencedGeometry.release();
290  }
291  else {
292  return sequencedGeometry.get();
293  }
294  }
295 };
296 
297 } // namespace geos::operation::linemerge
298 } // namespace geos::operation
299 } // namespace geos
300 
301 #ifdef _MSC_VER
302 #pragma warning(pop)
303 #endif
304 
305 #endif // GEOS_OP_LINEMERGE_LINESEQUENCER_H
Builds a sequence from a set of LineStrings so that they are ordered end to end.
Definition: LineSequencer.h:99
void filter(const geom::Geometry *g)
Definition: LineSequencer.h:268
geom::Geometry * getSequencedLineStrings(bool release=1)
Definition: LineSequencer.h:285
bool isSequenceable()
Definition: LineSequencer.h:232
Represents a directed edge in a PlanarGraph.
Definition: planargraph/DirectedEdge.h:46
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition: Geometry.h:187
Definition: LineString.h:69
A planar graph of edges that is analyzed to sew the edges together.
Definition: LineMergeGraph.h:59
Supplies a set of utility methods for building Geometry objects from CoordinateSequence or other Geom...
Definition: GeometryFactory.h:67
void add(const geom::Geometry &geometry)
Definition: LineSequencer.h:247
Basic namespace for all GEOS functionalities.
Definition: IndexedNestedRingTester.h:25
A node in a PlanarGraph is a location where 0 or more Edge meet.
Definition: planargraph/Node.h:45
A subgraph of a PlanarGraph.
Definition: Subgraph.h:53
void applyComponentFilter(T &f) const
Apply a fiter to each component of this geometry. The filter is expected to provide a ...
Definition: Geometry.h:751