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