1 /********************************************************************** 2 * 3 * GEOS - Geometry Engine Open Source 4 * http://geos.osgeo.org 5 * 6 * Copyright (C) 2006 Refractions Research Inc. 7 * 8 * This is free software; you can redistribute and/or modify it under 9 * the terms of the GNU Lesser General Public Licence as published 10 * by the Free Software Foundation. 11 * See the COPYING file for more information. 12 * 13 ********************************************************************** 14 * 15 * Last port: operation/linemerge/LineMerger.java r378 (JTS-1.12) 16 * 17 **********************************************************************/ 18 19 #ifndef GEOS_OP_LINEMERGE_LINEMERGER_H 20 #define GEOS_OP_LINEMERGE_LINEMERGER_H 21 22 #include <geos/export.h> 23 #include <geos/geom/LineString.h> 24 #include <geos/operation/linemerge/LineMergeGraph.h> // for composition 25 26 #include <memory> 27 #include <vector> 28 29 #ifdef _MSC_VER 30 #pragma warning(push) 31 #pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class 32 #endif 33 34 // Forward declarations 35 namespace geos { 36 namespace geom { 37 class GeometryFactory; 38 class Geometry; 39 } 40 namespace planargraph { 41 class Node; 42 } 43 namespace operation { 44 namespace linemerge { 45 class EdgeString; 46 class LineMergeDirectedEdge; 47 } 48 } 49 } 50 51 52 namespace geos { 53 namespace operation { // geos::operation 54 namespace linemerge { // geos::operation::linemerge 55 56 /** 57 * 58 * \brief 59 * Sews together a set of fully noded LineStrings. 60 * 61 * Sewing stops at nodes of degree 1 or 3 or more. 62 * The exception is an isolated loop, which only has degree-2 nodes, 63 * in which case a node is simply chosen as a starting point. 64 * The direction of each merged LineString will be that of the majority 65 * of the LineStrings from which it was derived. 66 * 67 * Any dimension of Geometry is handled. 68 * The constituent linework is extracted to form the edges. 69 * The edges must be correctly noded; that is, they must only meet 70 * at their endpoints. 71 * 72 * The LineMerger will still run on incorrectly noded input 73 * but will not form polygons from incorrected noded edges. 74 * 75 */ 76 class GEOS_DLL LineMerger { 77 78 private: 79 80 LineMergeGraph graph; 81 82 std::vector<std::unique_ptr<geom::LineString>> mergedLineStrings; 83 84 std::vector<EdgeString*> edgeStrings; 85 86 const geom::GeometryFactory* factory; 87 88 void merge(); 89 90 void buildEdgeStringsForObviousStartNodes(); 91 92 void buildEdgeStringsForIsolatedLoops(); 93 94 void buildEdgeStringsForUnprocessedNodes(); 95 96 void buildEdgeStringsForNonDegree2Nodes(); 97 98 void buildEdgeStringsStartingAt(planargraph::Node* node); 99 100 EdgeString* buildEdgeStringStartingWith(LineMergeDirectedEdge* start); 101 102 public: 103 LineMerger(); 104 ~LineMerger(); 105 106 /** 107 * \brief 108 * Adds a collection of Geometries to be processed. 109 * May be called multiple times. 110 * 111 * Any dimension of Geometry may be added; the constituent 112 * linework will be extracted. 113 */ 114 void add(std::vector<const geom::Geometry*>* geometries); 115 116 /** 117 * \brief 118 * Adds a Geometry to be processed. 119 * May be called multiple times. 120 * 121 * Any dimension of Geometry may be added; the constituent 122 * linework will be extracted. 123 */ 124 void add(const geom::Geometry* geometry); 125 126 /** 127 * \brief 128 * Returns the LineStrings built by the merging process. 129 * 130 * Ownership of vector _and_ its elements to caller. 131 */ 132 std::vector<std::unique_ptr<geom::LineString>> getMergedLineStrings(); 133 134 void add(const geom::LineString* lineString); 135 136 // Declare type as noncopyable 137 LineMerger(const LineMerger& other) = delete; 138 LineMerger& operator=(const LineMerger& rhs) = delete; 139 }; 140 141 } // namespace geos::operation::linemerge 142 } // namespace geos::operation 143 } // namespace geos 144 145 #ifdef _MSC_VER 146 #pragma warning(pop) 147 #endif 148 149 #endif // GEOS_OP_LINEMERGE_LINEMERGER_H 150