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  \brief Header of ...
35 
36  \author Aline LIBRES <aline.libres@gmail.com>
37  */
38 
39 #ifndef POLYGONGRAPH_HPP_
40 #define 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* getNewEntity(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* getEntity(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 getRasterPolyOverlapping(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 and the LineStringEntity of a LineStringGraph.
202  @param Graph The LineStringGraph to compare to.
203  @param Relation The Relationship to use for comparison.
204  @param BufferDistance The distance below which we consider that two elements are related.
205  @param ContactLength Min Length of the LineString in intersection with polygon Buffered Boundaries to be taking acccount (only for LandRTools::TOUCHES RelationShip)
206  */
207  void computeLineStringNeighbours(LineStringGraph& Graph,
209  double BufferDistance,
210  double ContactLength=0);
211 
212  /**
213  @brief Computes the neighbours between the PolygonEntity elements of this PolygonGraph by using
214  the LineStringEntity of an input LineStringGraph which are considered as barriers.
215  @details A barrier between two PolygonEntity will avoid to considered them as neighbours.
216  @details A LineStringEntity is considered as a barrier if it lies within the buffer of this PolygonEntity polygon boundary.
217  @param Graph The LineStringGraph to compare to.
218  @param Relation The Relationship to use for comparison, the LandRTools::Relationship INTERSECTS is not allowed.
219  @param BufferDistance The distance below which we consider that two elements are related.
220  @param ContactLength Min Length of the LineString in intersection with polygon Buffered Boundaries to be taking acccount (only for LandRTools::TOUCHES RelationShip)
221  */
222  void computeNeighboursWithBarriers(LineStringGraph& Graph,
224  double BufferDistance,
225  double ContactLength=0);
226 
227  /**
228  @brief Creates attribute for the PolygonEdge of this PolygonGraph.
229  @details Doesn't reset if the AttributeName already exists.
230  @param AttributeName The name of the PolygonEdge attribute.
231  @param Value The core::Value to associate to this attribute.
232  */
233  void createEdgeAttribute(std::string AttributeName,
234  openfluid::core::Value &Value);
235 
236  /**
237  @brief Removes the attribute of the PolygonEdge of this PolygonGraph.
238  @param AttributeName The name of the PolygonEdge attribute to delete.
239  @details Does nothing if AttributeName doesn't exist.
240  */
241  void removeEdgeAttribute(std::string AttributeName);
242 
243  /**
244  @brief Returns a vector of the name of the PolygonEdge attributes.
245  @return A vector of the name of the PolygonEdge attributes.
246  */
247  std::vector<std::string> getEdgeAttributeNames();
248 
249  /**
250  @brief Removes from this PolygonGraph the PolygonEntity with OfldId and its associated nodes.
251  @param OfldId
252  */
253  virtual void removeEntity(int OfldId);
254 
255  /**
256  @brief Clean the PolygonEdge of a PolygonEntity.
257  @param Entity The PolygonEntity to clean.
258  */
259  void cleanEdges(PolygonEntity & Entity);
260 
261  /**
262  @brief Gets a map of small PolygonEntity which area are under a threshold.
263  @param MinArea The area threshold (in map units).
264  @return a multimap of PolygonEntity with key is the area of each PolygonEntity.
265  */
266  std::multimap<double, PolygonEntity*> getPolygonEntitiesByMinArea(double MinArea);
267 
268  /**
269  @brief Gets a map of sliver PolygonEntity which compactness value are superior to a compactness threshold (Gravelius Index)
270  @param Compactness The compactness threshold (perimeter/2 x sqrt (Pi x area))
271  @return a multimap of PolygonEntity with key is the compactness of each PolygonEntity.
272  */
273  std::multimap<double, PolygonEntity*> getPolygonEntitiesByCompactness(double Compactness);
274 
275  /**
276  @brief Merge a PolygonEntity into an other one.
277  @details The PolygonEntity to merge is deleted.
278  @param Entity An existent PolygonEntity.
279  @param EntityToMerge The PolygonEntity which will be merged into Entity and will be deleted.
280  */
281  void mergePolygonEntities(PolygonEntity& Entity,
282  PolygonEntity& EntityToMerge);
283 
284 
285 
286 };
287 
288 } } // namespace landr, openfluid
289 #endif /* POLYGONGRAPH_HPP_ */
Relationship
Definition: LandRTools.hpp:65
Interface for managing Vector Data format.
Definition: VectorDataset.hpp:65
A LandRGraph composed of LineStringEntities.
Definition: LineStringGraph.hpp:107
Header of ...
GraphType
Definition: LandRGraph.hpp:82
Header of ...
A LandRGraph composed of PolygonEntities.
Definition: PolygonGraph.hpp:58
Interface for a landscape representation element.
Definition: LandREntity.hpp:63
Header of ...
Interface for a graph composed of LandREntity.
Definition: LandRGraph.hpp:78
A LandREntity representing a geos::geom::Polygon.
Definition: PolygonEntity.hpp:64
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
Definition: Value.hpp:64
std::list< LandREntity * > Entities_t
Definition: LandRGraph.hpp:87
Container class for geospatial vector data, represented by an OGR datasource.
Definition: GeoVectorValue.hpp:54
A part of a PolygonEntity exterior ring, that may be share between to adjacent PolygonEntity.
Definition: PolygonEdge.hpp:69
Header of ...
#define DLLEXPORT
Definition: dllexport.hpp:51