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