All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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>
45 #include <openfluid/dllexport.hpp>
46 #include <geos/geom/CoordinateArraySequenceFactory.h>
47 
48 namespace geos { namespace geom {
49 class Geometry;
50 class LineString;
51 class Polygon;
52 } }
53 
54 namespace openfluid { namespace landr {
55 
56 class VectorDataset;
57 
58 /**
59  @brief Set of tools to manage LandR elements.
60 */
62 {
63  public:
64 
66  {
67  NONE, INTERSECTS, CONTAINS, EQUALS, TOUCHES
68  };
69 
70  /**
71  @brief Returns a geos::geom::LineString representing the linearized input geos::geom::Geometry.
72  @param Geom The geos::geom::Geometry to linearize.
73  @return A new allocated geos::geom::LineString representing the linearized input geos::geom::Geometry,
74  or 0 if the geos::geom::Geometry cannot be linearized into a single geos::geom::LineString.
75  */
76  static geos::geom::LineString* computeMergedLineStringFromGeometry(geos::geom::Geometry* Geom);
77 
78  /**
79  @brief Returns a vector of geos::geom::LineString representing the linearized input geos::geom::Geometry.
80  @param Geom The geos::geom::Geometry to linearize.
81  @return A new allocated vector of geos::geom::LineString
82  representing the maximal linearized input geos::geom::Geometry,
83  or 0 if the geos::geom::Geometry is not \"Line\" typed.
84  */
85  static std::vector<geos::geom::LineString*>* computeMergedLineStringsFromGeometry(geos::geom::Geometry* Geom);
86 
87  /**
88  @brief Returns all exterior rings of the polygon-typed VectorDataset.
89  @param Val A VectorDataset of polygons.
90  @return A vector of new allocated geos::geom::LineString representing exterior rings.
91  @throw openfluid::base::FrameworkException if the VectorDataset is not polygon-typed.
92  */
93  static std::vector<geos::geom::LineString*> computeVectorOfExteriorRings(openfluid::landr::VectorDataset& Val);
94 
95  /**
96  @brief Returns all geos::geom::LineString composing of the linestring-typed VectorDataset.
97  @param Val A VectorDataset of linestrings.
98  @return A vector of new allocated geos::geom::Geometry representing lines.
99  @throw base::FrameworkException if the VectorDataset is not linestring-typed.
100  */
101  static std::vector<geos::geom::LineString*> computeVectorOfLines(openfluid::landr::VectorDataset& Val);
102 
103  /**
104  @brief Gets all full noded geos::geom::LineString from intersection between geom1 and geom2, with snap tolerance.
105  @param Geom1 The geos::geom::Geometry to node with Geom2.
106  @param Geom2 The other geos::geom::Geometry.
107  @param SnapTolerance The tolerance to use while computing intersections and equality of lines.
108  @param PrecisionReducer The PrecisionModel value for reducing
109  coordinates precision, default is 10000000 (7 digits).
110  @return A vector of geos::geom::LineString, representing all input lines, cut at each node.
111  */
112  static std::vector<geos::geom::LineString*>* computeNodedLines(geos::geom::Geometry* Geom1,
113  geos::geom::Geometry* Geom2,
114  double SnapTolerance = 0,
115  double PrecisionReducer=10000000);
116 
117  /**
118  @brief Same as from geos::operation::overlay::snap::SnapOverlayOp::Union(),
119  but with ability to use the wished snap tolerance value.
120  @param Geom1 The geos::geom::Geometry to join with Geom2.
121  @param Geom2 The other geos::geom::Geometry.
122  @param SnapTolerance The tolerance to use, default is 0.
123  @return A new geos::geom::Geometry representing the union of Geom1 and Geom2 according to SnapTolerance value.
124  */
125  static geos::geom::Geometry* computeSnapOverlayUnion(geos::geom::Geometry& Geom1,
126  geos::geom::Geometry& Geom2,
127  double SnapTolerance = 0);
128 
129  /**
130  @brief Returns true if a geos::geom::LineString is exactly equals
131  of an element of a list of geos::geom::LineString, up to a specified tolerance.
132  @param Line The geos::geom::LineString to compare.
133  @param RefLines The list of geos::geom::LineString to compare to.
134  @param Tolerance The tolerance to use.
135  */
136  static bool exists(geos::geom::LineString* Line,
137  std::list<geos::geom::LineString*> RefLines,
138  double Tolerance = 0);
139 
140  /**
141  @brief Creates all possible geos::geom::Polygon from a geos::geom::Geometry.
142  @param Lines The input vector of geos::geom::Geometry to polygonize.
143  @param Polygons The output vector of newly created geos::geom::Polygon.
144  @param Dangles The output vector of dangle geos::geom::LineString.
145  */
146  static void polygonizeGeometry(std::vector<geos::geom::Geometry*>& Lines,
147  std::vector<geos::geom::Polygon*>& Polygons,
148  std::vector<const geos::geom::LineString*>& Dangles);
149 
150  /**
151  @brief Recursive depth first search algorithm in a LineStringGraph and mark visited Nodes
152  @param Node the begin geos::planargraph::Node of LineStringGraph
153  */
154  static void markVisitedNodesUsingDFS(geos::planargraph::Node* Node);
155 
156  /**
157  @brief Intersection of two geos::geom::Geometry of Polygons.
158  @param Geom1 The geos::geom::Geometry to join with Geom2.
159  @param Geom2 The other geos::geom::Geometry.
160  @return A vector of geos::geom::Polygon representing the intersection of Geom1 and Geom2.
161  */
162  static std::vector<geos::geom::Polygon*> computeIntersectPolygons(geos::geom::Geometry* Geom1,
163  geos::geom::Geometry* Geom2);
164 
165  /**
166  @brief Splits a geos::geom::LineString by a geos::geom::Point.
167  @param Entity An existent geos::geom::LineString.
168  @param Point A geos::geom::Point.
169  @param SnapTolerance The threshold distance used to find Point on Line.
170  @return a vector of geos::geom::LineString,
171  or empty vector if splitting operation is null.
172  */
173  static std::vector<geos::geom::LineString*> splitLineStringByPoint(geos::geom::LineString& Entity,
174  geos::geom::Point& Point,
175  double SnapTolerance);
176 
177  /**
178  @brief Recursively split operation on a geos::geom::LineString by a vector of geos::geom::Point.
179  @param Entity An existent geos::geom::LineString.
180  @param Points A vector of geos::geom::Point.
181  @param SnapTolerance The threshold distance used to find Point on Line.
182  @param vLines the resulting vector of geos::geom::LineString splitted.
183  @param step iterator of the vector of Point; default is 0.
184  */
185  static void splitLineStringByPoints(geos::geom::LineString& Entity,
186  std::vector<geos::geom::Point*>& Points,
187  double SnapTolerance,
188  std::vector<geos::geom::LineString*>& vLines,
189  unsigned int step=0);
190 
191  /**
192  @brief Clean a vector of geos::geom::LineString (break at each intersection and remove duplicate geometry)
193  @param vLines An existent vector of geos::geom::LineString.
194  @param SnapTolerance The tolerance to use.
195  @return a vector of geos::geom::LineString.
196  */
197  static std::vector<geos::geom::LineString*>* cleanLineStrings(std::vector<geos::geom::LineString*> vLines,
198  double SnapTolerance);
199 
200  /**
201  @brief Returns the nodes of a vector of geos::geom::LineString.
202  @param NodedLines A vector of geos::geom::LineString.
203  @return A vector of geos::geom::Point.
204  */
205  static std::vector<geos::geom::Point*> computeNodesFromVectorOfLines(
206  std::vector<geos::geom::LineString*>& NodedLines);
207 
208  /**
209  @brief Returns the inverted openfluid::landr::LineStringEntity of a geos::planargraph using a recursive method.
210  @param Node A geos::planargraph::node of a geos::planargraph.
211  @param vectIdent A vector which will contain the identifier of each inverted openfluid::landr::LinestringEntity.
212  */
213  static void markInvertedLineStringEntityUsingDFS(geos::planargraph::Node* Node,std::vector<int>& vectIdent);
214 
215  /**
216  @brief Returns true if the OGREnvelope intersect, false otherwise
217  */
218  static bool isExtentsIntersect(std::vector<OGREnvelope> vEnvelope);
219 
220 
221 };
222 
223 } } // namespace openfluid, landr
224 #endif /* __OPENFLUID_LANDR_LANDRTOOLS_HPP__ */
Interface for managing Vector Data format.
Definition: VectorDataset.hpp:64
Relationship
Definition: LandRTools.hpp:65
#define OPENFLUID_API
Definition: dllexport.hpp:87
Set of tools to manage LandR elements.
Definition: LandRTools.hpp:61