LandRGraph.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 LandRGraph.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_LANDRGRAPH_HPP__
40 #define __OPENFLUID_LANDR_LANDRGRAPH_HPP__
41 
42 
43 #include <list>
44 
45 #include <ogrsf_frmts.h>
46 
47 #include <geos/planargraph/PlanarGraph.h>
48 
49 #include <openfluid/dllexport.hpp>
50 
51 
52 namespace geos { namespace geom {
53 class Geometry;
54 class GeometryFactory;
55 class LineString;
56 class Polygon;
57 class Coordinate;
58 } }
59 
60 namespace planargraph {
61 class Node;
62 }
63 
64 namespace openfluid {
65 
66 namespace core {
67 class GeoVectorValue;
68 class GeoRasterValue;
69 }
70 
71 /**
72  @brief Classes for landscape representation management.
73 */
74 namespace landr {
75 
76 class LandREntity;
77 class VectorDataset;
78 class RasterDataset;
79 
80 /**
81  @brief Interface for a graph composed of LandREntity.
82 */
83 class OPENFLUID_API LandRGraph: public geos::planargraph::PlanarGraph
84 {
85  public:
86 
87  enum GraphType
88  {
89  POLYGON, LINESTRING
90  };
91 
92  typedef std::list<LandREntity*> Entities_t;
93 
94 
95  protected:
96  /**
97  @brief The VectorDataset associated to this LandRGraph.
98  */
100 
101  /**
102  @brief The geos::geom::GeometryFactory used to build this LandRGraph.
103  */
104  const geos::geom::GeometryFactory* mp_Factory;
105 
106  /**
107  @brief A map of the LandREntity of this LandRGraph and sorted by identifier.
108  */
109  std::map<int, LandREntity*> m_EntitiesByOfldId;
110 
111  /**
112  @brief A list of the LandREntity of this LandRGraph.
113  */
114  Entities_t m_Entities;
115 
116  /**
117  @brief The RasterDataset associated to this LandRGraph.
118  */
120 
121  /**
122  @brief The VectorDataset representation of the RasterDataset associated to this LandRGraph.
123  */
125 
126  /**
127  @brief A vector of geos::geom::Polygon representation of the RasterDataset associated to this LandRGraph.
128  */
129  std::vector<geos::geom::Polygon*>* mp_RasterPolygonizedPolys;
130 
131  static int m_FileNum;
132 
133  LandRGraph();
134 
135  /**
136  @brief Creates a new LandRGraph from a core::GeoVectorValue.
137  */
139 
140  /**
141  @brief Creates a new LandRGraph from a VectorDataset.
142  */
144 
145  /**
146  @brief Adds LandREntity from the associated VectorDataset of this LandRGraph.
147  */
148  void addEntitiesFromGeoVector();
149 
150  /**
151  @brief Adds LandREntity from a LandREntity list to this LandRGraph.
152  */
153  void addEntitiesFromEntityList(const LandRGraph::Entities_t& Entities);
154 
155  /**
156  @brief Adds a LandREntity to this LandRGraph.
157  @param Entity The LandREntity to add.
158  */
159  virtual void addEntity(LandREntity* Entity) = 0;
160 
161  /**
162  @brief Creates a new LandREntity.
163  @param Geom A geos::geom::Geometry.
164  @param OfldId The identifier of the new LandREntity.
165  */
166  virtual LandREntity* createNewEntity(const geos::geom::Geometry* Geom,
167  unsigned int OfldId) = 0;
168 
169  /**
170  @brief Returns a geos::planagraph::Node of this LandRGraph from a geos::geom::Coordinate.
171  @param Coordinate A geos::geom::Coordinate.
172  @return A geos::planargraph::Node.
173  */
174  geos::planargraph::Node* node(const geos::geom::Coordinate& Coordinate);
175 
176  public:
177 
178  /**
179  @attention Delete also associated RasterPolygonized if present.
180  */
181  virtual ~LandRGraph();
182 
183  /**
184  @brief Returns the type of graph.
185  */
186  virtual GraphType getType() = 0;
187 
188  /**
189  @brief Returns the LandREntity with OfldId, or 0 if it doesn't exist.
190  */
191  virtual LandREntity* entity(int OfldId);
192 
193  /**
194  @brief Returns a list of the LandREntity of this LandRGraph.
195  */
196  Entities_t getEntities();
197 
198  /**
199  @brief Returns a list of the LandREntity of this LandRGraph and sorted by identifier.
200  */
201  Entities_t getOfldIdOrderedEntities();
202 
203  /**
204  @brief Returns a map of the LandREntity of this LandRGraph and their identifiers.
205  */
206  std::map<int, LandREntity*> getEntitiesByOfldId();
207 
208  /**
209  @brief Gets the number of LandREntity in the LandRGraph.
210  */
211  unsigned int getSize() const;
212 
213  /**
214  @brief Removes from this LandRGraph the nodes of degree 0.
215  */
216  void removeUnusedNodes();
217 
218  /**
219  @brief Adds an attribute to this LandRGraph.
220  @details Doesn't reset if the AttributeName already exists.
221  @param AttributeName The name of the attribute.
222  */
223  void addAttribute(const std::string& AttributeName);
224 
225  /**
226  @brief Removes an attribute to this LandRGraph.
227  @details Does nothing if AttributeName doesn't exist.
228  @param AttributeName The name of the attribute.
229  */
230  void removeAttribute(const std::string& AttributeName);
231 
232  /**
233  @brief Returns a vector of the names of the attributes of this LandRGraph.
234  */
235  std::vector<std::string> getAttributeNames();
236 
237  /**
238  @brief Associates a core::GeoRasterValue to this LandRGraph.
239  @param Raster A core::GeoRasterValue.
240  @details Replace associated raster if exists.
241  */
242  void addAGeoRasterValue(openfluid::core::GeoRasterValue& Raster);
243 
244  /**
245  @brief Associates a RasterDataset to this LandRGraph.
246  @param Raster A RasterDataset.
247  @details Replace associated raster if exists.
248  */
249  void addAGeoRasterValue(const openfluid::landr::RasterDataset& Raster);
250 
251  /**
252  @brief Returns true if this LandRGraph has an associated raster, false otherwise.
253  */
254  bool hasAnAssociatedRaster();
255 
256  /**
257  @brief Transforms the associated raster value into an openfluid::landr::VectorDataset of polygons.
258  @return An openfluid::landr::VectorDataset of the created polygons.
259  */
260  openfluid::landr::VectorDataset* rasterPolygonized();
261 
262  /**
263  @brief Transforms the associated raster value into a vector of geos::geom::Polygon.
264  @return A vector of the created geos::geom::Polygon.
265  */
266  std::vector<geos::geom::Polygon*>* rasterPolygonizedPolys();
267 
268  /**
269  @brief Fetchs the associated raster value corresponding to the LandREntity centroid coordinate.
270  @param Entity The LandREntity to get the centroid coordinate from.
271  @return The raster value corresponding to the LandREntity centroid coordinate.
272  */
273  virtual double getRasterValueForEntityCentroid(const LandREntity& Entity);
274 
275  /**
276  @brief Creates a new attribute for all the LandREntity of this LandRGraph, and set for each LandREntity
277  this attribute value as the raster value corresponding to the LandREntity centroid coordinate.
278  @param AttributeName The name of the attribute to create.
279  */
280  void setAttributeFromRasterValueAtCentroid(const std::string& AttributeName);
281 
282  /**
283  @brief Creates a new attribute for all the LandREntity of this LandRGraph, and set for each LandREntity
284  this attribute value as a mean of the raster value.
285  @param AttributeName The name of the attribute to create.
286  */
287  virtual void setAttributeFromMeanRasterValues(const std::string& AttributeName)=0;
288 
289  /**
290  @brief Computes the LandREntity neighbours of each LandREntity of this LandRGraph, according to its type.
291  */
292  void computeNeighbours();
293 
294  /**
295  @brief Creates on disk a shapefile representing this LandRGraph.
296  @param FilePath The path where to create the out file.
297  @param FileName A name for the out file to create, with a .shp extension.
298  */
299  void exportToShp(const std::string& FilePath, const std::string& FileName);
300 
301  /**
302  @brief Creates a new attribute for all the LandREntity of this LandRGraph, and set for each LandREntity
303  this attribute value as the vector value corresponding to the entity ID number.
304  @param AttributeName The name of the attribute to create.
305  @param Vector The Name of the core::GeoVectorValue.
306  @param IdColumn The ID number column of the core::GeoVectorValue.
307  @param ValueColumn The column of the core::GeoVectorValue to upload.
308  */
309  void setAttributeFromVectorId(const std::string& AttributeName,
311  const std::string& IdColumn,
312  const std::string& ValueColumn);
313 
314  /**
315  @brief Creates a new attribute for all the LandREntity of this LandRGraph, and set for each LandREntity
316  this attribute value as the vector value corresponding to the entity OFLD_ID.
317  @param AttributeName The name of the attribute to create.
318  @param Vector The Name of the VectorDataset.
319  @param IdColumn The ID number column of the landr::VectorDataset.
320  @param ValueColumn The column of the landr::VectorDataset to upload.
321  */
322  void setAttributeFromVectorId(const std::string& AttributeName,
324  const std::string& IdColumn,
325  const std::string& ValueColumn);
326 
327  /**
328  @brief Creates a new attribute for all the LandREntity of this LandRGraph, and set for each LandREntity
329  this attribute value as the vector value corresponding to the Vector Entity Geometry
330  @param AttributeName The name of the attribute to create.
331  @param Vector The Name of the core::GeoVectorValue.
332  @param Column The column of the core::GeoVectorValue to upload.
333  @param Thresh The threshold of minimum distance between
334  the core::GeoVectorValue geometry and the LandRGraph geometry.
335  */
336  virtual void setAttributeFromVectorLocation(const std::string& AttributeName,
338  const std::string& Column,double Thresh=0.0001);
339 
340  /**
341  @brief Creates a new attribute for all the LandREntity of this LandRGraph, and set for each LandREntity
342  this attribute value as the vector value corresponding to the Vector Entity Geometry
343  @param AttributeName The name of the attribute to create.
344  @param Vector The Name of the VectorDataset.
345  @param Column The column of the VectorDataset to upload.
346  @param Thresh The threshold of minimum distance between the VectorDataset geometry and the LandRGraph geometry.
347  */
348  virtual void setAttributeFromVectorLocation(const std::string& AttributeName,
350  const std::string& Column,double Thresh=0.0001);
351 
352  /**
353  @brief Removes a LandREntity with identifier from this LandRGraph.
354  @details The associated nodes of the LandREntity are also removed.
355  @param OfldId The identifier.
356  */
357  virtual void removeEntity(int OfldId)=0;
358 
359  /**
360  @brief Snap the vertices of this LandRGraph under a threshold.
361  @param snapTolerance The threshold.
362  */
363  void snapVertices(double snapTolerance);
364 
365 };
366 
367 
368 } } // namespaces
369 
370 
371 #endif /* __OPENFLUID_LANDR_LANDRGRAPH_HPP__ */
Interface for a graph composed of LandREntity.
Definition: LandRGraph.hpp:83
Entities_t m_Entities
A list of the LandREntity of this LandRGraph.
Definition: LandRGraph.hpp:114
Definition: GeoRasterValue.hpp:55
Definition: LandRGraph.hpp:60
openfluid::landr::VectorDataset * mp_Vector
The VectorDataset associated to this LandRGraph.
Definition: LandRGraph.hpp:99
const geos::geom::GeometryFactory * mp_Factory
The geos::geom::GeometryFactory used to build this LandRGraph.
Definition: LandRGraph.hpp:104
std::map< int, LandREntity * > m_EntitiesByOfldId
A map of the LandREntity of this LandRGraph and sorted by identifier.
Definition: LandRGraph.hpp:109
std::vector< geos::geom::Polygon * > * mp_RasterPolygonizedPolys
A vector of geos::geom::Polygon representation of the RasterDataset associated to this LandRGraph...
Definition: LandRGraph.hpp:129
std::list< LandREntity * > Entities_t
Definition: LandRGraph.hpp:92
static int m_FileNum
Definition: LandRGraph.hpp:131
Interface for a landscape representation element.
Definition: LandREntity.hpp:69
Interface for managing Vector Data format.
Definition: VectorDataset.hpp:64
Definition: LandRGraph.hpp:89
openfluid::landr::RasterDataset * mp_Raster
The RasterDataset associated to this LandRGraph.
Definition: LandRGraph.hpp:119
Definition: LandREntity.hpp:53
Definition: ApplicationException.hpp:47
Definition: GeoVectorValue.hpp:55
Interface for managing Raster Data format.
Definition: RasterDataset.hpp:70
#define OPENFLUID_API
Definition: dllexport.hpp:87
openfluid::landr::VectorDataset * mp_RasterPolygonized
The VectorDataset representation of the RasterDataset associated to this LandRGraph.
Definition: LandRGraph.hpp:124
GraphType
Definition: LandRGraph.hpp:87