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