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 #ifdef _MSC_VER
00034 #pragma warning(push)
00035 #pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
00036 #endif
00037
00038
00039 namespace geos {
00040 namespace geom {
00041 class GeometryFactory;
00042 class Geometry;
00043 class LineString;
00044 }
00045 namespace planargraph {
00046 class DirectedEdge;
00047 class Subgraph;
00048 class Node;
00049 }
00050 }
00051
00052
00053 namespace geos {
00054 namespace operation {
00055 namespace linemerge {
00056
00099 class GEOS_DLL LineSequencer {
00100
00101 private:
00102 typedef std::list<planargraph::DirectedEdge*> DirEdgeList;
00103 typedef std::vector< DirEdgeList* > Sequences;
00104
00105 LineMergeGraph graph;
00106 const geom::GeometryFactory *factory;
00107 unsigned int lineCount;
00108 bool isRun;
00109 std::auto_ptr<geom::Geometry> sequencedGeometry;
00110 bool isSequenceableVar;
00111
00112 void addLine(const geom::LineString *lineString);
00113 void computeSequence();
00114 Sequences* findSequences();
00115 DirEdgeList* findSequence(planargraph::Subgraph& graph);
00116
00117 void delAll( Sequences& );
00118
00120 static geom::LineString* reverse(const geom::LineString *line);
00121
00134 geom::Geometry* buildSequencedGeometry(const Sequences& sequences);
00135
00136 static const planargraph::Node* findLowestDegreeNode(
00137 const planargraph::Subgraph& graph);
00138
00139 void addReverseSubpath(const planargraph::DirectedEdge *de,
00140 DirEdgeList& deList,
00141 DirEdgeList::iterator lit,
00142 bool expectedClosed);
00143
00152 static const planargraph::DirectedEdge* findUnvisitedBestOrientedDE(
00153 const planargraph::Node* node);
00154
00173 DirEdgeList* orient(DirEdgeList* seq);
00174
00183 DirEdgeList* reverse(DirEdgeList& seq);
00184
00192 bool hasSequence(planargraph::Subgraph& graph);
00193
00194 public:
00195
00196 static geom::Geometry* sequence(const geom::Geometry& geom)
00197 {
00198 LineSequencer sequencer;
00199 sequencer.add(geom);
00200 return sequencer.getSequencedLineStrings();
00201 }
00202
00203 LineSequencer()
00204 :
00205 factory(0),
00206 lineCount(0),
00207 isRun(false),
00208 sequencedGeometry(0),
00209 isSequenceableVar(false)
00210 {}
00211
00222 static bool isSequenced(const geom::Geometry* geom);
00223
00230 bool isSequenceable() {
00231 computeSequence();
00232 return isSequenceableVar;
00233 }
00234
00243 void add(const geom::Geometry& geometry) {
00244 geometry.applyComponentFilter(*this);
00245 }
00246
00247 template <class TargetContainer>
00248 void add(TargetContainer& geoms)
00249 {
00250 for (typename TargetContainer::const_iterator i = geoms.begin(),
00251 e = geoms.end(); i != e; ++i)
00252 {
00253 const geom::Geometry* g = *i;
00254 add(*g);
00255 }
00256 }
00257
00262 void filter(const geom::Geometry* g)
00263 {
00264 if (const geom::LineString *ls=dynamic_cast<const geom::LineString *>(g))
00265 {
00266 addLine(ls);
00267 }
00268 }
00269
00279 geom::Geometry*
00280 getSequencedLineStrings(bool release=1) {
00281 computeSequence();
00282 if (release) return sequencedGeometry.release();
00283 else return sequencedGeometry.get();
00284 }
00285 };
00286
00287 }
00288 }
00289 }
00290
00291 #ifdef _MSC_VER
00292 #pragma warning(pop)
00293 #endif
00294
00295 #endif // GEOS_OP_LINEMERGE_LINESEQUENCER_H