landr/LandRGraph.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 LandRGraph.hpp
00034  \brief Header of ...
00035 
00036  \author Aline LIBRES <aline.libres@gmail.com>
00037  */
00038 
00039 #ifndef LANDRGRAPH_HPP_
00040 #define LANDRGRAPH_HPP_
00041 
00042 #include <geos/planargraph/PlanarGraph.h>
00043 #include <openfluid/dllexport.hpp>
00044 #include <ogrsf_frmts.h>
00045 #include <list>
00046 
00047 namespace geos { namespace geom {
00048 class Geometry;
00049 class GeometryFactory;
00050 class LineString;
00051 class Polygon;
00052 class Coordinate;
00053 } }
00054 
00055 namespace planargraph {
00056 class Node;
00057 }
00058 
00059 namespace openfluid {
00060 
00061 namespace core {
00062 class GeoVectorValue;
00063 class GeoRasterValue;
00064 }
00065 
00066 /**
00067  @brief Classes for landscape representation management.
00068  */
00069 namespace landr {
00070 
00071 class LandREntity;
00072 class VectorDataset;
00073 class RasterDataset;
00074 
00075 /**
00076  @brief Interface for a graph composed of LandREntity.
00077  */
00078 class DLLEXPORT LandRGraph: public geos::planargraph::PlanarGraph
00079 {
00080   public:
00081 
00082     enum GraphType
00083     {
00084       POLYGON, LINESTRING
00085     };
00086 
00087     typedef std::list<LandREntity*> Entities_t;
00088 
00089   protected:
00090     /**
00091      @brief The VectorDataset associated to this LandRGraph.
00092      */
00093     openfluid::landr::VectorDataset* mp_Vector;
00094 
00095     /**
00096      @brief The geos::geom::GeometryFactory used to build this LandRGraph.
00097      */
00098     const geos::geom::GeometryFactory* mp_Factory;
00099 
00100     /**
00101      @brief A map of the LandREntity of this LandRGraph and sorted by identifier.
00102      */
00103     std::map<int, LandREntity*> m_EntitiesByOfldId;
00104 
00105     /**
00106      @brief A list of the LandREntity of this LandRGraph.
00107      */
00108     Entities_t m_Entities;
00109 
00110     /**
00111      @brief The RasterDataset associated to this LandRGraph.
00112      */
00113     openfluid::landr::RasterDataset* mp_Raster;
00114 
00115     /**
00116      @brief The VectorDataset representation of the RasterDataset associated to this LandRGraph.
00117      */
00118     openfluid::landr::VectorDataset* mp_RasterPolygonized;
00119 
00120     /**
00121      @brief A vector of geos::geom::Polygon representation of the RasterDataset associated to this LandRGraph.
00122      */
00123     std::vector<geos::geom::Polygon*>* mp_RasterPolygonizedPolys;
00124 
00125     static int FileNum;
00126 
00127     LandRGraph();
00128 
00129     /**
00130      @brief Creates a new LandRGraph from a core::GeoVectorValue.
00131      */
00132     LandRGraph(openfluid::core::GeoVectorValue& Val);
00133 
00134     /**
00135      @brief Creates a new LandRGraph from a VectorDataset.
00136      */
00137     LandRGraph(const openfluid::landr::VectorDataset& Vect);
00138 
00139     /**
00140      @brief Adds LandREntity from the associated VectorDataset of this LandRGraph.
00141      */
00142     void addEntitiesFromGeoVector();
00143 
00144     /**
00145      @brief Adds LandREntity from a LandREntity list to this LandRGraph.
00146      */
00147     void addEntitiesFromEntityList(const LandRGraph::Entities_t& Entities);
00148 
00149     /**
00150      @brief Adds a LandREntity to this LandRGraph.
00151      @param Entity The LandREntity to add.
00152      */
00153     virtual void addEntity(LandREntity* Entity) = 0;
00154 
00155     /**
00156      @brief Creates a new LandREntity.
00157      @param Geom A geos::geom::Geometry.
00158      @param OfldId The identifier of the new LandREntity.
00159      */
00160     virtual LandREntity* getNewEntity(const geos::geom::Geometry* Geom,
00161                                       unsigned int OfldId) = 0;
00162 
00163     /**
00164      @brief Returns a geos::planagraph::Node of this LandRGraph from a geos::geom::Coordinate.
00165      @param Coordinate A geos::geom::Coordinate.
00166      @return A geos::planargraph::Node.
00167      */
00168     geos::planargraph::Node* getNode(const geos::geom::Coordinate& Coordinate);
00169 
00170   public:
00171 
00172     /**
00173      @attention Delete also associated RasterPolygonized if present.
00174      */
00175     virtual ~LandRGraph();
00176 
00177   /**
00178    @brief Returns the type of graph.
00179    */
00180     virtual GraphType getType() = 0;
00181 
00182     /**
00183      @brief Returns the LandREntity with OfldId, or 0 if it doesn't exist.
00184      */
00185     virtual LandREntity* getEntity(int OfldId);
00186 
00187     /**
00188      @brief Returns a list of the LandREntity of this LandRGraph.
00189      */
00190     Entities_t getEntities();
00191 
00192     /**
00193      @brief Returns a list of the LandREntity of this LandRGraph and sorted by identifier.
00194      */
00195     Entities_t getOfldIdOrderedEntities();
00196 
00197     /**
00198      @brief Returns a map of the LandREntity of this LandRGraph and their identifiers.
00199      */
00200     std::map<int, LandREntity*> getEntitiesByOfldId();
00201 
00202     /**
00203      @brief Gets the number of LandREntity in the LandRGraph.
00204      */
00205     unsigned int getSize() const;
00206 
00207     /**
00208      @brief Removes from this LandRGraph the nodes of degree 0.
00209      */
00210     void removeUnusedNodes();
00211 
00212     /**
00213      @brief Adds an attribute to this LandRGraph.
00214      @details Doesn't reset if the AttributeName already exists.
00215      @param AttributeName The name of the attribute.
00216      */
00217     void addAttribute(const std::string& AttributeName);
00218 
00219     /**
00220      @brief Removes an attribute to this LandRGraph.
00221      @details Does nothing if AttributeName doesn't exist.
00222      @param AttributeName The name of the attribute.
00223      */
00224     void removeAttribute(const std::string& AttributeName);
00225 
00226     /**
00227      @brief Returns a vector of the names of the attributes of this LandRGraph.
00228      */
00229     std::vector<std::string> getAttributeNames();
00230 
00231     /**
00232      @brief Associates a core::GeoRasterValue to this LandRGraph.
00233      @param Raster A core::GeoRasterValue.
00234      @details Replace associated raster if exists.
00235      */
00236     void addAGeoRasterValue(openfluid::core::GeoRasterValue& Raster);
00237 
00238     /**
00239      @brief Associates a RasterDataset to this LandRGraph.
00240      @param Raster A RasterDataset.
00241      @details Replace associated raster if exists.
00242      */
00243     void addAGeoRasterValue(const openfluid::landr::RasterDataset& Raster);
00244 
00245     /**
00246      @brief Returns true if this LandRGraph has an associated raster, false otherwise.
00247      */
00248     bool hasAnAssociatedRaster();
00249 
00250     /**
00251      @brief Transforms the associated raster value into an openfluid::landr::VectorDataset of polygons.
00252      @return An openfluid::landr::VectorDataset of the created polygons.
00253      */
00254     openfluid::landr::VectorDataset* getRasterPolygonized();
00255 
00256     /**
00257      @brief Transforms the associated raster value into a vector of geos::geom::Polygon.
00258      @return A vector of the created geos::geom::Polygon.
00259      */
00260     std::vector<geos::geom::Polygon*>* getRasterPolygonizedPolys();
00261 
00262     /**
00263      @brief Fetchs the associated raster value corresponding to the LandREntity centroid coordinate.
00264      @param Entity The LandREntity to get the centroid coordinate from.
00265      @return The raster value corresponding to the LandREntity centroid coordinate.
00266      */
00267     virtual float* getRasterValueForEntityCentroid(const LandREntity& Entity);
00268 
00269     /**
00270      @brief Creates a new attribute for all the LandREntity of this LandRGraph, and set for each LandREntity
00271      this attribute value as the raster value corresponding to the LandREntity centroid coordinate.
00272      @param AttributeName The name of the attribute to create.
00273      */
00274     void setAttributeFromRasterValueAtCentroid(const std::string& AttributeName);
00275 
00276     /**
00277      @brief Creates a new attribute for all the LandREntity of this LandRGraph, and set for each LandREntity
00278      this attribute value as a mean of the raster value.
00279      @param AttributeName The name of the attribute to create.
00280      */
00281     virtual void setAttributeFromMeanRasterValues(const std::string& AttributeName)=0;
00282 
00283     /**
00284     @brief Computes the LandREntity neighbours of each LandREntity of this LandRGraph, according to its type.
00285      */
00286     void computeNeighbours();
00287 
00288     /**
00289      @brief Creates on disk a shapefile representing this LandRGraph.
00290      @param FilePath The path where to create the out file.
00291      @param FileName A name for the out file to create, with a .shp extension.
00292      */
00293     void exportToShp(const std::string& FilePath, const std::string& FileName);
00294 
00295     /**
00296      @brief Creates a new attribute for all the LandREntity of this LandRGraph, and set for each LandREntity
00297      this attribute value as the vector value corresponding to the entity OFLD_ID.
00298      @param AttributeName The name of the attribute to create.
00299      @param Vector The Name of the core::GeoVectorValue.
00300      @param Column The column of the core::GeoVectorValue to upload.
00301      */
00302     void setAttributeFromVectorId(const std::string& AttributeName,
00303                                   openfluid::core::GeoVectorValue& Vector,
00304                                   const std::string& Column);
00305 
00306     /**
00307      @brief Creates a new attribute for all the LandREntity of this LandRGraph, and set for each LandREntity
00308      this attribute value as the vector value corresponding to the entity OFLD_ID.
00309      @param AttributeName The name of the attribute to create.
00310      @param Vector The Name of the VectorDataset.
00311      @param Column The column of the core::GeoVectorValue to upload.
00312      */
00313     void setAttributeFromVectorId(const std::string& AttributeName,
00314                                   openfluid::landr::VectorDataset& Vector,
00315                                   const std::string& Column);
00316 
00317     /**
00318      @brief Creates a new attribute for all the LandREntity of this LandRGraph, and set for each LandREntity
00319      this attribute value as the vector value corresponding to the Vector Entity Geometry
00320      @param AttributeName The name of the attribute to create.
00321      @param Vector The Name of the core::GeoVectorValue.
00322      @param Column The column of the core::GeoVectorValue to upload.
00323      @param Thresh The threshold of minimum distance between the core::GeoVectorValue geometry and the LandRGraph geometry.
00324      */
00325     virtual void setAttributeFromVectorLocation(const std::string& AttributeName,
00326                                                 openfluid::core::GeoVectorValue& Vector,
00327                                                 const std::string& Column,double Thresh=0.0001);
00328 
00329     /**
00330      @brief Creates a new attribute for all the LandREntity of this LandRGraph, and set for each LandREntity
00331      this attribute value as the vector value corresponding to the Vector Entity Geometry
00332      @param AttributeName The name of the attribute to create.
00333      @param Vector The Name of the VectorDataset.
00334      @param Column The column of the VectorDataset to upload.
00335      @param Thresh The threshold of minimum distance between the VectorDataset geometry and the LandRGraph geometry.
00336      */
00337     virtual void setAttributeFromVectorLocation(const std::string& AttributeName,
00338                                                 openfluid::landr::VectorDataset& Vector,
00339                                                 const std::string& Column,double Thresh=0.0001);
00340 
00341     /**
00342      @brief Removes a LandREntity with identifier from this LandRGraph.
00343      @details The associated nodes of the LandREntity are also removed.
00344      @param OfldId The identifier.
00345      */
00346      virtual void removeEntity(int OfldId)=0;
00347 
00348      /**
00349       @brief Snap the vertices of this LandRGraph under a threshold.
00350       @param snapTolerance The threshold.
00351       */
00352      void snapVertices(double snapTolerance);
00353 
00354 };
00355 
00356 } } // namespace landr, openfluid
00357 
00358 #endif /* LANDRGRAPH_HPP_ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines