00001 /* 00002 00003 This file is part of OpenFLUID software 00004 Copyright(c) 2007, INRA - Montpellier SupAgro 00005 00006 00007 == GNU General Public License Usage == 00008 00009 OpenFLUID is free software: you can redistribute it and/or modify 00010 it under the terms of the GNU General Public License as published by 00011 the Free Software Foundation, either version 3 of the License, or 00012 (at your option) any later version. 00013 00014 OpenFLUID is distributed in the hope that it will be useful, 00015 but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 GNU General Public License for more details. 00018 00019 You should have received a copy of the GNU General Public License 00020 along with OpenFLUID. If not, see <http://www.gnu.org/licenses/>. 00021 00022 00023 == Other Usage == 00024 00025 Other Usage means a use of OpenFLUID that is inconsistent with the GPL 00026 license, and requires a written agreement between You and INRA. 00027 Licensees for Other Usage of OpenFLUID may use this file in accordance 00028 with the terms contained in the written agreement between You and INRA. 00029 00030 */ 00031 00032 /** 00033 \file LandRTools.hpp 00034 \brief Header of ... 00035 00036 \author Aline LIBRES <aline.libres@gmail.com> 00037 */ 00038 00039 #ifndef LANDRTOOLS_HPP_ 00040 #define LANDRTOOLS_HPP_ 00041 00042 #include <vector> 00043 #include <list> 00044 #include <openfluid/landr/LineStringGraph.hpp> 00045 #include <openfluid/dllexport.hpp> 00046 #include <geos/geom/CoordinateArraySequenceFactory.h> 00047 00048 namespace geos { namespace geom { 00049 class Geometry; 00050 class LineString; 00051 class Polygon; 00052 } } 00053 00054 namespace openfluid { namespace landr { 00055 00056 class VectorDataset; 00057 00058 /** 00059 @brief Set of tools to manage LandR elements. 00060 */ 00061 class DLLEXPORT LandRTools 00062 { 00063 public: 00064 00065 enum Relationship 00066 { 00067 NONE, INTERSECTS, CONTAINS, EQUALS, TOUCHES 00068 }; 00069 00070 /** 00071 @brief Returns a geos::geom::LineString representing the linearized input geos::geom::Geometry. 00072 @param Geom The geos::geom::Geometry to linearize. 00073 @return A new allocated geos::geom::LineString representing the linearized input geos::geom::Geometry, 00074 or 0 if the geos::geom::Geometry cannot be linearized into a single geos::geom::LineString. 00075 */ 00076 static geos::geom::LineString* getMergedLineStringFromGeometry(geos::geom::Geometry* Geom); 00077 00078 /** 00079 @brief Returns a vector of geos::geom::LineString representing the linearized input geos::geom::Geometry. 00080 @param Geom The geos::geom::Geometry to linearize. 00081 @return A new allocated vector of geos::geom::LineString representing the maximal linearized input geos::geom::Geometry, 00082 or 0 if the geos::geom::Geometry is not \"Line\" typed. 00083 */ 00084 static std::vector<geos::geom::LineString*>* getMergedLineStringsFromGeometry(geos::geom::Geometry* Geom); 00085 00086 /** 00087 @brief Returns all exterior rings of the polygon-typed VectorDataset. 00088 @param Val A VectorDataset of polygons. 00089 @return A vector of new allocated geos::geom::LineString representing exterior rings. 00090 @throw base::OFException if the VectorDataset is not polygon-typed. 00091 */ 00092 static std::vector<geos::geom::LineString*> getVectorOfExteriorRings(openfluid::landr::VectorDataset& Val); 00093 00094 /** 00095 @brief Returns all geos::geom::LineString composing of the linestring-typed VectorDataset. 00096 @param Val A VectorDataset of linestrings. 00097 @return A vector of new allocated geos::geom::Geometry representing lines. 00098 @throw base::OFException if the VectorDataset is not linestring-typed. 00099 */ 00100 static std::vector<geos::geom::LineString*> getVectorOfLines(openfluid::landr::VectorDataset& Val); 00101 00102 /** 00103 @brief Gets all full noded geos::geom::LineString from intersection between geom1 and geom2, with snap tolerance. 00104 @param Geom1 The geos::geom::Geometry to node with Geom2. 00105 @param Geom2 The other geos::geom::Geometry. 00106 @param SnapTolerance The tolerance to use while computing intersections and equality of lines. 00107 @param PrecisionReducer The PrecisionModel value for reducing coordinates precision, default is 10000000 (7 digits). 00108 @return A vector of geos::geom::LineString, representing all input lines, cut at each node. 00109 */ 00110 static std::vector<geos::geom::LineString*>* getNodedLines(geos::geom::Geometry* Geom1, 00111 geos::geom::Geometry* Geom2, 00112 double SnapTolerance = 0, 00113 double PrecisionReducer=10000000); 00114 00115 /** 00116 @brief Same as from geos::operation::overlay::snap::SnapOverlayOp::Union(), 00117 but with ability to use the wished snap tolerance value. 00118 @param Geom1 The geos::geom::Geometry to join with Geom2. 00119 @param Geom2 The other geos::geom::Geometry. 00120 @param SnapTolerance The tolerance to use, default is 0. 00121 @return A new geos::geom::Geometry representing the union of Geom1 and Geom2 according to SnapTolerance value. 00122 */ 00123 static geos::geom::Geometry* computeSnapOverlayUnion(geos::geom::Geometry& Geom1, 00124 geos::geom::Geometry& Geom2, 00125 double SnapTolerance = 0); 00126 00127 00128 /** 00129 @brief Returns true if a geos::geom::LineString is exactly equals of an element of a list of geos::geom::LineString, up to a specified tolerance. 00130 @param Line The geos::geom::LineString to compare. 00131 @param RefLines The list of geos::geom::LineString to compare to. 00132 @param Tolerance The tolerance to use. 00133 */ 00134 static bool exists(geos::geom::LineString* Line, 00135 std::list<geos::geom::LineString*> RefLines, 00136 double Tolerance = 0); 00137 00138 /** 00139 @brief Creates all possible geos::geom::Polygon from a geos::geom::Geometry. 00140 @param Lines The input vector of geos::geom::Geometry to polygonize. 00141 @param Polygons The output vector of newly created geos::geom::Polygon. 00142 @param Dangles The output vector of dangle geos::geom::LineString. 00143 */ 00144 static void polygonizeGeometry(std::vector<geos::geom::Geometry*>& Lines, 00145 std::vector<geos::geom::Polygon*>& Polygons, 00146 std::vector<const geos::geom::LineString*>& Dangles); 00147 00148 /** 00149 @brief Recursive depth first search algorithm in a LineStringGraph and mark visited Nodes 00150 @param Node the begin geos::planargraph::Node of LineStringGraph 00151 */ 00152 static void markVisitedNodesUsingDFS(geos::planargraph::Node* Node); 00153 00154 /** 00155 @brief Intersection of two geos::geom::Geometry of Polygons. 00156 @param Geom1 The geos::geom::Geometry to join with Geom2. 00157 @param Geom2 The other geos::geom::Geometry. 00158 @return A vector of geos::geom::Polygon representing the intersection of Geom1 and Geom2. 00159 */ 00160 static std::vector<geos::geom::Polygon*> computeIntersectPolygons(geos::geom::Geometry* Geom1, 00161 geos::geom::Geometry* Geom2); 00162 00163 00164 /** 00165 @brief Splits a geos::geom::LineString by a geos::geom::Point. 00166 @param Entity An existent geos::geom::LineString. 00167 @param Point A geos::geom::Point. 00168 @param SnapTolerance The threshold distance used to find Point on Line. 00169 @return a vector of geos::geom::LineString, 00170 * or empty vector if splitting operation is null. 00171 */ 00172 static std::vector<geos::geom::LineString*> splitLineStringByPoint(geos::geom::LineString& Entity, 00173 geos::geom::Point& Point, 00174 double SnapTolerance); 00175 00176 00177 /** 00178 @brief Recursively split operation on a geos::geom::LineString by a vector of geos::geom::Point. 00179 @param Entity An existent geos::geom::LineString. 00180 @param Points A vector of geos::geom::Point. 00181 @param SnapTolerance The threshold distance used to find Point on Line. 00182 @param vLines the resulting vector of geos::geom::LineString splitted. 00183 @param step iterator of the vector of Point; default is 0. 00184 */ 00185 static void splitLineStringByPoints(geos::geom::LineString& Entity, 00186 std::vector<geos::geom::Point*>& Points, 00187 double SnapTolerance, 00188 std::vector<geos::geom::LineString*>& vLines, 00189 unsigned int step=0); 00190 00191 /** 00192 @brief Clean a vector of geos::geom::LineString (break at each intersection and remove duplicate geometry) 00193 @param vLines An existent vector of geos::geom::LineString. 00194 @param SnapTolerance The tolerance to use. 00195 @return a vector of geos::geom::LineString. 00196 */ 00197 static std::vector<geos::geom::LineString*>* cleanLineStrings(std::vector<geos::geom::LineString*> vLines, 00198 double SnapTolerance); 00199 00200 /** 00201 @brief Returns the nodes of a vector of geos::geom::LineString. 00202 @param NodedLines A vector of geos::geom::LineString. 00203 @return A vector of geos::geom::Point. 00204 */ 00205 static std::vector<geos::geom::Point*> getNodesFromVectorOfLines(std::vector<geos::geom::LineString*>& NodedLines); 00206 00207 /** 00208 @brief Returns the inverted openfluid::landr::LineStringEntity of a geos::planargraph using a recursive method. 00209 @param Node A geos::planargraph::node of a geos::planargraph. 00210 @param vectIdent A vector which will contain the identifier of each inverted openfluid::landr::LinestringEntity. 00211 */ 00212 static void markInvertedLineStringEntityUsingDFS(geos::planargraph::Node* Node,std::vector<int>& vectIdent); 00213 00214 00215 }; 00216 00217 } } // namespace openfluid, landr 00218 #endif /* LANDRTOOLS_HPP_ */