LandRTools.hpp
Go to the documentation of this file.
1 /*
2 
3  This file is part of OpenFLUID software
4  Copyright(c) 2007, INRA - Montpellier SupAgro
5 
6 
7  == GNU General Public License Usage ==
8 
9  OpenFLUID is free software: you can redistribute it and/or modify
10  it under the terms of the GNU General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  (at your option) any later version.
13 
14  OpenFLUID is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with OpenFLUID. If not, see <http://www.gnu.org/licenses/>.
21 
22 
23  == Other Usage ==
24 
25  Other Usage means a use of OpenFLUID that is inconsistent with the GPL
26  license, and requires a written agreement between You and INRA.
27  Licensees for Other Usage of OpenFLUID may use this file in accordance
28  with the terms contained in the written agreement between You and INRA.
29 
30 */
31 
32 /**
33  @file LandRTools.hpp
34 
35  @author Aline LIBRES <aline.libres@gmail.com>
36  @author Michael RABOTIN <michael.rabotin@supagro.inra.fr>
37  */
38 
39 #ifndef __OPENFLUID_LANDR_LANDRTOOLS_HPP__
40 #define __OPENFLUID_LANDR_LANDRTOOLS_HPP__
41 
42 #include <vector>
43 #include <list>
44 
45 #include <geos/geom/CoordinateArraySequenceFactory.h>
46 
48 #include <openfluid/dllexport.hpp>
49 
50 
51 namespace geos { namespace geom {
52 class Geometry;
53 class LineString;
54 class Polygon;
55 } }
56 
57 namespace openfluid { namespace landr {
58 
59 class VectorDataset;
60 
61 /**
62  @brief Set of tools to manage LandR elements.
63 */
65 {
66  public:
67 
69  {
70  NONE, INTERSECTS, CONTAINS, EQUALS, TOUCHES
71  };
72 
73  /**
74  @brief Returns a geos::geom::LineString representing the linearized input geos::geom::Geometry.
75  @param Geom The geos::geom::Geometry to linearize.
76  @return A new allocated geos::geom::LineString representing the linearized input geos::geom::Geometry,
77  or 0 if the geos::geom::Geometry cannot be linearized into a single geos::geom::LineString.
78  */
79  static geos::geom::LineString* computeMergedLineStringFromGeometry(geos::geom::Geometry* Geom);
80 
81  /**
82  @brief Returns a vector of geos::geom::LineString representing the linearized input geos::geom::Geometry.
83  @param Geom The geos::geom::Geometry to linearize.
84  @return A new allocated vector of geos::geom::LineString
85  representing the maximal linearized input geos::geom::Geometry,
86  or 0 if the geos::geom::Geometry is not \"Line\" typed.
87  */
88  static std::vector<geos::geom::LineString*>* computeMergedLineStringsFromGeometry(geos::geom::Geometry* Geom);
89 
90  /**
91  @brief Returns all exterior rings of the polygon-typed VectorDataset.
92  @param Val A VectorDataset of polygons.
93  @return A vector of new allocated geos::geom::LineString representing exterior rings.
94  @throw openfluid::base::FrameworkException if the VectorDataset is not polygon-typed.
95  */
96  static std::vector<geos::geom::LineString*> computeVectorOfExteriorRings(openfluid::landr::VectorDataset& Val);
97 
98  /**
99  @brief Returns all geos::geom::LineString composing of the linestring-typed VectorDataset.
100  @param Val A VectorDataset of linestrings.
101  @return A vector of new allocated geos::geom::Geometry representing lines.
102  @throw base::FrameworkException if the VectorDataset is not linestring-typed.
103  */
104  static std::vector<geos::geom::LineString*> computeVectorOfLines(openfluid::landr::VectorDataset& Val);
105 
106  /**
107  @brief Gets all full noded geos::geom::LineString from intersection between geom1 and geom2, with snap tolerance.
108  @param Geom1 The geos::geom::Geometry to node with Geom2.
109  @param Geom2 The other geos::geom::Geometry.
110  @param SnapTolerance The tolerance to use while computing intersections and equality of lines.
111  @param PrecisionReducer The PrecisionModel value for reducing
112  coordinates precision, default is 10000000 (7 digits).
113  @return A vector of geos::geom::LineString, representing all input lines, cut at each node.
114  */
115  static std::vector<geos::geom::LineString*>* computeNodedLines(geos::geom::Geometry* Geom1,
116  geos::geom::Geometry* Geom2,
117  double SnapTolerance = 0,
118  double PrecisionReducer=10000000);
119 
120  /**
121  @brief Same as from geos::operation::overlay::snap::SnapOverlayOp::Union(),
122  but with ability to use the wished snap tolerance value.
123  @param Geom1 The geos::geom::Geometry to join with Geom2.
124  @param Geom2 The other geos::geom::Geometry.
125  @param SnapTolerance The tolerance to use, default is 0.
126  @return A new geos::geom::Geometry representing the union of Geom1 and Geom2 according to SnapTolerance value.
127  */
128  static geos::geom::Geometry* computeSnapOverlayUnion(geos::geom::Geometry& Geom1,
129  geos::geom::Geometry& Geom2,
130  double SnapTolerance = 0);
131 
132  /**
133  @brief Returns true if a geos::geom::LineString is exactly equals
134  of an element of a list of geos::geom::LineString, up to a specified tolerance.
135  @param Line The geos::geom::LineString to compare.
136  @param RefLines The list of geos::geom::LineString to compare to.
137  @param Tolerance The tolerance to use.
138  */
139  static bool exists(geos::geom::LineString* Line,
140  std::list<geos::geom::LineString*> RefLines,
141  double Tolerance = 0);
142 
143  /**
144  @brief Creates all possible geos::geom::Polygon from a geos::geom::Geometry.
145  @param Lines The input vector of geos::geom::Geometry to polygonize.
146  @param Polygons The output vector of newly created geos::geom::Polygon.
147  @param Dangles The output vector of dangle geos::geom::LineString.
148  */
149  static void polygonizeGeometry(std::vector<geos::geom::Geometry*>& Lines,
150  std::vector<geos::geom::Polygon*>& Polygons,
151  std::vector<const geos::geom::LineString*>& Dangles);
152 
153  /**
154  @brief Recursive depth first search algorithm in a LineStringGraph and mark visited Nodes
155  @param Node the begin geos::planargraph::Node of LineStringGraph
156  */
157  static void markVisitedNodesUsingDFS(geos::planargraph::Node* Node);
158 
159  /**
160  @brief Intersection of two geos::geom::Geometry of Polygons.
161  @param Geom1 The geos::geom::Geometry to join with Geom2.
162  @param Geom2 The other geos::geom::Geometry.
163  @return A vector of geos::geom::Polygon representing the intersection of Geom1 and Geom2.
164  */
165  static std::vector<geos::geom::Polygon*> computeIntersectPolygons(geos::geom::Geometry* Geom1,
166  geos::geom::Geometry* Geom2);
167 
168  /**
169  @brief Splits a geos::geom::LineString by a geos::geom::Point.
170  @param Entity An existent geos::geom::LineString.
171  @param Point A geos::geom::Point.
172  @param SnapTolerance The threshold distance used to find Point on Line.
173  @return a vector of geos::geom::LineString,
174  or empty vector if splitting operation is null.
175  */
176  static std::vector<geos::geom::LineString*> splitLineStringByPoint(geos::geom::LineString& Entity,
177  geos::geom::Point& Point,
178  double SnapTolerance);
179 
180  /**
181  @brief Recursively split operation on a geos::geom::LineString by a vector of geos::geom::Point.
182  @param Entity An existent geos::geom::LineString.
183  @param Points A vector of geos::geom::Point.
184  @param SnapTolerance The threshold distance used to find Point on Line.
185  @param vLines the resulting vector of geos::geom::LineString splitted.
186  @param step iterator of the vector of Point; default is 0.
187  */
188  static void splitLineStringByPoints(geos::geom::LineString& Entity,
189  std::vector<geos::geom::Point*>& Points,
190  double SnapTolerance,
191  std::vector<geos::geom::LineString*>& vLines,
192  unsigned int step=0);
193 
194  /**
195  @brief Clean a vector of geos::geom::LineString (break at each intersection and remove duplicate geometry)
196  @param vLines An existent vector of geos::geom::LineString.
197  @param SnapTolerance The tolerance to use.
198  @return a vector of geos::geom::LineString.
199  */
200  static std::vector<geos::geom::LineString*>* cleanLineStrings(std::vector<geos::geom::LineString*> vLines,
201  double SnapTolerance);
202 
203  /**
204  @brief Returns the nodes of a vector of geos::geom::LineString.
205  @param NodedLines A vector of geos::geom::LineString.
206  @return A vector of geos::geom::Point.
207  */
208  static std::vector<geos::geom::Point*> computeNodesFromVectorOfLines(
209  std::vector<geos::geom::LineString*>& NodedLines);
210 
211  /**
212  @brief Returns the inverted openfluid::landr::LineStringEntity of a geos::planargraph using a recursive method.
213  @param Node A geos::planargraph::node of a geos::planargraph.
214  @param vectIdent A vector which will contain the identifier of each inverted openfluid::landr::LinestringEntity.
215  */
216  static void markInvertedLineStringEntityUsingDFS(geos::planargraph::Node* Node,std::vector<int>& vectIdent);
217 
218  /**
219  @brief Returns true if the OGREnvelope intersect, false otherwise
220  */
221  static bool isExtentsIntersect(std::vector<OGREnvelope> vEnvelope);
222 
223 
224 };
225 
226 
227 } } // namespaces
228 
229 
230 #endif /* __OPENFLUID_LANDR_LANDRTOOLS_HPP__ */
Interface for managing Vector Data format.
Definition: VectorDataset.hpp:64
Definition: LandREntity.hpp:53
Relationship
Definition: LandRTools.hpp:68
Definition: ApplicationException.hpp:47
#define OPENFLUID_API
Definition: dllexport.hpp:87
Set of tools to manage LandR elements.
Definition: LandRTools.hpp:64