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