Manual for OpenFLUID 2.1.10

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 /**
34  @file RasterDataset.hpp
35 
36  @author Aline LIBRES <aline.libres@gmail.com>
37  @author Michael RABOTIN <michael.rabotin@supagro.inra.fr>
38 */
39 
40 
41 #ifndef __OPENFLUID_LANDR_RASTERDATASET_HPP__
42 #define __OPENFLUID_LANDR_RASTERDATASET_HPP__
43 
44 
45 #include <map>
46 
47 #include <gdal_priv.h>
48 #include <ogrsf_frmts.h>
49 #include <cpl_conv.h> // for CPLMalloc()
50 
51 #include <openfluid/dllexport.hpp>
52 
53 
54 namespace geos { namespace geom {
55 class Coordinate;
56 } }
57 
58 
59 namespace openfluid {
60 
61 
62 namespace core {
63 class GeoRasterValue;
64 }
65 
66 namespace landr {
67 
68 class VectorDataset;
69 
70 
71 /**
72  @brief Interface for managing Raster Data format.
73 */
75 {
76  private:
77 
78  /**
79  @brief The GDALDataset associated to this RasterDataset.
80  */
81  GDALDataset* mp_Dataset;
82 
83  /**
84  @brief The affine transformation coefficients of this RasterDataset.
85  */
86  double* mp_GeoTransform;
87 
88  /**
89  @brief A map of the related VectorDataset to this RasterDataset.
90  */
91  std::map<unsigned int, openfluid::landr::VectorDataset*> mp_PolygonizedByRasterBandIndex;
92 
93  /**
94  @brief Computes the affine transformation coefficients of this RasterDataset.
95  */
96  void computeGeoTransform();
97 
98  public:
99 
100  /**
101  @brief Create a virtual (in memory) copy of Value GDALDataset
102  @param Value The GeoRasterValue to copy
103  @throw openfluid::base::FrameworkException if fails
104  */
106 
107  /**
108  @brief Copy constructor
109  @throw openfluid::base::FrameworkException if fails
110  */
111  RasterDataset(const RasterDataset& Other);
112 
113  /**
114  @brief Delete the virtual GDALDataset
115  */
116  ~RasterDataset();
117 
118  /**
119  @brief Returns the GDALDataset related to this RasterDataset.
120  */
121  GDALDataset* source();
122 
123  /**
124  @brief Returns the const GDALDataset related to this RasterDataset.
125  */
126  GDALDataset* source() const;
127 
128  /**
129  @brief Gets the RasterBand indexed with RasterBandIndex of the dataset.
130  @details Is owned by its dataset, should never be destroyed with the C++ delete operator.
131  @param RasterBandIndex The rasterBand to get, default 1
132  */
133  GDALRasterBand* rasterBand(unsigned int RasterBandIndex = 1);
134 
135  /**
136  @brief Returns the column and line index of a pixel from the coordinate of the pixel.
137  @param Coo A geos::geom::Coordinate.
138  @return A pair of the column and line index of the pixel in this RasterDataset.
139  */
140  std::pair<int, int> getPixelFromCoordinate(geos::geom::Coordinate Coo);
141 
142  /**
143  @brief Returns the geos::geom::Coordinate origin of this RasterDataset.
144  */
145  geos::geom::Coordinate* computeOrigin();
146 
147  /**
148  @brief Returns the pixel width of this RasterDataset.
149  */
150  double getPixelWidth();
151 
152  /**
153  @brief Returns the pixel height of this RasterDataset.
154  */
155  double getPixelHeight();
156 
157  /**
158  @brief Returns a vector of the pixel values of a line of this RasterDataset.
159  @param LineIndex The line index to get the pixel values.
160  @param RasterBandIndex The raster band index (default is 1).
161  @return A vector of pixel values.
162  */
163  std::vector<float> getValuesOfLine(int LineIndex,
164  unsigned int RasterBandIndex = 1);
165  /**
166  @brief Returns a vector of the pixel values of a column of this RasterDataset.
167  @param ColIndex The column index to get the pixel values.
168  @param RasterBandIndex The raster band index (default is 1).
169  @return A vector of pixel values.
170  */
171  std::vector<float> getValuesOfColumn(int ColIndex,
172  unsigned int RasterBandIndex = 1);
173 
174  /**
175  @brief Returns the pixel value with column and line index.
176  @param ColIndex The column index.
177  @param LineIndex The line index.
178  @param RasterBandIndex The raster band index (default is 1).
179  @return The pixel value.
180  */
181  float getValueOfPixel(int ColIndex,
182  int LineIndex,
183  unsigned int RasterBandIndex = 1);
184 
185  /**
186  @brief Returns the pixel value with coordinate.
187  @param Coo The geos::geom::Coordinate.
188  @param RasterBandIndex The raster band index (default is 1).
189  @return The pixel value.
190  */
191  float getValueOfCoordinate(geos::geom::Coordinate Coo, unsigned int RasterBandIndex = 1);
192 
193  /**
194  @brief Creates a new VectorDataset with polygons for all connected regions of pixels
195  in the raster sharing a common pixel value.
196  @details Use openfluid::landr::VectorDataset::copyToDisk() to keep this vectorDataset on disk
197  @param FileName The name of the new VectorDataset.
198  @param FieldName The name of the field to be created for storing the pixel value,
199  limited to 10 characters (or will be truncated).
200  Default is set to "PixelVal". Type of field is OFTReal .
201  @param RasterBandIndex The raster band index (default is 1).
202  @return The newly created VectorDataset.
203  */
204  openfluid::landr::VectorDataset* polygonize(const std::string& FileName,
205  std::string FieldName = "",
206  unsigned int RasterBandIndex = 1);
207 
208  static std::string getDefaultPolygonizedFieldName();
209 
210  /**
211  @brief Returns the OGREnvelope associated to this RasterDataset.
212  */
213  OGREnvelope envelope();
214 
215 };
216 
217 
218 } } // namespaces
219 
220 #endif /* __OPENFLUID_LANDR_RASTERDATASET_HPP__ */
Definition: ApplicationException.hpp:47
Interface for managing Vector Data format.
Definition: VectorDataset.hpp:64
Definition: GeoRasterValue.hpp:58
Definition: LandREntity.hpp:53
#define OPENFLUID_API
Definition: dllexport.hpp:86
Interface for managing Raster Data format.
Definition: RasterDataset.hpp:74