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