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