GEOS 3.3.4

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List

LineSequencer.h
1 /**********************************************************************
2 * $Id: LineSequencer.h 3309 2011-04-27 15:47:14Z strk $
3 *
4 * GEOS - Geometry Engine Open Source
5 * http://geos.refractions.net
6 *
7 * Copyright (C) 2011 Sandro Santilli <strk@keybit.net>
8 * Copyright (C) 2006 Refractions Research Inc.
9 *
10 * This is free software; you can redistribute and/or modify it under
11 * the terms of the GNU Lesser General Public Licence as published
12 * by the Free Software Foundation.
13 * See the COPYING file for more information.
14 *
15 **********************************************************************
16 *
17 * Last port: operation/linemerge/LineSequencer.java r378 (JTS-1.12)
18 *
19 **********************************************************************/
20
21 #ifndef GEOS_OP_LINEMERGE_LINESEQUENCER_H
22 #define GEOS_OP_LINEMERGE_LINESEQUENCER_H
23
24 #include <geos/export.h>
25
26 #include <geos/operation/linemerge/LineMergeGraph.h> // for composition
27 #include <geos/geom/Geometry.h> // for inlines
28 #include <geos/geom/LineString.h> // for inlines
29
30 #include <vector>
31 #include <list>
32 #include <memory> // for auto_ptr
33
34 #ifdef _MSC_VER
35 #pragma warning(push)
36 #pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
37 #endif
38
39 // Forward declarations
40 namespace geos {
41 namespace geom {
42 class GeometryFactory;
43 class Geometry;
44 class LineString;
45 }
46 namespace planargraph {
47 class DirectedEdge;
48 class Subgraph;
49 class Node;
50 }
51 }
52
53
54 namespace geos {
55 namespace operation { // geos::operation
56 namespace linemerge { // geos::operation::linemerge
57
100 class GEOS_DLL LineSequencer {
101
102 private:
103 typedef std::list<planargraph::DirectedEdge*> DirEdgeList;
104 typedef std::vector< DirEdgeList* > Sequences;
105
106 LineMergeGraph graph;
107 const geom::GeometryFactory *factory;
108 unsigned int lineCount;
109 bool isRun;
110 std::auto_ptr<geom::Geometry> sequencedGeometry;
111 bool isSequenceableVar;
112
113 void addLine(const geom::LineString *lineString);
114 void computeSequence();
115 Sequences* findSequences();
116 DirEdgeList* findSequence(planargraph::Subgraph& graph);
117
118 void delAll( Sequences& );
119
121 static geom::LineString* reverse(const geom::LineString *line);
122
135 geom::Geometry* buildSequencedGeometry(const Sequences& sequences);
136
137 static const planargraph::Node* findLowestDegreeNode(
138 const planargraph::Subgraph& graph);
139
140 void addReverseSubpath(const planargraph::DirectedEdge *de,
141 DirEdgeList& deList,
142 DirEdgeList::iterator lit,
143 bool expectedClosed);
144
153 static const planargraph::DirectedEdge* findUnvisitedBestOrientedDE(
154 const planargraph::Node* node);
155
174 DirEdgeList* orient(DirEdgeList* seq);
175
184 DirEdgeList* reverse(DirEdgeList& seq);
185
193 bool hasSequence(planargraph::Subgraph& graph);
194
195 public:
196
197 static geom::Geometry* sequence(const geom::Geometry& geom)
198 {
199 LineSequencer sequencer;
200 sequencer.add(geom);
201 return sequencer.getSequencedLineStrings();
202 }
203
204 LineSequencer()
205 :
206 factory(0),
207 lineCount(0),
208 isRun(false),
209 sequencedGeometry(0),
210 isSequenceableVar(false)
211 {}
212
223 static bool isSequenced(const geom::Geometry* geom);
224
231 bool isSequenceable() {
232 computeSequence();
233 return isSequenceableVar;
234 }
235
244 void add(const geom::Geometry& geometry) {
245 geometry.applyComponentFilter(*this);
246 }
247
248 template <class TargetContainer>
249 void add(TargetContainer& geoms)
250 {
251 for (typename TargetContainer::const_iterator i = geoms.begin(),
252 e = geoms.end(); i != e; ++i)
253 {
254 const geom::Geometry* g = *i;
255 add(*g);
256 }
257 }
258
263 void filter(const geom::Geometry* g)
264 {
265 if (const geom::LineString *ls=dynamic_cast<const geom::LineString *>(g))
266 {
267 addLine(ls);
268 }
269 }
270
280 geom::Geometry*
281 getSequencedLineStrings(bool release=1) {
282 computeSequence();
283 if (release) return sequencedGeometry.release();
284 else return sequencedGeometry.get();
285 }
286 };
287
288 } // namespace geos::operation::linemerge
289 } // namespace geos::operation
290 } // namespace geos
291
292 #ifdef _MSC_VER
293 #pragma warning(pop)
294 #endif
295
296 #endif // GEOS_OP_LINEMERGE_LINESEQUENCER_H
297
298 /**********************************************************************
299 * $Log$
300 * Revision 1.1 2006/03/22 10:13:53 strk
301 * opLinemerge.h split
302 *
303 **********************************************************************/