All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RasterDataset.hpp
Go to the documentation of this file.
1 /*
2 
3  This file is part of OpenFLUID software
4  Copyright(c) 2007, INRA - Montpellier SupAgro
5 
6 
7  == GNU General Public License Usage ==
8 
9  OpenFLUID is free software: you can redistribute it and/or modify
10  it under the terms of the GNU General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  (at your option) any later version.
13 
14  OpenFLUID is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with OpenFLUID. If not, see <http://www.gnu.org/licenses/>.
21 
22 
23  == Other Usage ==
24 
25  Other Usage means a use of OpenFLUID that is inconsistent with the GPL
26  license, and requires a written agreement between You and INRA.
27  Licensees for Other Usage of OpenFLUID may use this file in accordance
28  with the terms contained in the written agreement between You and INRA.
29 
30 */
31 
32 /**
33  @file RasterDataset.hpp
34 
35  @author Aline LIBRES <aline.libres@gmail.com>
36  @author Michael RABOTIN <michael.rabotin@supagro.inra.fr>
37  */
38 
39 #ifndef __OPENFLUID_LANDR_RASTERDATASET_HPP__
40 #define __OPENFLUID_LANDR_RASTERDATASET_HPP__
41 
42 #include <map>
43 #include "gdal_priv.h"
44 #include <ogrsf_frmts.h>
45 #include "cpl_conv.h" // for CPLMalloc()
46 #include <openfluid/dllexport.hpp>
47 
48 namespace geos { namespace geom {
49 class Coordinate;
50 } }
51 namespace openfluid {
52 
53 namespace core {
54 class GeoRasterValue;
55 }
56 
57 namespace landr {
58 
59 class VectorDataset;
60 /**
61  @brief Interface for managing Raster Data format.
62 */
64 {
65  private:
66 
67  /**
68  @brief The GDALDataset associated to this RasterDataset.
69  */
70  GDALDataset* mp_Dataset;
71 
72  /**
73  @brief The affine transformation coefficients of this RasterDataset.
74  */
75  double* mp_GeoTransform;
76 
77  /**
78  @brief A map of the related VectorDataset to this RasterDataset.
79  */
80  std::map<unsigned int, openfluid::landr::VectorDataset*> mp_PolygonizedByRasterBandIndex;
81 
82  /**
83  @brief Computes the affine transformation coefficients of this RasterDataset.
84  */
85  void computeGeoTransform();
86 
87  public:
88 
89  /**
90  @brief Create a virtual (in memory) copy of Value GDALDataset
91  @param Value The GeoRasterValue to copy
92  @throw openfluid::base::FrameworkException if fails
93  */
95 
96  /**
97  @brief Copy constructor
98  @throw openfluid::base::FrameworkException if fails
99  */
100  RasterDataset(const RasterDataset& Other);
101 
102  /**
103  @brief Delete the virtual GDALDataset
104  */
105  ~RasterDataset();
106 
107  /**
108  @brief Returns the GDALDataset related to this RasterDataset.
109  */
110  GDALDataset* source();
111 
112  /**
113  @brief Returns the const GDALDataset related to this RasterDataset.
114  */
115  GDALDataset* source() const;
116 
117  /**
118  @brief Gets the RasterBand indexed with RasterBandIndex of the dataset.
119  @details Is owned by its dataset, should never be destroyed with the C++ delete operator.
120  @param RasterBandIndex The rasterBand to get, default 1
121  */
122  GDALRasterBand* rasterBand(unsigned int RasterBandIndex = 1);
123 
124  /**
125  @brief Returns the column and line index of a pixel from the coordinate of the pixel.
126  @param Coo A geos::geom::Coordinate.
127  @return A pair of the column and line index of the pixel in this RasterDataset.
128  */
129  std::pair<int, int> getPixelFromCoordinate(geos::geom::Coordinate Coo);
130 
131  /**
132  @brief Returns the geos::geom::Coordinate origin of this RasterDataset.
133  */
134  geos::geom::Coordinate* computeOrigin();
135 
136  /**
137  @brief Returns the pixel width of this RasterDataset.
138  */
139  double getPixelWidth();
140 
141  /**
142  @brief Returns the pixel height of this RasterDataset.
143  */
144  double getPixelHeight();
145 
146  /**
147  @brief Returns a vector of the pixel values of a line of this RasterDataset.
148  @param LineIndex The line index to get the pixel values.
149  @param RasterBandIndex The raster band index (default is 1).
150  @return A vector of pixel values.
151  */
152  std::vector<float> getValuesOfLine(int LineIndex,
153  unsigned int RasterBandIndex = 1);
154  /**
155  @brief Returns a vector of the pixel values of a column of this RasterDataset.
156  @param ColIndex The column index to get the pixel values.
157  @param RasterBandIndex The raster band index (default is 1).
158  @return A vector of pixel values.
159  */
160  std::vector<float> getValuesOfColumn(int ColIndex,
161  unsigned int RasterBandIndex = 1);
162 
163  /**
164  @brief Returns the pixel value with column and line index.
165  @param ColIndex The column index.
166  @param LineIndex The line index.
167  @param RasterBandIndex The raster band index (default is 1).
168  @return The pixel value.
169  */
170  float getValueOfPixel(int ColIndex,
171  int LineIndex,
172  unsigned int RasterBandIndex = 1);
173 
174  /**
175  @brief Returns the pixel value with coordinate.
176  @param Coo The geos::geom::Coordinate.
177  @param RasterBandIndex The raster band index (default is 1).
178  @return The pixel value.
179  */
180  float getValueOfCoordinate(geos::geom::Coordinate Coo,
181  unsigned int RasterBandIndex = 1);
182 
183  /**
184  @brief Creates a new VectorDataset with polygons for all connected regions of pixels
185  in the raster sharing a common pixel value.
186  @details Use openfluid::landr::VectorDataset::copyToDisk() to keep this vectorDataset on disk
187  @param FileName The name of the new VectorDataset.
188  @param FieldName The name of the field to be created for storing the pixel value,
189  limited to 10 characters (or will be truncated).
190  Default is set to "PixelVal". Type of field is OFTReal .
191  @param RasterBandIndex The raster band index (default is 1).
192  @return The newly created VectorDataset.
193  */
194  openfluid::landr::VectorDataset* polygonize(const std::string& FileName,
195  std::string FieldName = "",
196  unsigned int RasterBandIndex = 1);
197 
198  static std::string getDefaultPolygonizedFieldName();
199 
200  /**
201  @brief Returns the OGREnvelope associated to this RasterDataset.
202  */
203  OGREnvelope envelope();
204 
205 };
206 
207 } } // namespaces openfluid, landr
208 
209 #endif /* __OPENFLUID_LANDR_RASTERDATASET_HPP__ */
Interface for managing Vector Data format.
Definition: VectorDataset.hpp:64
Definition: GeoRasterValue.hpp:55
#define OPENFLUID_API
Definition: dllexport.hpp:87
Interface for managing Raster Data format.
Definition: RasterDataset.hpp:63