landr/PolygonGraph.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 PolygonGraph.hpp
00034  \brief Header of ...
00035 
00036  \author Aline LIBRES <aline.libres@gmail.com>
00037  */
00038 
00039 #ifndef POLYGONGRAPH_HPP_
00040 #define POLYGONGRAPH_HPP_
00041 
00042 #include <openfluid/core/Value.hpp>
00043 #include <openfluid/core/DoubleValue.hpp>
00044 #include <openfluid/landr/LandRGraph.hpp>
00045 
00046 
00047 // for covariant return type of getEntity
00048 #include <openfluid/landr/PolygonEntity.hpp>
00049 #include <openfluid/dllexport.hpp>
00050 
00051 namespace openfluid { namespace landr {
00052 
00053 class VectorDataset;
00054 
00055 /**
00056  @brief A LandRGraph composed of PolygonEntities.
00057  */
00058 class DLLEXPORT PolygonGraph: public LandRGraph
00059 {
00060   public:
00061 
00062     /**
00063      @brief A a map of polygonized Raster geos::geom::Polygon and its area intersecting PolygonEntity.
00064      */
00065     typedef std::map<geos::geom::Polygon*, double> RastValByRastPoly_t;
00066 
00067   private:
00068 
00069     /**
00070      @brief Creates a new PolygonGraph from an other PolygonGraph.
00071      */
00072     PolygonGraph(PolygonGraph& Other);
00073 
00074   protected:
00075 
00076     PolygonGraph();
00077 
00078     /**
00079      @brief Creates a new PolygonGraph initialized from a core::GeoVectorValue.
00080      */
00081     PolygonGraph(openfluid::core::GeoVectorValue& Val);
00082 
00083     /**
00084      @brief Creates a new PolygonGraph initialized from a VectorDataset.
00085      */
00086     PolygonGraph(openfluid::landr::VectorDataset& Vect);
00087 
00088     /**
00089      @brief Adds a LandREntity into this PolygonGraph.
00090      */
00091     virtual void addEntity(LandREntity* Entity);
00092 
00093     /**
00094      @brief Creates a new PolygonEntity.
00095      @param Geom The geos::geom::Geometry of the new PolygonEntity to create.
00096      @param OfldId The identifier of the new PolygonEntity.
00097      @return A new LandREntity.
00098      */
00099     virtual LandREntity* getNewEntity(const geos::geom::Geometry* Geom,
00100                                       unsigned int OfldId);
00101 
00102     /**
00103      @brief Creates a new PolygonEdge, with its two DirectedEdges and add them to this graph.
00104      @param LineString The geos::geom::LineString representing the PolygonEdge to create.
00105      @return The newly created PolygonEdge, or 0 if fails.
00106      */
00107     PolygonEdge* createEdge(geos::geom::LineString& LineString);
00108 
00109     /**
00110      @brief Removes a segment of the exterior boundary of the input PolygonEntity.
00111      @param Entity The PolygonEntity to removes the segment to.
00112      @param Segment The geos::geom::LineString to remove.
00113      */
00114     void removeSegment(PolygonEntity* Entity,
00115                        geos::geom::LineString* Segment);
00116 
00117     /**
00118      @brief Adds an attribute to the PolygonEdge of a PolygonEntity.
00119      @param AttributeName The name of the attribute to add.
00120      @param Entity The LandREntity to add the PolygonEdge attribute.
00121      */
00122     void addEdgeAttribute(std::string AttributeName,
00123                           LandREntity& Entity);
00124 
00125     /**
00126      @brief Removes an attribute to the PolygonEdge of a PolygonEntity.
00127      @param AttributeName The name of the attribute to remove.
00128      @param Entity The LandREntity to remove the PolygonEdge attribute.
00129      */
00130     void removeEdgeAttribute(std::string AttributeName,
00131                              LandREntity& Entity);
00132 
00133   public:
00134 
00135     /**
00136      @brief Creates a new PolygonGraph initialized from a core::GeoVectorValue.
00137      @details Val must be composed of one or many Polygons, and each of them must contain a "OFLD_ID" attribute.
00138      */
00139     static PolygonGraph* create(openfluid::core::GeoVectorValue& Val);
00140 
00141     /**
00142      @brief Create a new PolygonGraph initialized from a VectorDataset.
00143      @details Vect must be composed of one or many Polygons, and each of them must contain a "OFLD_ID" attribute.
00144      */
00145     static PolygonGraph* create(openfluid::landr::VectorDataset& Vect);
00146 
00147     /**
00148      @brief Create a new PolygonGraph initialized with a list of LandREntity.
00149      @details Entities must be PolygonEntity.
00150      */
00151     static PolygonGraph* create(const LandRGraph::Entities_t& Entities);
00152 
00153     virtual ~PolygonGraph();
00154 
00155     /**
00156      @brief Returns the type of graph.
00157      */
00158     LandRGraph::GraphType getType();
00159 
00160     /**
00161      @brief Returns a PolygonEntity with OfldId, or 0 if it doesn't exist.
00162      */
00163     PolygonEntity* getEntity(int OfldId);
00164 
00165     /**
00166      @brief Returns true if each PolygonEntity is complete.
00167      @return True if all PolygonEntity of this PolygonGraph are complete, false otherwise.
00168      */
00169     bool isComplete();
00170 
00171     /**
00172      @brief Returns true if this PolygonGraph has one or more islands.
00173      @return True if one or more islands are present, false otherwise.
00174      */
00175     bool hasIsland();
00176 
00177     /**
00178      @brief Gets a map of polygonized Raster polygons and its area intersecting Entity.
00179      @param Entity The PolygonEntity to compare with the associated Raster.
00180      @return A map of polygonized Raster Polygons, from associated polygonized raster,
00181      with for each one the intersection area.
00182      */
00183     RastValByRastPoly_t getRasterPolyOverlapping(PolygonEntity& Entity);
00184 
00185     /**
00186      @brief Creates a new attribute for this PolygonGraph entities, and set for each PolygonEntity
00187      this attribute value as the mean of the overlapping raster values, relative to overlapping areas.
00188      @param AttributeName The name of the attribute to create
00189      */
00190     virtual void setAttributeFromMeanRasterValues(const std::string& AttributeName);
00191 
00192     /**
00193      @brief Creates on disk a shapefile representing the PolygonEdges of this PolygonGraph.
00194      @param FilePath The path where to create the out file.
00195      @param FileName A name for the out file to create, with a .shp extension.
00196      */
00197     void createVectorRepresentation(std::string FilePath,
00198                                     std::string FileName);
00199 
00200     /**
00201      @brief Computes the neighbours between the PolygonEntity elements of this PolygonGraph and the LineStringEntity of a LineStringGraph.
00202      @param Graph The LineStringGraph to compare to.
00203      @param Relation The Relationship to use for comparison.
00204      @param BufferDistance The distance below which we consider that two elements are related.
00205      @param ContactLength Min Length of the LineString in intersection with polygon Buffered Boundaries to be taking acccount (only for LandRTools::TOUCHES RelationShip)
00206      */
00207     void computeLineStringNeighbours(LineStringGraph& Graph,
00208                                      openfluid::landr::LandRTools::Relationship Relation,
00209                                      double BufferDistance,
00210                                      double ContactLength=0);
00211 
00212     /**
00213      @brief Computes the neighbours between the PolygonEntity elements of this PolygonGraph by using
00214      the LineStringEntity of an input LineStringGraph which are considered as barriers.
00215      @details A barrier between two PolygonEntity will avoid to considered them as neighbours.
00216      @details A LineStringEntity is considered as a barrier if it lies within the buffer of this PolygonEntity polygon boundary.
00217      @param Graph The LineStringGraph to compare to.
00218      @param Relation The Relationship to use for comparison, the LandRTools::Relationship INTERSECTS is not allowed.
00219      @param BufferDistance The distance below which we consider that two elements are related.
00220      @param ContactLength Min Length of the LineString in intersection with polygon Buffered Boundaries to be taking acccount (only for LandRTools::TOUCHES RelationShip)
00221      */
00222     void computeNeighboursWithBarriers(LineStringGraph& Graph,
00223                                        openfluid::landr::LandRTools::Relationship Relation,
00224                                        double BufferDistance,
00225                                        double ContactLength=0);
00226 
00227     /**
00228      @brief Creates attribute for the PolygonEdge of this PolygonGraph.
00229      @details Doesn't reset if the AttributeName already exists.
00230      @param AttributeName The name of the PolygonEdge attribute.
00231      @param Value The core::Value to associate to this attribute.
00232      */
00233     void createEdgeAttribute(std::string AttributeName,
00234                              openfluid::core::Value &Value);
00235 
00236     /**
00237      @brief Removes the attribute of the PolygonEdge of this PolygonGraph.
00238      @param AttributeName The name of the PolygonEdge attribute to delete.
00239      @details Does nothing if AttributeName doesn't exist.
00240      */
00241     void removeEdgeAttribute(std::string AttributeName);
00242 
00243     /**
00244      @brief Returns a vector of the name of the PolygonEdge attributes.
00245      @return A vector of the name of the PolygonEdge attributes.
00246      */
00247     std::vector<std::string> getEdgeAttributeNames();
00248 
00249        /**
00250      @brief Removes from this PolygonGraph the PolygonEntity with OfldId and its associated nodes.
00251      @param OfldId
00252      */
00253     virtual void removeEntity(int OfldId);
00254 
00255     /**
00256      @brief Clean the PolygonEdge of a PolygonEntity.
00257      @param Entity The PolygonEntity to clean.
00258      */
00259     void cleanEdges(PolygonEntity & Entity);
00260 
00261     /**
00262      @brief Gets a map of small PolygonEntity which area are under a threshold.
00263      @param MinArea The area threshold (in map units).
00264      @return a multimap of PolygonEntity with key is the area of each PolygonEntity.
00265      */
00266     std::multimap<double,  PolygonEntity*> getPolygonEntitiesByMinArea(double MinArea);
00267 
00268     /**
00269      @brief Gets a map of sliver PolygonEntity which compactness value are superior to a compactness threshold (Gravelius Index)
00270      @param Compactness The compactness threshold (perimeter/2 x sqrt (Pi x area))
00271      @return a multimap of PolygonEntity with key is the compactness of each PolygonEntity.
00272      */
00273     std::multimap<double,  PolygonEntity*> getPolygonEntitiesByCompactness(double Compactness);
00274 
00275     /**
00276      @brief Merge a PolygonEntity into an other one.
00277      @details The PolygonEntity to merge is deleted.
00278      @param Entity An existent PolygonEntity.
00279      @param EntityToMerge The PolygonEntity which will be merged into Entity and will be deleted.
00280      */
00281     void mergePolygonEntities(PolygonEntity& Entity,
00282                               PolygonEntity& EntityToMerge);
00283 
00284 
00285 
00286 };
00287 
00288 } } // namespace landr, openfluid
00289 #endif /* POLYGONGRAPH_HPP_ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines