isce3  0.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
Raster.h
1 #pragma once
2 
3 #include "forward.h"
4 
5 #include <gdal_priv.h>
6 #include <string>
7 
8 #include "Dataset.h"
9 #include "detail/MemoryMap.h"
10 
11 namespace isce3 { namespace io { namespace gdal {
12 
14 class Raster {
15 public:
16 
18  static
19  std::string defaultDriver() { return Dataset::defaultDriver(); }
20 
27  Raster(const std::string & path, GDALAccess access = GA_ReadOnly);
28 
37  Raster(const isce3::io::IDataSet & dataset, GDALAccess access = GA_ReadOnly);
38 
46  Raster(const std::string & path, int band, GDALAccess access = GA_ReadOnly);
47 
57  Raster(const isce3::io::IDataSet & dataset, int band, GDALAccess access = GA_ReadOnly);
58 
68  Raster(const std::string & path,
69  int width,
70  int length,
71  GDALDataType datatype,
72  const std::string & driver = defaultDriver());
73 
83  template<typename T>
84  Raster(const T * data, int width, int length);
85 
96  template<typename T>
97  Raster(T * data, int width, int length, GDALAccess access = GA_Update);
98 
108  template<typename T>
109  Raster(const T * data,
110  int width,
111  int length,
112  std::size_t colstride,
113  std::size_t rowstride);
114 
125  template<typename T>
126  Raster(T * data,
127  int width,
128  int length,
129  std::size_t colstride,
130  std::size_t rowstride,
131  GDALAccess access = GA_Update);
132 
134  const Dataset & dataset() const { return _dataset; }
135 
137  Dataset & dataset() { return _dataset; }
138 
140  int band() const { return _band; }
141 
143  GDALDataType datatype() const;
144 
146  GDALAccess access() const { return _dataset.access(); }
147 
149  int width() const { return _dataset.width(); }
150 
152  int length() const { return _dataset.length(); }
153 
155  std::string driver() const { return _dataset.driver(); }
156 
163  GeoTransform getGeoTransform() const { return _dataset.getGeoTransform(); }
164 
170  void setGeoTransform(const GeoTransform & transform) { _dataset.setGeoTransform(transform); }
171 
177  isce3::core::ProjectionBase * getProjection() const { return _dataset.getProjection(); }
178 
184  void setProjection(const isce3::core::ProjectionBase * proj) { _dataset.setProjection(proj); }
185 
187  double x0() const { return _dataset.x0(); }
188 
190  double y0() const { return _dataset.y0(); }
191 
193  double dx() const { return _dataset.dx(); }
194 
196  double dy() const { return _dataset.dy(); }
197 
208  template<typename T>
209  void readPixel(T * dst, int col, int row) const;
210 
221  template<typename T>
222  void writePixel(const T * src, int col, int row);
223 
233  template<typename T>
234  void readLine(T * dst, int row) const;
235 
245  template<typename T>
246  void writeLine(const T * src, int row);
247 
258  template<typename T>
259  void readLines(T * dst, int first_row, int num_rows) const;
260 
271  template<typename T>
272  void writeLines(const T * src, int first_row, int num_rows);
273 
286  template<typename T>
287  void readBlock(T * dst, int first_col, int first_row, int num_cols, int num_rows) const;
288 
301  template<typename T>
302  void writeBlock(const T * src, int first_col, int first_row, int num_cols, int num_rows);
303 
312  template<typename T>
313  void readAll(T * dst) const;
314 
323  template<typename T>
324  void writeAll(const T * src);
325 
327  GDALRasterBand * get() { return _dataset._dataset->GetRasterBand(_band); }
328 
330  const GDALRasterBand * get() const { return _dataset._dataset->GetRasterBand(_band); }
331 
340  Buffer memmap();
341 
353  template<typename T>
355 
356  friend class Dataset;
357 
358 private:
359 
360  Raster(const Dataset & dataset, int band);
361 
362  template<typename T>
363  GDALDataType getIODataType() const;
364 
365  template<typename T>
366  CPLErr readwriteBlock(T * buf,
367  int first_col,
368  int first_row,
369  int num_cols,
370  int num_rows,
371  GDALRWFlag rwflag) const;
372 
373  Dataset _dataset;
374  int _band = 1;
375 
376  // _mmap must be constructed after _dataset and destructed before _dataset
377  detail::MemoryMap _mmap;
378 };
379 
380 }}}
381 
382 #define ISCE_IO_GDAL_RASTER_ICC
383 #include "Raster.icc"
384 #undef ISCE_IO_GDAL_RASTER_ICC
void readPixel(T *dst, int col, int row) const
Read a single pixel value from the raster.
Definition: Raster.icc:127
void setGeoTransform(const GeoTransform &)
Set geotransform.
Definition: Dataset.cpp:156
void writeLine(const T *src, int row)
Write a line of pixel data to the raster.
Definition: Raster.icc:148
int length() const
Number of rows.
Definition: Dataset.h:154
void setProjection(const isce3::core::ProjectionBase *)
Set spatial reference system.
Definition: Dataset.cpp:185
GDALAccess access() const
Access mode.
Definition: Dataset.h:148
Definition: MemoryMap.h:11
int band() const
Band index (1-based)
Definition: Raster.h:140
static std::string defaultDriver()
Default GDAL driver for raster creation.
Definition: Raster.h:19
isce3::core::ProjectionBase * getProjection() const
Get spatial reference system.
Definition: Raster.h:177
void writeLines(const T *src, int first_row, int num_rows)
Write one or more lines of pixel data to the raster.
Definition: Raster.icc:162
std::string driver() const
Driver name.
Definition: Dataset.h:160
double y0() const
Upper edge of upper-most line in projection coordinates.
Definition: Dataset.h:202
static std::string defaultDriver()
Default GDAL driver for dataset creation.
Definition: Dataset.h:22
void setGeoTransform(const GeoTransform &transform)
Set geotransform.
Definition: Raster.h:170
double x0() const
Left edge of left-most pixel in projection coordinates.
Definition: Raster.h:187
std::string driver() const
Driver name.
Definition: Raster.h:155
void setProjection(const isce3::core::ProjectionBase *proj)
Set spatial reference system.
Definition: Raster.h:184
double dx() const
Pixel width in projection coordinates.
Definition: Dataset.h:205
int width() const
Number of columns.
Definition: Dataset.h:151
double y0() const
Upper edge of upper-most line in projection coordinates.
Definition: Raster.h:190
double dy() const
Line height in projection coordinates.
Definition: Raster.h:196
Interface to 2-D memory array.
Definition: Buffer.h:13
Dataset & dataset()
Get the dataset containing the raster.
Definition: Raster.h:137
isce3::core::ProjectionBase * getProjection() const
Get spatial reference system.
Definition: Dataset.cpp:169
Our derived dataset structure that includes utility functions.
Definition: IH5.h:44
Abstract base class for individual projections.
Definition: Projections.h:22
GDALDataType datatype() const
Datatype identifier.
Definition: Raster.icc:120
void writePixel(const T *src, int col, int row)
Write a single pixel value to the raster.
Definition: Raster.icc:134
void readAll(T *dst) const
Read all pixel data from the raster.
Definition: Raster.icc:201
void writeBlock(const T *src, int first_col, int first_row, int num_cols, int num_rows)
Write a block of pixel data to the raster.
Definition: Raster.icc:183
Buffer memmap()
Create a virtual memory mapping of the raster.
Definition: Raster.icc:214
int length() const
Number of rows.
Definition: Raster.h:152
Transform coefficients for transforming from (pixel, line) coordinates in raster space to (x...
Definition: GeoTransform.h:15
Raster(const std::string &path, GDALAccess access=GA_ReadOnly)
Open an existing file containing a single raster band as a GDAL raster.
Definition: Raster.icc:39
double dy() const
Line height in projection coordinates.
Definition: Dataset.h:208
double dx() const
Pixel width in projection coordinates.
Definition: Raster.h:193
Wrapper for GDALRasterBand representing a single raster.
Definition: Raster.h:14
Buffer with static type information.
Definition: Buffer.h:136
int width() const
Number of columns.
Definition: Raster.h:149
GDALAccess access() const
Access mode.
Definition: Raster.h:146
void readLines(T *dst, int first_row, int num_rows) const
Read one or more lines of pixel data from the raster.
Definition: Raster.icc:155
void readLine(T *dst, int row) const
Read a line of pixel data from the raster.
Definition: Raster.icc:141
void readBlock(T *dst, int first_col, int first_row, int num_cols, int num_rows) const
Read a block of pixel data from the raster.
Definition: Raster.icc:169
const Dataset & dataset() const
Get the dataset containing the raster.
Definition: Raster.h:134
Wrapper for GDALDataset representing a collection of associated Raster bands.
Definition: Dataset.h:17
GeoTransform getGeoTransform() const
Get transform from raster coordinates (pixel, line) to projected coordinates (x, y) ...
Definition: Dataset.cpp:149
GeoTransform getGeoTransform() const
Get transform from raster coordinates (pixel, line) to projected coordinates (x, y) ...
Definition: Raster.h:163
double x0() const
Left edge of left-most pixel in projection coordinates.
Definition: Dataset.h:199
void writeAll(const T *src)
Write all pixel data to the raster.
Definition: Raster.icc:208

Generated for ISCE3.0 by doxygen 1.8.5.