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