LineStringGraph.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 LineStringGraph.hpp
34 
35  @author Aline LIBRES <aline.libres@gmail.com>
36  @author Michael RABOTIN <michael.rabotin@supagro.inra.fr>
37  */
38 
39 
40 #ifndef __OPENFLUID_LANDR_LINESTRINGGRAPH_HPP__
41 #define __OPENFLUID_LANDR_LINESTRINGGRAPH_HPP__
42 
43 
46 #include <openfluid/dllexport.hpp>
47 
48 
49 // =====================================================================
50 // =====================================================================
51 
52 
53 /**
54  Macro for declaration of a loop processing all entities of a graph
55  @param[in] loopid ID of the loop
56 */
57 #define DECLARE_ENTITIES_GRAPH_LOOP(loopid) \
58  std::list<openfluid::landr::LandREntity*>::iterator _M_##loopid##_it;\
59  std::list<openfluid::landr::LandREntity*> _M_##loopid##_uvect; \
60 
61 
62 /**
63  Macro for declaration of a loop processing all entities of a graph, following their OFLD_ID
64  @param[in] loopid ID of the loop
65 */
66 #define DECLARE_ENTITIES_ORDERED_LOOP(loopid) \
67  std::list<openfluid::landr::LandREntity*>::iterator _M_##loopid##_it;\
68  std::list<openfluid::landr::LandREntity*> _M_##loopid##_uvect; \
69 
70 /**
71  Macro for the beginning of a loop processing all entities of a graph
72  @param[in] loopid ID of the loop, must match declaration
73  @param[in] graph pointer to a openfluid::landr::LineStringGraph
74  @param[out] entity pointer to a openfluid::landr::LineStringEntity object, pointing to the current processed entity
75 */
76 #define BEGIN_ENTITIES_GRAPH_LOOP(loopid,graph,entity) \
77  if (graph) \
78  { \
79  _M_##loopid##_uvect = graph->getEntities();\
80  for (_M_##loopid##_it=_M_##loopid##_uvect.begin();\
81  _M_##loopid##_it != _M_##loopid##_uvect.end(); ++_M_##loopid##_it) \
82  { \
83  entity = dynamic_cast<openfluid::landr::LineStringEntity*>(*_M_##loopid##_it); \
84 
85 /**
86  Macro for the beginning of a loop processing all entities of a graph, following their OFLD_ID
87  @param[in] loopid ID of the loop, must match declaration
88  @param[in] graph pointer to a openfluid::landr::LineStringGraph
89  @param[out] entity pointer to a openfluid::landr::LineStringEntity object, pointing to the current processed entity
90 */
91 #define BEGIN_ENTITIES_ORDERED_LOOP(loopid,graph,entity) \
92  if (graph) \
93  { \
94  _M_##loopid##_uvect = graph->getOfldIdOrderedEntities();\
95  for (_M_##loopid##_it=_M_##loopid##_uvect.begin();\
96  _M_##loopid##_it != _M_##loopid##_uvect.end(); ++_M_##loopid##_it) \
97  { \
98  entity = dynamic_cast<openfluid::landr::LineStringEntity*>(*_M_##loopid##_it); \
99 
100 /**
101  Macro for the ending of a loop
102 */
103 #define END_LOOP \
104  } \
105  }
106 
107 
108 // =====================================================================
109 // =====================================================================
110 
111 
112 namespace openfluid { namespace landr {
113 
114 
115 class VectorDataset;
116 
117 /**
118  @brief A LandRGraph composed of LineStringEntities.
119 */
121 {
122  private:
123 
125 
126 
127  protected:
128 
129  LineStringGraph();
130 
131  /**
132  @brief Creates a new LineStringGraph initialized from a core::GeoVectorValue.
133  */
135 
136  /**
137  @brief Creates a new LineStringGraph initialized from a VectorDataset.
138  */
140 
141  /**
142  @brief Adds a LandREntity into this LineStringGraph.
143  */
144  virtual void addEntity(LandREntity* Entity);
145 
146  /**
147  @brief Creates a new LineStringEntity.
148  @param Geom The geos::geom::Geometry of the new LineStringEntity to create.
149  @param OfldId The identifier of the new LineStringEntity.
150  @return A new LandREntity.
151  */
152  virtual LandREntity* createNewEntity(const geos::geom::Geometry* Geom, unsigned int OfldId);
153 
154 
155  public:
156 
157  /**
158  @brief Creates a new LineStringGraph initialized from a core::GeoVectorValue.
159  @param Val A core::GeoVectorValue which must be composed of one or many LineStrings,
160  and each of them must contain a "OFLD_ID" attribute.
161  */
163 
164  /**
165  @brief Creates a new LineStringGraph initialized from a VectorDataset.
166  @param Vect A VectorDataset which must be composed of one or many LineStrings,
167  and each of them must contain a "OFLD_ID" attribute.
168  */
169  static LineStringGraph* create(openfluid::landr::VectorDataset& Vect);
170 
171  /**
172  @brief Creates a new LineStringGraph initialized with a list of LandREntity.
173  @param Entities A list of LandREntity which must be LineStringEntity.
174  */
175  static LineStringGraph* create(const LandRGraph::Entities_t& Entities);
176 
177  virtual ~LineStringGraph();
178 
179  /**
180  @brief Returns the type of graph.
181  */
182  LandRGraph::GraphType getType();
183 
184  /**
185  @brief Returns a LineStringEntity with OFLD_ID, or 0 if it doesn't exist.
186  */
187  LineStringEntity* entity(int OfldId);
188 
189  /**
190  @brief Removes from this LineStringGraph the LineStringEntity with OFLD_ID and its associated nodes.
191  @param OfldId The identifier.
192  */
193  virtual void removeEntity(int OfldId);
194 
195  /**
196  @brief Returns the last LineStringEntity of this LineStringGraph, according to the LineStringEntity orientations,
197  ie the one that has no down neighbour.
198  @return The last LineStringEntity or 0 if there is zero or more than one LineStringEntity whith no down neighbour.
199  */
200  LineStringEntity* lastLineStringEntity();
201 
202  /**
203  @brief Returns a vector of LineStringEntity that have no down neighbour,
204  according to the LineStringEntity orientations.
205  */
206  std::vector<LineStringEntity*> getEndLineStringEntities();
207 
208  /**
209  @brief Returns a vector of LineStringEntity that have no up neighbour,
210  according to the LineStringEntity orientations.
211  */
212  std::vector<LineStringEntity*> getStartLineStringEntities();
213 
214  /**
215  @brief Fetch the associated raster value corresponding to the LineStringEntity StartNode coordinate.
216  @param Entity The LineStringEntity to get the StartNode coordinate from.
217  @return The raster value corresponding to the LineStringEntity StartNode coordinate.
218  */
219  double getRasterValueForEntityStartNode(LineStringEntity& Entity);
220 
221  /**
222  @brief Fetch the associated raster value corresponding to the LineStringEntity EndNode coordinate.
223  @param Entity The LineStringEntity to get the EndNode coordinate from.
224  @return The raster value corresponding to the LineStringEntity EndNode coordinate.
225  */
226  double getRasterValueForEntityEndNode(LineStringEntity& Entity);
227 
228  /**
229  @brief Creates a new attribute for these LineStringGraph entities, and set for each LineStringEntity
230  this attribute value as the associated raster values corresponding to the StartNode LineStringEntity coordinates.
231  @param AttributeName The name of the attribute to create for the StartNode
232  */
233  void setAttributeFromRasterValueAtStartNode(const std::string& AttributeName);
234 
235  /**
236  @brief Creates a new attribute for these LineStringGraph entities, and set for each LineStringEntity
237  this attribute value as the associated raster values corresponding to the EndNode LineStringEntity coordinates.
238  @param AttributeName The name of the attribute to create for the EndNode
239  */
240  void setAttributeFromRasterValueAtEndNode(const std::string& AttributeName);
241 
242  /**
243  @brief Reverse a LineStringEntity orientation.
244  @param Entity The LineStringEntity to reverse.
245  */
246  void reverseLineStringEntity(LineStringEntity& Entity);
247 
248  /**
249  @brief Returns true if this LineStringGraph is an arborescence, false otherwise.
250  @details An arborescence is a graph with no loop; edges can be well directed or not.
251  */
252  bool isLineStringGraphArborescence();
253 
254  /**
255  @brief Creates a new attribute for this LineStringGraph entities, and set for each LineStringEntity
256  this attribute value as the mean of the StartNode altitude and the EndNode altitude.
257  @param AttributeName The name of the attribute to create.
258  */
259  virtual void setAttributeFromMeanRasterValues(const std::string& AttributeName);
260 
261  /**
262  @brief Merges a LineStringEntity into an other one.
263  @details The LineStringEntity to merge is deleted.
264  @param Entity An existent LineStringEntity.
265  @param EntityToMerge The LineStringEntity which will be merged into Entity and will be deleted.
266  */
267  void mergeLineStringEntities(LineStringEntity& Entity, LineStringEntity& EntityToMerge);
268 
269  /**
270  @brief Gets a map of small LineStringEntity under length threshold
271  @param MinLength The length threshold (in map units).
272  @param rmDangle : if true, get also dangles under the threshold.
273  @param HighDegree : if true, do not get the if StartNode and EndNode of this LineStringEntitiy are Degree>=3.
274  @return a multimap of LineStringEntity with key is the length of each LineStringEntity.
275  */
276  std::multimap<double,LineStringEntity*> getLineStringEntitiesByMinLength(double MinLength,
277  bool rmDangle=true,
278  bool HighDegree=true);
279 
280  /**
281  @brief Set the orientation of the LineStringGraph with outlet identification by OFLD_ID identifier.
282  Only for LineStringGraph of arborescence type
283  @param OfldId The identifier of the outlet.
284  */
285  void setOrientationByOfldId(int OfldId);
286 
287  /**
288  @brief Merges the entities of this LineStringGraph under length threshold.
289  @param MinLength The length threshold (in map units).
290  @param rmDangle if true, remove also dangles under the threshold, default is true.
291  */
292  void mergeLineStringEntitiesByMinLength(double MinLength,bool rmDangle=true);
293 
294 };
295 
296 
297 } } // namespaces
298 
299 
300 #endif /* __OPENFLUID_LANDR_LINESTRINGGRAPH_HPP__ */
GraphType
Definition: LandRGraph.hpp:87
std::list< LandREntity * > Entities_t
Definition: LandRGraph.hpp:92
#define OPENFLUID_API
Definition: dllexport.hpp:87
A LandRGraph composed of LineStringEntities.
Definition: LineStringGraph.hpp:120
Definition: ApplicationException.hpp:47
Interface for managing Vector Data format.
Definition: VectorDataset.hpp:64
Interface for a graph composed of LandREntity.
Definition: LandRGraph.hpp:83
A LandREntity representing a geos::geom::LineString.
Definition: LineStringEntity.hpp:60
Interface for a landscape representation element.
Definition: LandREntity.hpp:69
Definition: GeoVectorValue.hpp:55