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