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