1#ifndef ISCE_IO_GDAL_RASTER_ICC
2#error "Raster.icc is an implementation detail of Raster.h"
5#include <isce3/except/Error.h>
8#include "detail/GDALDataTypeUtil.h"
10namespace isce3 {
namespace io {
namespace gdal {
15void checkSingleBand(
const Dataset & dataset)
17 if (dataset.bands() == 0) {
18 throw isce3::except::RuntimeError(ISCE_SRCINFO(),
"dataset contains no raster bands");
20 if (dataset.bands() > 1) {
21 std::string errmsg =
"dataset contains multiple raster bands - "
22 "please specify raster band index";
23 throw isce3::except::RuntimeError(ISCE_SRCINFO(), errmsg);
28void checkValidBand(
const Dataset & dataset,
int band)
30 if (band < 1 || band > dataset.bands()) {
31 std::string errmsg =
"raster band index (" + std::to_string(band) +
") is out of range";
32 throw isce3::except::OutOfRange(ISCE_SRCINFO(), errmsg);
43 detail::checkSingleBand(_dataset);
51 detail::checkSingleBand(_dataset);
60 detail::checkValidBand(_dataset,
band);
69 detail::checkValidBand(_dataset,
band);
77 const std::string &
driver)
101 std::size_t colstride,
102 std::size_t rowstride)
104 _dataset(data,
width,
length, 1, colstride, rowstride, 0)
112 std::size_t colstride,
113 std::size_t rowstride,
122 return _dataset._dataset->GetRasterBand(_band)->GetRasterDataType();
172 throw isce3::except::InvalidArgument(ISCE_SRCINFO(),
"destination address may not be null");
175 CPLErr status = readwriteBlock(dst, first_col, first_row, num_cols, num_rows, GF_Read);
176 if (status != CE_None) {
177 throw isce3::except::GDALError(ISCE_SRCINFO(),
"error while reading from raster");
185 if (
access() == GA_ReadOnly) {
186 throw isce3::except::RuntimeError(ISCE_SRCINFO(),
"attempted to write to read-only raster");
190 throw isce3::except::InvalidArgument(ISCE_SRCINFO(),
"source address may not be null");
193 CPLErr status = readwriteBlock(
const_cast<T *
>(src), first_col, first_row, num_cols, num_rows, GF_Write);
194 if (status != CE_None) {
195 throw isce3::except::GDALError(ISCE_SRCINFO(),
"error while writing to raster");
218 _mmap = detail::MemoryMap(
get(),
access());
222 std::array<std::size_t, 2> strides = { _mmap.rowstride(), _mmap.colstride() };
232 return buffer.
cast<T>();
244GDALDataType Raster::getIODataType()
const
246 return detail::Type2GDALDataType<T>::datatype;
251GDALDataType Raster::getIODataType<void>()
const
258CPLErr Raster::readwriteBlock(T * buf,
263 GDALRWFlag rwflag)
const
265 GDALDataType gdt = getIODataType<T>();
266 if (gdt == GDT_Unknown) {
267 throw isce3::except::RuntimeError(ISCE_SRCINFO(),
"type is not mappable to GDALDataType");
271 throw isce3::except::InvalidArgument(ISCE_SRCINFO(),
"block width must be > 0");
275 throw isce3::except::InvalidArgument(ISCE_SRCINFO(),
"block length must be > 0");
278 if (first_col < 0 || first_row < 0 || first_col + num_cols >
width() || first_row + num_rows >
length()) {
279 throw isce3::except::OutOfRange(ISCE_SRCINFO(),
"out of bounds raster access");
282 return _dataset._dataset->GetRasterBand(_band)->RasterIO(
283 rwflag, first_col, first_row, num_cols, num_rows, buf, num_cols, num_rows, gdt, 0, 0);
Our derived dataset structure that includes utility functions.
Definition IH5.h:41
Interface to 2-D memory array.
Definition Buffer.h:13
constexpr TypedBuffer< T > cast() const
Cast to typed buffer.
Definition Buffer.icc:63
Wrapper for GDALDataset representing a collection of associated Raster bands.
Definition Dataset.h:17
GDALDataType datatype() const
Datatype identifier.
Definition Raster.icc:120
const Dataset & dataset() const
Get the dataset containing the raster.
Definition Raster.h:134
void readPixel(T *dst, int col, int row) const
Read a single pixel value from the raster.
Definition Raster.icc:127
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
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
int length() const
Number of rows.
Definition Raster.h:152
std::string driver() const
Driver name.
Definition Raster.h:155
int width() const
Number of columns.
Definition Raster.h:149
int band() const
Band index (1-based)
Definition Raster.h:140
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
void writePixel(const T *src, int col, int row)
Write a single pixel value to the raster.
Definition Raster.icc:134
Buffer memmap()
Create a virtual memory mapping of the raster.
Definition Raster.icc:214
void writeAll(const T *src)
Write all pixel data to the raster.
Definition Raster.icc:208
void writeLine(const T *src, int row)
Write a line of pixel data to the raster.
Definition Raster.icc:148
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
void readLine(T *dst, int row) const
Read a line of pixel data from the raster.
Definition Raster.icc:141
GDALRasterBand * get()
Get the underlying GDALRasterBand pointer.
Definition Raster.h:327
void readAll(T *dst) const
Read all pixel data from the raster.
Definition Raster.icc:201
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
GDALAccess access() const
Access mode.
Definition Raster.h:146
Buffer with static type information.
Definition Buffer.h:136
The isce3::io namespace.
Definition Constants.h:14
base interpolator is an abstract base class
Definition BinarySearchFunc.cpp:5