00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef GEOS_OP_LINEMERGE_LINESEQUENCER_H
00017 #define GEOS_OP_LINEMERGE_LINESEQUENCER_H
00018
00019 #include <geos/operation/linemerge/LineMergeGraph.h>
00020 #include <geos/geom/Geometry.h>
00021 #include <geos/geom/LineString.h>
00022
00023 #include <vector>
00024 #include <list>
00025 #include <memory>
00026
00027
00028 namespace geos {
00029 namespace geom {
00030 class GeometryFactory;
00031 class Geometry;
00032 class LineString;
00033 }
00034 namespace planargraph {
00035 class DirectedEdge;
00036 class Subgraph;
00037 class Node;
00038 }
00039 }
00040
00041
00042 namespace geos {
00043 namespace operation {
00044 namespace linemerge {
00045
00082 class LineSequencer {
00083
00084 private:
00085 typedef std::list<planargraph::DirectedEdge*> DirEdgeList;
00086 typedef std::vector< DirEdgeList* > Sequences;
00087
00088 LineMergeGraph graph;
00089 const geom::GeometryFactory *factory;
00090 unsigned int lineCount;
00091 bool isRun;
00092 std::auto_ptr<geom::Geometry> sequencedGeometry;
00093 bool isSequenceableVar;
00094
00095 void addLine(const geom::LineString *lineString);
00096 void computeSequence();
00097 Sequences* findSequences();
00098 DirEdgeList* findSequence(planargraph::Subgraph& graph);
00099
00101 static geom::LineString* reverse(const geom::LineString *line);
00102
00112 geom::Geometry* buildSequencedGeometry(const Sequences& sequences);
00113
00114 static const planargraph::Node* findLowestDegreeNode(
00115 const planargraph::Subgraph& graph);
00116
00117 void addReverseSubpath(const planargraph::DirectedEdge *de,
00118 DirEdgeList& deList,
00119 DirEdgeList::iterator lit,
00120 bool expectedClosed);
00121
00130 static const planargraph::DirectedEdge* findUnvisitedBestOrientedDE(
00131 const planargraph::Node* node);
00132
00151 DirEdgeList* orient(DirEdgeList* seq);
00152
00161 DirEdgeList* reverse(DirEdgeList& seq);
00162
00170 bool hasSequence(planargraph::Subgraph& graph);
00171
00172 public:
00173
00174 LineSequencer()
00175 :
00176 factory(0),
00177 lineCount(0),
00178 isRun(false),
00179 sequencedGeometry(0),
00180 isSequenceableVar(false)
00181 {}
00182
00193 static bool isSequenced(const geom::Geometry* geom);
00194
00201 bool isSequenceable() {
00202 computeSequence();
00203 return isSequenceableVar;
00204 }
00205
00214 void add(const geom::Geometry& geometry) {
00215 geometry.applyComponentFilter(*this);
00216 }
00217
00222 void filter(const geom::Geometry* g)
00223 {
00224 if (const geom::LineString *ls=dynamic_cast<const geom::LineString *>(g))
00225 {
00226 addLine(ls);
00227 }
00228 }
00229
00239 geom::Geometry*
00240 getSequencedLineStrings(bool release=1) {
00241 computeSequence();
00242 if (release) return sequencedGeometry.release();
00243 else return sequencedGeometry.get();
00244 }
00245
00246
00247 };
00248
00249 }
00250 }
00251 }
00252
00253 #endif // GEOS_OP_LINEMERGE_LINESEQUENCER_H
00254
00255
00256
00257
00258
00259
00260