16 #include <unordered_map>
19 #include <gdal_priv.h>
21 #include <ogr_spatialref.h>
22 #include "Constants.h"
23 #include <isce3/core/Matrix.h>
25 #include <isce3/io/gdal/Raster.h>
38 Raster() {_dataset =
nullptr;};
41 Raster(
const std::string& fname, GDALAccess
access = GA_ReadOnly);
55 template<
typename T>
Raster(pyre::grid::View<T> &view);
59 template<
typename T>
Raster(
const std::string& fname,
const std::vector<T>& buffer,
size_t length) :
61 template<
typename T>
Raster(
const std::string& fname,
const std::valarray<T>& buffer,
size_t length) :
65 Raster(
const std::string& fname,
const std::vector<Raster>& rastVec);
74 Raster(GDALDataset *inputDataset,
bool owner=
true);
77 inline void initFromPointer(
void* ptr, GDALDataType
dtype,
size_t width,
size_t length,
size_t pixeloffset,
size_t lineoffset);
86 inline size_t length()
const {
return _dataset->GetRasterYSize(); }
89 inline size_t width()
const {
return _dataset->GetRasterXSize(); }
92 inline size_t numBands()
const {
return _dataset->GetRasterCount(); }
95 inline GDALAccess
access()
const {
return _dataset->GetAccess(); }
98 inline GDALDataset*
dataset()
const {
return _dataset; }
103 inline void dataset(GDALDataset* ds) { _dataset=ds; }
108 inline GDALDataType
dtype(
const size_t band=1)
const {
return _dataset->GetRasterBand(band)->GetRasterDataType(); }
116 inline void open(
const std::string &fname, GDALAccess
access);
125 inline void addRawBandToVRT(
const std::string &fname, GDALDataType dtype);
130 template<
typename T>
void getSetValue(T& buffer,
size_t xidz,
size_t yidx,
size_t band, GDALRWFlag);
131 template<
typename T>
void getValue(T& buffer,
size_t xidx,
size_t yidx,
size_t band = 1);
132 template<
typename T>
void setValue(T& buffer,
size_t xidx,
size_t yidx,
size_t band = 1);
136 template<
typename T>
void getSetLine(T* buffer,
size_t yidx,
size_t iowidth,
size_t band, GDALRWFlag iodir);
138 template<
typename T>
void getLine(T* buffer,
size_t yidx,
size_t iowidth,
size_t band = 1);
139 template<
typename T>
void getLine(std::vector<T>& vec,
size_t yidx,
size_t band = 1);
140 template<
typename T>
void getLine(std::valarray<T>& arr,
size_t yidx,
size_t band = 1);
142 template<
typename T>
void setLine(T* buffer,
size_t yidx,
size_t iowidth,
size_t band = 1);
143 template<
typename T>
void setLine(std::vector<T>& vec,
size_t yidx,
size_t band = 1);
144 template<
typename T>
void setLine(std::valarray<T>& arr,
size_t yidx,
size_t band = 1);
148 template<
typename T>
void getSetBlock(T* buffer,
size_t xidx,
size_t yidx,
size_t iowidth,
size_t iolength,
size_t band, GDALRWFlag iodir);
150 template<
typename T>
void getBlock(T* buffer,
size_t xidx,
size_t yidx,
size_t iowidth,
size_t iolength,
size_t band = 1);
151 template<
typename T>
void getBlock(std::vector<T>& vec,
size_t xidx,
size_t yidx,
size_t iowidth,
size_t iolength,
size_t band = 1);
152 template<
typename T>
void getBlock(std::valarray<T>& arr,
size_t xidx,
size_t yidx,
size_t iowidth,
size_t iolength,
size_t band = 1);
154 template<
typename T>
void setBlock(T* buffer,
size_t xidx,
size_t yidx,
size_t iowidth,
size_t iolength,
size_t band = 1);
155 template<
typename T>
void setBlock(std::vector<T>& vec,
size_t xidx,
size_t yidx,
size_t iowidth,
size_t iolength,
size_t band = 1);
156 template<
typename T>
void setBlock(std::valarray<T>& arr,
size_t xidx,
size_t yidx,
size_t iowidth,
size_t iolength,
size_t band = 1);
164 template<
typename T>
void getSetBlock(pyre::grid::View<T>& view,
size_t xidx,
size_t yidx,
size_t band, GDALRWFlag iodir);
165 template<
typename T>
void getBlock(pyre::grid::View<T>& view,
size_t xidx,
size_t yidx,
size_t band = 1);
166 template<
typename T>
void setBlock(pyre::grid::View<T>& view,
size_t xidx,
size_t yidx,
size_t band = 1);
183 inline double x0()
const;
185 inline double y0()
const;
187 inline double dx()
const;
189 inline double dy()
const;
192 GDALDataset * _dataset;
196 #define ISCE_IO_RASTER_ICC
197 #include "Raster.icc"
198 #undef ISCE_IO_RASTER_ICC
void addBandToVRT(GDALRasterBand *inBand)
Add a GDALRasterBand to VRT.
Definition: Raster.icc:173
void dataset(GDALDataset *ds)
GDALDataset pointer setter.
Definition: Raster.h:103
void setBlock(T *buffer, size_t xidx, size_t yidx, size_t iowidth, size_t iolength, size_t band=1)
Write block of data to given band from buffer, vector, or valarray.
Definition: Raster.icc:424
void getLine(T *buffer, size_t yidx, size_t iowidth, size_t band=1)
Read one line of data from given band to buffer, vector, or valarray.
Definition: Raster.icc:288
void setGeoTransform(double *arr)
Set Raster GeoTransform from buffer, vector, or valarray.
Definition: Raster.icc:554
int getEPSG()
Return EPSG code corresponding to raster.
Definition: Raster.cpp:142
const std::string defaultGDALDriver
Default GDAL driver used by Raster for creation.
Definition: Constants.h:18
bool match(const Raster &rast) const
Check dimensions compatibility with another raster.
Definition: Raster.h:113
double dx() const
Return EW pixel spacing of Raster.
Definition: Raster.icc:631
void getSetLine(T *buffer, size_t yidx, size_t iowidth, size_t band, GDALRWFlag iodir)
Get/Set line in a band from raw pointer.
Definition: Raster.icc:267
void setLine(T *buffer, size_t yidx, size_t iowidth, size_t band=1)
Write one line of data from buffer, vector, or valarray to given band.
Definition: Raster.icc:313
GDALAccess access() const
Access mode getter.
Definition: Raster.h:95
size_t length() const
Length getter.
Definition: Raster.h:86
const GDALDataType defaultGDALDataType
Default GDAL data type used by Raster for creation.
Definition: Constants.h:20
void addRawBandToVRT(const std::string &fname, GDALDataType dtype)
Add a raw data band to VRT.
Definition: Raster.icc:189
void open(const std::string &fname, GDALAccess access)
Open file with GDAL.
Definition: Raster.icc:153
double y0() const
Return Northern Limit of Raster.
Definition: Raster.icc:623
size_t width() const
Width getter.
Definition: Raster.h:89
double dy() const
Return NS pixel spacing of Raster.
Definition: Raster.icc:639
void getSetValue(T &buffer, size_t xidz, size_t yidx, size_t band, GDALRWFlag)
Get/Set single value for given band.
Definition: Raster.icc:218
void getValue(T &buffer, size_t xidx, size_t yidx, size_t band=1)
Definition: Raster.icc:238
int setEPSG(int code)
Set EPSG code.
Definition: Raster.cpp:203
void setValue(T &buffer, size_t xidx, size_t yidx, size_t band=1)
Definition: Raster.icc:249
~Raster()
Destructor.
Definition: Raster.cpp:235
void getSetBlock(T *buffer, size_t xidx, size_t yidx, size_t iowidth, size_t iolength, size_t band, GDALRWFlag iodir)
Get/Set block in band from raw pointer.
Definition: Raster.icc:347
void initFromPointer(void *ptr, GDALDataType dtype, size_t width, size_t length, size_t pixeloffset, size_t lineoffset)
Construct dataset for a 1 band dataset with raw pointer, dimensions and offsets.
Definition: Raster.icc:17
void getGeoTransform(double *) const
Copy Raster GeoTransform into a buffer, vector, or valarray.
Definition: Raster.icc:586
Wrapper for GDALRasterBand representing a single raster.
Definition: Raster.h:14
void getBlock(T *buffer, size_t xidx, size_t yidx, size_t iowidth, size_t iolength, size_t band=1)
Read block of data from given band to buffer, vector, or valarray.
Definition: Raster.icc:373
Raster & operator=(const Raster &)
Assignment operator.
Definition: Raster.icc:133
GDALDataset * dataset() const
GDALDataset pointer getter.
Definition: Raster.h:98
size_t numBands() const
Number of bands getter.
Definition: Raster.h:92
void addRasterToVRT(const isce3::io::Raster &rast)
Add a raster to VRT.
Definition: Raster.icc:162
GDALDataType dtype(const size_t band=1) const
Return GDALDatatype of specified band.
Definition: Raster.h:108
Data structure meant to handle Raster I/O operations.
Definition: Raster.h:34
double x0() const
Return Western Limit of Raster.
Definition: Raster.icc:615