All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PolygonEntity.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 PolygonEntity.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_POLYGONENTITY_HPP__
40 #define __OPENFLUID_LANDR_POLYGONENTITY_HPP__
41 
45 #include <openfluid/dllexport.hpp>
46 #include <vector>
47 
48 namespace geos { namespace geom {
49 class Polygon;
50 class LineString;
51 } }
52 
53 namespace openfluid { namespace landr {
54 
55 class PolygonEdge;
56 class LineStringGraph;
57 class LineStringEntity;
58 
59 
60 /**
61  @brief A LandREntity representing a geos::geom::Polygon.
62  @details A PolygonEntity has at least a PolygonEdge, all edges representing the Polygon exterior ring.
63 */
65 {
66  private:
67 
68  /**
69  @brief The geos::geom::Polygon associated to this PolygonEntity.
70  */
71  const geos::geom::Polygon* mp_Polygon;
72 
73  PolygonEntity();
75 
76  public:
77 
78  /**
79  @brief A map of the PolygonEntity neighbours and their shared PolygonEdge to this PolygonEntity.
80  */
81  typedef std::map<PolygonEntity*, std::vector<PolygonEdge*> > NeighboursMap_t;
82 
83  /**
84  @brief A map of the LineStringEntity neighbours and the PolygonEdge in contact with this PolygonEntity.
85  */
86  typedef std::map<LineStringEntity*, PolygonEdge*> LineStringNeighboursMap_t;
87 
88  /**
89  @brief A Map of neighbours of PolygonEntity type and the related vector of PolygonEdge
90  that are between this PolygonEntity and his neighbours.
91  */
93 
94  /**
95  @brief A Map of neighbours of LineStringEntity type and the related PolygonEdge
96  that is between this PolygonEntity and his neighbours, if exist.
97  */
99 
100  /**
101  @brief A vector of the PolygonEdge of this PolygonEntity.
102  */
103  std::vector<PolygonEdge*> m_PolyEdges;
104 
105  /**
106  @brief Create a new PolygonEntity.
107  @details Takes ownership of NewPolygon.
108  @param NewPolygon The geos::geom::Geometry of this new PolygonEntity.
109  @param OfldId The identifier of this new PolygonEntity.
110  @throw base::FrameworkException if NewPolygon is not a geos::geom::Polygon or is not a valid geometry.
111  */
112  PolygonEntity(const geos::geom::Geometry* NewPolygon, unsigned int OfldId);
113 
114  virtual ~PolygonEntity();
115 
116  /**
117  @brief Clone a new PolygonEntity from this PolygonEntity.
118  @attention Doesn't deep-copy m_PolyEdges nor neighbours.
119  */
120  PolygonEntity* clone();
121 
122  /**
123  @brief Returns the geos::geom::Polygon associated to this PolygonEntity.
124  */
125  const geos::geom::Polygon* polygon() const;
126 
127  /**
128  @brief Adds a PolygonEdge to this PolygonEntity.
129  */
130  void addEdge(PolygonEdge& Edge);
131 
132  /**
133  @brief Removes a PolygonEdge to this PolygonEntity.
134  @attention Also delete input parameter Edge.
135  */
136  void removeEdge(PolygonEdge* Edge);
137 
138  /**
139  @brief Returns a vector of geos::geom::LineString representing the linear intersections between two PolygonEntity.
140  @param Other The PolygonEntity to compare to.
141  @return A vector of new allocated geos::geom::LineString representing the linear
142  intersections (eventually merged) between this PolygonEntity and Other.
143  */
144  std::vector<geos::geom::LineString*> computeLineIntersectionsWith(PolygonEntity& Other);
145 
146  /**
147  @brief Returns the PolygonEdge containing Segment.
148  @param Segment The geos::geom::LineString to find.
149  @return The PolygonEdge of this PolygonEntity containing the input geos::geom::LineString,
150  or 0 if not found.
151  */
152  PolygonEdge* findEdgeLineIntersectingWith(geos::geom::LineString& Segment);
153 
154  /**
155  @brief Returns a map of this PolygonEntity neighbours with for each a vector of the shared PolygonEdge.
156  */
157  const NeighboursMap_t* neighboursAndEdges();
158 
159  /**
160  @brief Returns a vector of the OFLD_ID of this PolygonEntity neighbours, ascending ordered.
161  */
162  std::vector<int> getOrderedNeighbourOfldIds();
163 
164  /**
165  @brief Returns a multimap of the length of the shared boundary of each
166  neighbour of this PolygonEntity and each PolygonEntity neighbour,
167  ascending ordered by length shared boundary (shortest to longest boundary).
168  */
169  std::multimap<double,PolygonEntity*> getOrderedNeighboursByLengthBoundary();
170 
171  /**
172  @brief Check if this PolygonEntity is complete, that is if all PolygonEdge of this PolygonEntity,
173  merged in a LineString, equals this PolygonEntity polygon exterior ring.
174  @return True if complete, false otherwise.
175  */
176  bool isComplete();
177 
178  /**
179  @brief Gets the PolygonEdge of this PolygonEntity that are shared with Other.
180  @param Other A PolygonEntity.
181  @return A vector of PolygonEdge.
182  */
183  std::vector<PolygonEdge*> getCommonEdgesWith(PolygonEntity& Other);
184 
185  /**
186  @brief Gets the PolygonEntity which share the same Edge with the current PolygonEntity.
187  @param Edge A PolygonEdge.
188  @return A vector a PolygonEntity.
189  */
190  PolygonEntity * neighbourWithCommonEdge(PolygonEdge * Edge);
191 
192  /**
193  @brief Gets the boundary of this PolygonEntity polygon, with a buffer of BufferDistance.
194  @param BufferDistance The buffer distance.
195  @return A geos::geom::Geometry representing the buffered boundaries of this PolygonEntity.
196  */
197  geos::geom::Geometry* getBufferedBoundary(double BufferDistance);
198 
199  /**
200  @brief Computes the neighbours of this PolygonEntity.
201  @details A neighbour is another PolygonEntity that shares at least a PolygonEdge with this PolygonEntity.
202  */
203  void computeNeighbours();
204 
205  /**
206  @brief Computes the relations between this PolygonEntity and the LineStringEntity of an input LineStringGraph.
207  @details A LineStringEntity is considered as a neighbour if it lies within the buffer
208  of this PolygonEntity polygon boundary.
209  @param Graph The LineStringGraph to compare to.
210  @param Relation The Relationship to use for comparison.
211  @param BufferDistance The distance below which we consider that two elements are related.
212  @param ContactLength Min Length of the LineString in intersection with polygon
213  Buffered Boundaries to be taking acccount (only for LandRTools::TOUCHES RelationShip)
214  */
215  void computeLineStringNeighbours(LineStringGraph& Graph,
216  LandRTools::Relationship Relation,
217  double BufferDistance,
218  double ContactLength=0);
219 
220  /**
221  @brief Computes the relations between this PolygonEntity and its PolygonEntities Neighbours by using
222  the LineStringEntity of an input LineStringGraph which are considered as barriers.
223  @details A barrier between two PolygonEntity will avoid to considered them as neighbours.
224  @details A LineStringEntity is considered as a barrier if it lies within the buffer
225  of this PolygonEntity polygon boundary.
226  @param Graph The LineStringGraph to compare to.
227  @param Relation The Relationship to use for comparison, the LandRTools::Relationship INTERSECTS is not allowed.
228  @param BufferDistance The distance below which we consider that two elements are related.
229  @param ContactLength Min Length of the LineString in intersection with polygon
230  Buffered Boundaries to be taking acccount (only for LandRTools::TOUCHES RelationShip)
231  */
232  void computeNeighboursWithBarriers(LineStringGraph& Graph,
233  LandRTools::Relationship Relation,
234  double BufferDistance,
235  double ContactLength=0);
236 
237  /**
238  @brief Return the a map of the LineStringEntity neighbours of this PolygonEntity.
239  */
240  LineStringNeighboursMap_t* lineStringNeighbours();
241 
242  /**
243  @brief Merge a PolygonEdge into an other one.
244  @param Edge An existent PolygonEdge.
245  @param EdgeToMerge Another PolygonEdge to merge.
246  @return A geos::geom:LineString which have the geometry of the merged PolygonEdge.
247  */
248  geos::geom::LineString* mergeEdges(PolygonEdge* Edge,
249  PolygonEdge* EdgeToMerge);
250 
251  /**
252  @brief Find the LandREntity neighbour of this PolygonEntity by using
253  a line VectorDataset which indicates the neighbour relationship
254  \verbatim
255  ************** Following the directions of the
256  * |-*--> * lines of the VectorDataset,
257  * 1 * 3 * the neighbour of PolygonEntity 2 is
258  * * * the PolygonEntity 1 and the neighbour
259  * ^ ******** of PolygonEntity 1 is the PolygonEntity
260  * | * 3. If a line of the VectorDataset crosses
261  ******* a LineStringNeighbour of the PolygonEntity,
262  * | * it becomes the neighbour :e.g, if LineStringNeighbour
263  * - * exists between PolygonEntity 1 and 2, the neighbour
264  * 2 * of PolygonEntity becomes this LineStringNeighbour.
265  * *
266  *******
267  \endverbatim
268  @param LineTopology A line VectorDataset
269  @return A pair of openfluid::landr:landREntity and the length of the line of the VectorDataset
270  or an empty pair if not found.
271  */
272  std::pair< LandREntity*, double> computeNeighbourByLineTopology(VectorDataset LineTopology);
273 
274 
275 
276 };
277 
278 } } // namespace landr, openfluid
279 #endif /* __OPENFLUID_LANDR_POLYGONENTITY_HPP__ */
std::vector< PolygonEdge * > m_PolyEdges
A vector of the PolygonEdge of this PolygonEntity.
Definition: PolygonEntity.hpp:103
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
NeighboursMap_t * mp_NeighboursMap
A Map of neighbours of PolygonEntity type and the related vector of PolygonEdge that are between this...
Definition: PolygonEntity.hpp:92
LineStringNeighboursMap_t * mp_LineStringNeighboursMap
A Map of neighbours of LineStringEntity type and the related PolygonEdge that is between this Polygon...
Definition: PolygonEntity.hpp:98
std::map< PolygonEntity *, std::vector< PolygonEdge * > > NeighboursMap_t
A map of the PolygonEntity neighbours and their shared PolygonEdge to this PolygonEntity.
Definition: PolygonEntity.hpp:81
Interface for a landscape representation element.
Definition: LandREntity.hpp:63
A LandRGraph composed of LineStringEntities.
Definition: LineStringGraph.hpp:109
Relationship
Definition: LandRTools.hpp:65
A LandREntity representing a geos::geom::Polygon.
Definition: PolygonEntity.hpp:64
#define OPENFLUID_API
Definition: dllexport.hpp:87
std::map< LineStringEntity *, PolygonEdge * > LineStringNeighboursMap_t
A map of the LineStringEntity neighbours and the PolygonEdge in contact with this PolygonEntity...
Definition: PolygonEntity.hpp:86