landr/RasterDataset.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 RasterDataset.hpp
00034  \brief Header of ...
00035 
00036  \author Aline LIBRES <aline.libres@gmail.com>
00037  */
00038 
00039 #ifndef RASTERDATASET_HPP_
00040 #define RASTERDATASET_HPP_
00041 
00042 #include <map>
00043 #include "gdal_priv.h"
00044 #include "cpl_conv.h" // for CPLMalloc()
00045 #include <openfluid/dllexport.hpp>
00046 
00047 namespace geos { namespace geom {
00048 class Coordinate;
00049 } }
00050 namespace openfluid {
00051 
00052 namespace core {
00053 class GeoRasterValue;
00054 }
00055 
00056 namespace landr {
00057 
00058 class VectorDataset;
00059 /**
00060  @brief Interface for managing Raster Data format.
00061  *
00062  */
00063 class DLLEXPORT RasterDataset
00064 {
00065   private:
00066 
00067     /**
00068      @brief The GDALDataset associated to this RasterDataset.
00069      */
00070     GDALDataset* mp_Dataset;
00071 
00072     /**
00073      @brief The affine transformation coefficients of this RasterDataset.
00074      */
00075     double* mp_GeoTransform;
00076 
00077     /**
00078      @brief A map of the related VectorDataset to this RasterDataset.
00079      */
00080     std::map<unsigned int, openfluid::landr::VectorDataset*> mp_PolygonizedByRasterBandIndex;
00081 
00082     /**
00083      @brief Computes the affine transformation coefficients of this RasterDataset.
00084      */
00085     void computeGeoTransform();
00086 
00087   public:
00088 
00089     /**
00090      @brief Create a virtual (in memory) copy of Value GDALDataset
00091      @param Value The GeoRasterValue to copy
00092      @throw openfluid::base::OFException if fails
00093      */
00094     RasterDataset(openfluid::core::GeoRasterValue& Value);
00095 
00096     /**
00097      @brief Copy constructor
00098      @throw openfluid::base::OFException if fails
00099      */
00100     RasterDataset(const RasterDataset& Other);
00101 
00102     /**
00103      @brief Delete the virtual GDALDataset
00104      */
00105     ~RasterDataset();
00106 
00107     /**
00108      @brief Returns the GDALDataset related to this RasterDataset.
00109      */
00110     GDALDataset* getDataset();
00111 
00112     /**
00113      @brief Returns the const GDALDataset related to this RasterDataset.
00114      */
00115     GDALDataset* getDataset() const;
00116 
00117     /**
00118      @brief Gets the RasterBand indexed with RasterBandIndex of the dataset.
00119      @details Is owned by its dataset, should never be destroyed with the C++ delete operator.
00120      @param RasterBandIndex The rasterBand to get, default 1
00121      */
00122     GDALRasterBand* getRasterBand(unsigned int RasterBandIndex = 1);
00123 
00124     /**
00125      @brief Returns the column and line index of a pixel from the coordinate of the pixel.
00126      @param Coo A geos::geom::Coordinate.
00127      @return A pair of the column and line index of the pixel in this RasterDataset.
00128      */
00129     std::pair<int, int> getPixelFromCoordinate(geos::geom::Coordinate Coo);
00130 
00131     /**
00132      @brief Returns the geos::geom::Coordinate origin of this RasterDataset.
00133      */
00134     geos::geom::Coordinate* getOrigin();
00135 
00136     /**
00137      @brief Returns the pixel width of this RasterDataset.
00138      */
00139     double getPixelWidth();
00140 
00141     /**
00142      @brief Returns the pixel height of this RasterDataset.
00143      */
00144     double getPixelHeight();
00145 
00146     /**
00147      @brief Returns a vector of the pixel values of a line of this RasterDataset.
00148      @param LineIndex The line index to get the pixel values.
00149      @param RasterBandIndex The raster band index (default is 1).
00150      @return A vector of pixel values.
00151      */
00152     std::vector<float> getValuesOfLine(int LineIndex,
00153                                        unsigned int RasterBandIndex = 1);
00154     /**
00155      @brief Returns a vector of the pixel values of a column of this RasterDataset.
00156      @param ColIndex The column index to get the pixel values.
00157      @param RasterBandIndex The raster band index (default is 1).
00158      @return A vector of pixel values.
00159      */
00160     std::vector<float> getValuesOfColumn(int ColIndex,
00161                                          unsigned int RasterBandIndex = 1);
00162 
00163     /**
00164      @brief Returns the pixel value with column and line index.
00165      @param ColIndex The column index.
00166      @param LineIndex The line index.
00167      @param RasterBandIndex The raster band index (default is 1).
00168      @return The pixel value.
00169      */
00170     float getValueOfPixel(int ColIndex,
00171                           int LineIndex,
00172                           unsigned int RasterBandIndex = 1);
00173 
00174     /**
00175      @brief Returns the pixel value with coordinate.
00176      @param Coo The geos::geom::Coordinate.
00177      @param RasterBandIndex The raster band index (default is 1).
00178      @return The pixel value.
00179      */
00180     float getValueOfCoordinate(geos::geom::Coordinate Coo,
00181                                unsigned int RasterBandIndex = 1);
00182 
00183     /**
00184      @brief Creates a new VectorDataset with polygons for all connected regions of pixels in the raster sharing a common pixel value.
00185      @details Use openfluid::landr::VectorDataset::copyToDisk() to keep this vectorDataset on disk
00186      @param FileName The name of the new VectorDataset.
00187      @param FieldName The name of the field to be created for storing the pixel value, limited to 10 characters (or will be truncated).
00188      Default is set to "PixelVal". Type of field is OFTReal .
00189      @param RasterBandIndex The raster band index (default is 1).
00190      @return The newly created VectorDataset.
00191      */
00192     openfluid::landr::VectorDataset* polygonize(const std::string& FileName,
00193                                                 std::string FieldName = "",
00194                                                 unsigned int RasterBandIndex = 1);
00195 
00196     static std::string getDefaultPolygonizedFieldName();
00197 };
00198 
00199 } } // namespaces openfluid, landr
00200 
00201 #endif /* RASTERDATASET_HPP_ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines