PolygonGraph.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 PolygonGraph.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_POLYGONGRAPH_HPP__
41 #define __OPENFLUID_LANDR_POLYGONGRAPH_HPP__
42 
43 
44 #include <openfluid/core/Value.hpp>
48 #include <openfluid/dllexport.hpp>
49 
50 
51 namespace openfluid { namespace landr {
52 
53 class VectorDataset;
54 
55 /**
56  @brief A LandRGraph composed of PolygonEntities.
57 */
59 {
60  public:
61 
62  /**
63  @brief A a map of polygonized Raster geos::geom::Polygon and its area intersecting PolygonEntity.
64  */
65  typedef std::map<geos::geom::Polygon*, double> RastValByRastPoly_t;
66 
67 
68  private:
69 
70  /**
71  @brief Creates a new PolygonGraph from an other PolygonGraph.
72  */
73  PolygonGraph(PolygonGraph& Other);
74 
75 
76  protected:
77 
78  PolygonGraph();
79 
80  /**
81  @brief Creates a new PolygonGraph initialized from a core::GeoVectorValue.
82  */
84 
85  /**
86  @brief Creates a new PolygonGraph initialized from a VectorDataset.
87  */
89 
90  /**
91  @brief Adds a LandREntity into this PolygonGraph.
92  */
93  virtual void addEntity(LandREntity* Entity);
94 
95  /**
96  @brief Creates a new PolygonEntity.
97  @param Geom The geos::geom::Geometry of the new PolygonEntity to create.
98  @param OfldId The identifier of the new PolygonEntity.
99  @return A new LandREntity.
100  */
101  virtual LandREntity* createNewEntity(const geos::geom::Geometry* Geom,
102  unsigned int OfldId);
103 
104  /**
105  @brief Creates a new PolygonEdge, with its two DirectedEdges and add them to this graph.
106  @param LineString The geos::geom::LineString representing the PolygonEdge to create.
107  @return The newly created PolygonEdge, or 0 if fails.
108  */
109  PolygonEdge* createEdge(geos::geom::LineString& LineString);
110 
111  /**
112  @brief Removes a segment of the exterior boundary of the input PolygonEntity.
113  @param Entity The PolygonEntity to removes the segment to.
114  @param Segment The geos::geom::LineString to remove.
115  */
116  void removeSegment(PolygonEntity* Entity,
117  geos::geom::LineString* Segment);
118 
119  /**
120  @brief Adds an attribute to the PolygonEdge of a PolygonEntity.
121  @param AttributeName The name of the attribute to add.
122  @param Entity The LandREntity to add the PolygonEdge attribute.
123  */
124  void addEdgeAttribute(std::string AttributeName,
125  LandREntity& Entity);
126 
127  /**
128  @brief Removes an attribute to the PolygonEdge of a PolygonEntity.
129  @param AttributeName The name of the attribute to remove.
130  @param Entity The LandREntity to remove the PolygonEdge attribute.
131  */
132  void removeEdgeAttribute(std::string AttributeName,
133  LandREntity& Entity);
134 
135  public:
136 
137  /**
138  @brief Creates a new PolygonGraph initialized from a core::GeoVectorValue.
139  @details Val must be composed of one or many Polygons, and each of them must contain a "OFLD_ID" attribute.
140  */
141  static PolygonGraph* create(openfluid::core::GeoVectorValue& Val);
142 
143  /**
144  @brief Create a new PolygonGraph initialized from a VectorDataset.
145  @details Vect must be composed of one or many Polygons, and each of them must contain a "OFLD_ID" attribute.
146  */
147  static PolygonGraph* create(openfluid::landr::VectorDataset& Vect);
148 
149  /**
150  @brief Create a new PolygonGraph initialized with a list of LandREntity.
151  @details Entities must be PolygonEntity.
152  */
153  static PolygonGraph* create(const LandRGraph::Entities_t& Entities);
154 
155  virtual ~PolygonGraph();
156 
157  /**
158  @brief Returns the type of graph.
159  */
160  LandRGraph::GraphType getType();
161 
162  /**
163  @brief Returns a PolygonEntity with OfldId, or 0 if it doesn't exist.
164  */
165  PolygonEntity* entity(int OfldId);
166 
167  /**
168  @brief Returns true if each PolygonEntity is complete.
169  @return True if all PolygonEntity of this PolygonGraph are complete, false otherwise.
170  */
171  bool isComplete();
172 
173  /**
174  @brief Returns true if this PolygonGraph has one or more islands.
175  @return True if one or more islands are present, false otherwise.
176  */
177  bool hasIsland();
178 
179  /**
180  @brief Gets a map of polygonized Raster polygons and its area intersecting Entity.
181  @param Entity The PolygonEntity to compare with the associated Raster.
182  @return A map of polygonized Raster Polygons, from associated polygonized raster,
183  with for each one the intersection area.
184  */
185  RastValByRastPoly_t computeRasterPolyOverlapping(PolygonEntity& Entity);
186 
187  /**
188  @brief Creates a new attribute for this PolygonGraph entities, and set for each PolygonEntity
189  this attribute value as the mean of the overlapping raster values, relative to overlapping areas.
190  @param AttributeName The name of the attribute to create
191  */
192  virtual void setAttributeFromMeanRasterValues(const std::string& AttributeName);
193 
194  /**
195  @brief Creates on disk a shapefile representing the PolygonEdges of this PolygonGraph.
196  @param FilePath The path where to create the out file.
197  @param FileName A name for the out file to create, with a .shp extension.
198  */
199  void createVectorRepresentation(std::string FilePath,
200  std::string FileName);
201 
202  /**
203  @brief Computes the neighbours between the PolygonEntity elements of this PolygonGraph
204  and the LineStringEntity of a LineStringGraph.
205  @param Graph The LineStringGraph to compare to.
206  @param Relation The Relationship to use for comparison.
207  @param BufferDistance The distance below which we consider that two elements are related.
208  @param ContactLength Min Length of the LineString in intersection with polygon Buffered Boundaries
209  to be taking acccount (only for LandRTools::TOUCHES RelationShip)
210  */
211  void computeLineStringNeighbours(LineStringGraph& Graph,
213  double BufferDistance,
214  double ContactLength=0);
215 
216  /**
217  @brief Computes the neighbours between the PolygonEntity elements of this PolygonGraph by using
218  the LineStringEntity of an input LineStringGraph which are considered as barriers.
219  @details A barrier between two PolygonEntity will avoid to considered them as neighbours.
220  @details A LineStringEntity is considered as a barrier if it lies within the buffer of this
221  PolygonEntity polygon boundary.
222  @param Graph The LineStringGraph to compare to.
223  @param Relation The Relationship to use for comparison, the LandRTools::Relationship INTERSECTS is not allowed.
224  @param BufferDistance The distance below which we consider that two elements are related.
225  @param ContactLength Min Length of the LineString in intersection with polygon Buffered Boundaries
226  to be taking acccount (only for LandRTools::TOUCHES RelationShip)
227  */
228  void computeNeighboursWithBarriers(LineStringGraph& Graph,
230  double BufferDistance,
231  double ContactLength=0);
232 
233  /**
234  @brief Creates attribute for the PolygonEdge of this PolygonGraph.
235  @details Doesn't reset if the AttributeName already exists.
236  @param AttributeName The name of the PolygonEdge attribute.
237  @param Value The core::Value to associate to this attribute.
238  */
239  void createEdgeAttribute(std::string AttributeName,
240  openfluid::core::Value &Value);
241 
242  /**
243  @brief Removes the attribute of the PolygonEdge of this PolygonGraph.
244  @param AttributeName The name of the PolygonEdge attribute to delete.
245  @details Does nothing if AttributeName doesn't exist.
246  */
247  void removeEdgeAttribute(std::string AttributeName);
248 
249  /**
250  @brief Returns a vector of the name of the PolygonEdge attributes.
251  @return A vector of the name of the PolygonEdge attributes.
252  */
253  std::vector<std::string> getEdgeAttributeNames();
254 
255  /**
256  @brief Removes from this PolygonGraph the PolygonEntity with OfldId and its associated nodes.
257  @param OfldId
258  */
259  virtual void removeEntity(int OfldId);
260 
261  /**
262  @brief Clean the PolygonEdge of a PolygonEntity.
263  @param Entity The PolygonEntity to clean.
264  */
265  void cleanEdges(PolygonEntity & Entity);
266 
267  /**
268  @brief Gets a map of small PolygonEntity which area are under a threshold.
269  @param MinArea The area threshold (in map units).
270  @param Neighbour : if true, get only PolygonEntity with at least
271  one PolygonEntity neighbour; default is true.
272  @return a multimap of PolygonEntity with key is the area of each PolygonEntity.
273  */
274  std::multimap<double, PolygonEntity*> getPolygonEntitiesByMinArea(double MinArea, bool Neighbour=true);
275 
276  /**
277  @brief Gets a map of sliver PolygonEntity which compactness value are superior to a
278  compactness threshold (Gravelius Index)
279  @param Compactness The compactness threshold (perimeter/2 x sqrt (Pi x area))
280  @param Neighbour : if true, get only PolygonEntity with at least
281  one PolygonEntity neighbour; default is false.
282  @return a multimap of PolygonEntity with key is the compactness of each PolygonEntity.
283  */
284  std::multimap<double, PolygonEntity*> getPolygonEntitiesByCompactness(double Compactness, bool Neighbour=true);
285 
286  /**
287  @brief Merge a PolygonEntity into an other one.
288  @details The PolygonEntity to merge is deleted.
289  @param Entity An existent PolygonEntity.
290  @param EntityToMerge The PolygonEntity which will be merged into Entity and will be deleted.
291  */
292  void mergePolygonEntities(PolygonEntity& Entity,
293  PolygonEntity& EntityToMerge);
294 
295  /**
296  @brief Merge the entities of this PolygonGraph which area is under threshold
297  @details The small PolygonEntity is merged into the one which share the longest boundary.
298  @param MinArea The minimum area threshold.
299  */
300  void mergePolygonEntitiesByMinArea(double MinArea);
301 
302  /**
303  @brief Merge the entities of this PolygonGraph which compactness value are superior
304  to a compactness threshold (Gravelius Index).
305  @details The small PolygonEntity is merged into the one which share the longest boundary.
306  @param Compactness The compactness threshold (perimeter/2 x sqrt (Pi x area)).
307  */
308  void mergePolygonEntitiesByCompactness(double Compactness);
309 
310 };
311 
312 
313 } } // namespaces
314 
315 
316 #endif /* __OPENFLUID_LANDR_POLYGONGRAPH_HPP__ */
Definition: Value.hpp:64
Interface for a graph composed of LandREntity.
Definition: LandRGraph.hpp:83
A LandRGraph composed of PolygonEntities.
Definition: PolygonGraph.hpp:58
std::list< LandREntity * > Entities_t
Definition: LandRGraph.hpp:92
Interface for a landscape representation element.
Definition: LandREntity.hpp:69
Interface for managing Vector Data format.
Definition: VectorDataset.hpp:64
A LandRGraph composed of LineStringEntities.
Definition: LineStringGraph.hpp:120
A LandREntity representing a geos::geom::Polygon.
Definition: PolygonEntity.hpp:67
Relationship
Definition: LandRTools.hpp:68
Definition: ApplicationException.hpp:47
Definition: GeoVectorValue.hpp:55
#define OPENFLUID_API
Definition: dllexport.hpp:87
std::map< geos::geom::Polygon *, double > RastValByRastPoly_t
A a map of polygonized Raster geos::geom::Polygon and its area intersecting PolygonEntity.
Definition: PolygonGraph.hpp:65
A part of a PolygonEntity exterior ring, that may be share between to adjacent PolygonEntity.
Definition: PolygonEdge.hpp:74
GraphType
Definition: LandRGraph.hpp:87