GEOS 3.6.2
LineSequencer.h
1/**********************************************************************
2 *
3 * GEOS - Geometry Engine Open Source
4 * http://geos.osgeo.org
5 *
6 * Copyright (C) 2011 Sandro Santilli <strk@keybit.net>
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 auto_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
39namespace 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
53namespace geos {
54namespace operation { // geos::operation
55namespace linemerge { // geos::operation::linemerge
56
99class GEOS_DLL LineSequencer {
100
101private:
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::auto_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
194public:
195
196 static geom::Geometry* sequence(const geom::Geometry& geom)
197 {
198 LineSequencer sequencer;
199 sequencer.add(geom);
200 return sequencer.getSequencedLineStrings();
201 }
202
203 LineSequencer()
204 :
205 factory(0),
206 lineCount(0),
207 isRun(false),
208 sequencedGeometry(0),
209 isSequenceableVar(false)
210 {}
211
222 static bool isSequenced(const geom::Geometry* geom);
223
231 computeSequence();
232 return isSequenceableVar;
233 }
234
243 void add(const geom::Geometry& geometry) {
244 geometry.applyComponentFilter(*this);
245 }
246
247 template <class TargetContainer>
248 void add(TargetContainer& geoms)
249 {
250 for (typename TargetContainer::const_iterator i = geoms.begin(),
251 e = geoms.end(); i != e; ++i)
252 {
253 const geom::Geometry* g = *i;
254 add(*g);
255 }
256 }
257
262 void filter(const geom::Geometry* g)
263 {
264 if (const geom::LineString *ls=dynamic_cast<const geom::LineString *>(g))
265 {
266 addLine(ls);
267 }
268 }
269
280 getSequencedLineStrings(bool release=1) {
281 computeSequence();
282 if (release) return sequencedGeometry.release();
283 else return sequencedGeometry.get();
284 }
285};
286
287} // namespace geos::operation::linemerge
288} // namespace geos::operation
289} // namespace geos
290
291#ifdef _MSC_VER
292#pragma warning(pop)
293#endif
294
295#endif // GEOS_OP_LINEMERGE_LINESEQUENCER_H
Supplies a set of utility methods for building Geometry objects from CoordinateSequence or other Geom...
Definition GeometryFactory.h:67
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition Geometry.h:167
void applyComponentFilter(T &f) const
Apply a fiter to each component of this geometry. The filter is expected to provide a ....
Definition Geometry.h:685
Definition LineString.h:70
A planar graph of edges that is analyzed to sew the edges together.
Definition LineMergeGraph.h:59
bool isSequenceable()
Definition LineSequencer.h:230
void add(const geom::Geometry &geometry)
Definition LineSequencer.h:243
geom::Geometry * getSequencedLineStrings(bool release=1)
Definition LineSequencer.h:280
void filter(const geom::Geometry *g)
Definition LineSequencer.h:262
static bool isSequenced(const geom::Geometry *geom)
Represents a directed edge in a PlanarGraph.
Definition planargraph/DirectedEdge.h:46
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:54
Contains the Geometry interface hierarchy and supporting classes.
Definition IndexedNestedRingTester.h:26
Line merging package.
Definition EdgeString.h:40
Provides classes for implementing operations on geometries.
Definition IndexedNestedRingTester.h:40
Contains classes to implement a planar graph data structure.
Definition LineMergeDirectedEdge.h:32
Basic namespace for all GEOS functionalities.
Definition IndexedNestedRingTester.h:25