landr/PolygonEntity.hpp
Go to the documentation of this file.
00001 /*
00002 
00003   This file is part of OpenFLUID software
00004   Copyright(c) 2007, INRA - Montpellier SupAgro
00005 
00006 
00007  == GNU General Public License Usage ==
00008 
00009   OpenFLUID is free software: you can redistribute it and/or modify
00010   it under the terms of the GNU General Public License as published by
00011   the Free Software Foundation, either version 3 of the License, or
00012   (at your option) any later version.
00013 
00014   OpenFLUID is distributed in the hope that it will be useful,
00015   but WITHOUT ANY WARRANTY; without even the implied warranty of
00016   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017   GNU General Public License for more details.
00018 
00019   You should have received a copy of the GNU General Public License
00020   along with OpenFLUID. If not, see <http://www.gnu.org/licenses/>.
00021 
00022 
00023  == Other Usage ==
00024 
00025   Other Usage means a use of OpenFLUID that is inconsistent with the GPL
00026   license, and requires a written agreement between You and INRA.
00027   Licensees for Other Usage of OpenFLUID may use this file in accordance
00028   with the terms contained in the written agreement between You and INRA.
00029   
00030 */
00031 
00032 /**
00033  \file PolygonEntity.hpp
00034  \brief Header of ...
00035 
00036  \author Aline LIBRES <aline.libres@gmail.com>
00037  */
00038 
00039 #ifndef POLYGONENTITY_HPP_
00040 #define POLYGONENTITY_HPP_
00041 
00042 #include <openfluid/landr/LandREntity.hpp>
00043 #include <openfluid/landr/LandRTools.hpp>
00044 #include <openfluid/dllexport.hpp>
00045 #include <vector>
00046 
00047 namespace geos {
00048 namespace geom {
00049 class Polygon;
00050 class LineString;
00051 }
00052 }
00053 
00054 namespace openfluid {
00055 namespace landr {
00056 
00057 class PolygonEdge;
00058 class LineStringGraph;
00059 class LineStringEntity;
00060 
00061 /**
00062  * @brief A LandREntity representing a geos::geom::Polygon.
00063  * @details A PolygonEntity has at least a PolygonEdge, all edges representing the Polygon exterior ring.
00064  */
00065 class DLLEXPORT PolygonEntity: public LandREntity
00066 {
00067   private:
00068 
00069     /**
00070      * @brief The geos::geom::Polygon associated to this PolygonEntity.
00071      */
00072     const geos::geom::Polygon* mp_Polygon;
00073 
00074     PolygonEntity();
00075     PolygonEntity(const PolygonEntity&);
00076 
00077   public:
00078 
00079     /**
00080      * @brief A map of the PolygonEntity neighbours and their shared PolygonEdge to this PolygonEntity.
00081      */
00082     typedef std::map<PolygonEntity*, std::vector<PolygonEdge*> > NeighboursMap_t;
00083 
00084     /**
00085      * @brief A map of the LineStringEntity neighbours and the PolygonEdge in contact with this PolygonEntity.
00086      */
00087     typedef std::map<LineStringEntity*, PolygonEdge*> LineStringNeighboursMap_t;
00088 
00089     /**
00090      * @brief A Map of neighbours of PolygonEntity type and the related vector of PolygonEdge that are between this PolygonEntity and his neighbours.
00091      */
00092     NeighboursMap_t* mp_NeighboursMap;
00093 
00094     /**
00095      * @brief A Map of neighbours of LineStringEntity type and the related PolygonEdge that is between this PolygonEntity and his neighbours, if exist.
00096      */
00097     LineStringNeighboursMap_t* mp_LineStringNeighboursMap;
00098 
00099     /**
00100      * @brief A vector of the PolygonEdge of this PolygonEntity.
00101      */
00102     std::vector<PolygonEdge*> m_PolyEdges;
00103 
00104     /**
00105      * @brief Create a new PolygonEntity.
00106      * @details Takes ownership of NewPolygon.
00107      * @param NewPolygon The geos::geom::Geometry of this new PolygonEntity.
00108      * @param OfldId The identifier of this new PolygonEntity.
00109      *
00110      *  @throw base::OFException if NewPolygon is not a geos::geom::Polygon or is not a valid geometry.
00111      */
00112     PolygonEntity(const geos::geom::Geometry* NewPolygon, unsigned int OfldId);
00113 
00114     virtual ~PolygonEntity();
00115 
00116     /**
00117      * @brief Clone a new PolygonEntity from this PolygonEntity.
00118      * @attention Doesn't deep-copy m_PolyEdges nor neighbours.
00119      */
00120     PolygonEntity* clone();
00121 
00122     /**
00123      * @brief Returns the geos::geom::Polygon associated to this PolygonEntity.
00124      */
00125     const geos::geom::Polygon* getPolygon() const;
00126 
00127     /**
00128      * @brief Adds a PolygonEdge to this PolygonEntity.
00129      */
00130     void addEdge(PolygonEdge& Edge);
00131 
00132     /**
00133      * @brief Removes a PolygonEdge to this PolygonEntity.
00134      * @attention Also delete input parameter Edge.
00135      */
00136     void removeEdge(PolygonEdge* Edge);
00137 
00138     /**
00139      * @brief Returns a vector of geos::geom::LineString representing the linear intersections between two PolygonEntity.
00140      *
00141      * @param Other The PolygonEntity to compare to.
00142      * @return A vector of new allocated geos::geom::LineString representing the linear intersections (eventually merged) between this PolygonEntity and Other.
00143      */
00144     std::vector<geos::geom::LineString*> getLineIntersectionsWith(
00145         PolygonEntity& Other);
00146 
00147     /**
00148      * @brief Returns the PolygonEdge containing Segment.
00149      *
00150      * @param Segment The geos::geom::LineString to find.
00151      * @return The PolygonEdge of this PolygonEntity containing the input geos::geom::LineString,
00152      * or 0 if not found.
00153      */
00154     PolygonEdge* findEdgeLineIntersectingWith(geos::geom::LineString& Segment);
00155 
00156     /**
00157      * @brief Returns a map of this PolygonEntity neighbours with for each a vector of the shared PolygonEdge.
00158      */
00159     const NeighboursMap_t* getNeighboursAndEdges();
00160 
00161     /**
00162      * @brief Returns a vector of the OFLD_ID of this PolygonEntity neighbours, ascending ordered.
00163      */
00164     std::vector<int> getOrderedNeighbourOfldIds();
00165 
00166     /**
00167      * @brief Check if this PolygonEntity is complete, that is if all PolygonEdge of this PolygonEntity,
00168      * merged in a LineString, equals this PolygonEntity polygon exterior ring.
00169      *
00170      * @return True if complete, false otherwise.
00171      */
00172     bool isComplete();
00173 
00174     /**
00175      * @brief Gets the PolygonEdge of this PolygonEntity that are shared with Other.
00176      * @param Other A PolygonEntity.
00177      * @return A vector of PolygonEdge.
00178      */
00179     std::vector<PolygonEdge*> getCommonEdgesWith(PolygonEntity& Other);
00180 
00181     /**
00182      * @brief Gets the boundary of this PolygonEntity polygon, with a buffer of BufferDistance.
00183      * @param BufferDistance The buffer distance.
00184      * @return A geos::geom::Geometry representing the buffered boundaries of this PolygonEntity.
00185      */
00186     geos::geom::Geometry* getBufferedBoundary(double BufferDistance);
00187 
00188     /**
00189      * @brief Computes the neighbours of this PolygonEntity.
00190      * @details A neighbour is another PolygonEntity that shares at least a PolygonEdge with this PolygonEntity.
00191      */
00192     void computeNeighbours();
00193 
00194     /**
00195      * @brief Computes the relations between this PolygonEntity and the LineStringEntity of an input LineStringGraph.
00196      * @details A LineStringEntity is considered as a neighbour if it lies within the buffer of this PolygonEntity polygon boundary.
00197      *
00198      * @param Graph The LineStringGraph to compare to.
00199      * @param Relation The Relationship to use for comparison.
00200      * @param BufferDistance The distance below which we consider that two elements are related.
00201      * @param ContactLength Min Length of the LineString in intersection with polygon Buffered Boundaries to be taking acccount (only for LandRTools::TOUCHES RelationShip)
00202      */
00203     void computeLineStringNeighbours(LineStringGraph& Graph,
00204                                      LandRTools::Relationship Relation,
00205                                      double BufferDistance,double ContactLength=0);
00206 
00207     /**
00208      * @brief Return the a map of the LineStringEntity neighbours of this PolygonEntity.
00209      */
00210     LineStringNeighboursMap_t* getLineStringNeighbours();
00211 
00212 
00213     /**
00214      * @brief Merge a PolygonEdge into an other one.
00215      *
00216      * @param Edge An existent PolygonEdge.
00217      * @param EdgeToMerge Another PolygonEdge to merge.
00218      * @return A geos::geom:LineString which have the geometry of the merged PolygonEdge.
00219      */
00220     geos::geom::LineString*  mergeEdges(PolygonEdge* Edge, PolygonEdge* EdgeToMerge);
00221 
00222 
00223 
00224 
00225 };
00226 
00227 } // namespace landr
00228 } /* namespace openfluid */
00229 #endif /* POLYGONENTITY_HPP_ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines