Manual for OpenFLUID 2.1.11

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