00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef GEOS_OP_LINEMERGE_LINESEQUENCER_H
00021 #define GEOS_OP_LINEMERGE_LINESEQUENCER_H
00022
00023 #include <geos/export.h>
00024
00025 #include <geos/operation/linemerge/LineMergeGraph.h>
00026 #include <geos/geom/Geometry.h>
00027 #include <geos/geom/LineString.h>
00028
00029 #include <vector>
00030 #include <list>
00031 #include <memory>
00032
00033
00034 namespace geos {
00035 namespace geom {
00036 class GeometryFactory;
00037 class Geometry;
00038 class LineString;
00039 }
00040 namespace planargraph {
00041 class DirectedEdge;
00042 class Subgraph;
00043 class Node;
00044 }
00045 }
00046
00047
00048 namespace geos {
00049 namespace operation {
00050 namespace linemerge {
00051
00087 class GEOS_DLL LineSequencer {
00088
00089 private:
00090 typedef std::list<planargraph::DirectedEdge*> DirEdgeList;
00091 typedef std::vector< DirEdgeList* > Sequences;
00092
00093 LineMergeGraph graph;
00094 const geom::GeometryFactory *factory;
00095 unsigned int lineCount;
00096 bool isRun;
00097 std::auto_ptr<geom::Geometry> sequencedGeometry;
00098 bool isSequenceableVar;
00099
00100 void addLine(const geom::LineString *lineString);
00101 void computeSequence();
00102 Sequences* findSequences();
00103 DirEdgeList* findSequence(planargraph::Subgraph& graph);
00104
00106 static geom::LineString* reverse(const geom::LineString *line);
00107
00117 geom::Geometry* buildSequencedGeometry(const Sequences& sequences);
00118
00119 static const planargraph::Node* findLowestDegreeNode(
00120 const planargraph::Subgraph& graph);
00121
00122 void addReverseSubpath(const planargraph::DirectedEdge *de,
00123 DirEdgeList& deList,
00124 DirEdgeList::iterator lit,
00125 bool expectedClosed);
00126
00135 static const planargraph::DirectedEdge* findUnvisitedBestOrientedDE(
00136 const planargraph::Node* node);
00137
00156 DirEdgeList* orient(DirEdgeList* seq);
00157
00166 DirEdgeList* reverse(DirEdgeList& seq);
00167
00175 bool hasSequence(planargraph::Subgraph& graph);
00176
00177 public:
00178
00179 LineSequencer()
00180 :
00181 factory(0),
00182 lineCount(0),
00183 isRun(false),
00184 sequencedGeometry(0),
00185 isSequenceableVar(false)
00186 {}
00187
00198 static bool isSequenced(const geom::Geometry* geom);
00199
00206 bool isSequenceable() {
00207 computeSequence();
00208 return isSequenceableVar;
00209 }
00210
00219 void add(const geom::Geometry& geometry) {
00220 geometry.applyComponentFilter(*this);
00221 }
00222
00227 void filter(const geom::Geometry* g)
00228 {
00229 if (const geom::LineString *ls=dynamic_cast<const geom::LineString *>(g))
00230 {
00231 addLine(ls);
00232 }
00233 }
00234
00244 geom::Geometry*
00245 getSequencedLineStrings(bool release=1) {
00246 computeSequence();
00247 if (release) return sequencedGeometry.release();
00248 else return sequencedGeometry.get();
00249 }
00250
00251
00252 };
00253
00254 }
00255 }
00256 }
00257
00258 #endif // GEOS_OP_LINEMERGE_LINESEQUENCER_H
00259
00260
00261
00262
00263
00264
00265