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