isce3  0.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
Public Member Functions | List of all members
isce3::io::Raster Class Reference

Data structure meant to handle Raster I/O operations. More...

#include <Raster.h>

Public Member Functions

 Raster (const std::string &fname, GDALAccess access=GA_ReadOnly)
 Constructor to open an existing file with specified Access mode - defaults to read-only. More...
 
 Raster (const std::string &fname, size_t width, size_t length, size_t numBands, GDALDataType dtype=isce3::io::defaultGDALDataType, const std::string &driverName=isce3::io::defaultGDALDriver)
 Constructor to create a dataset. More...
 
 Raster (const std::string &fname, size_t width, size_t length, GDALDataType dtype=isce3::io::defaultGDALDataType)
 Constructor to create a 1 band dataset with default Driver. More...
 
template<typename T >
 Raster (isce3::core::Matrix< T > &matrix)
 Constructor for a 1 band dataset from isce3::core::Matrix<T>
 
template<typename T >
 Raster (pyre::grid::View< T > &view)
 
 Raster (const std::string &fname, const Raster &rast)
 Create new raster object like another. More...
 
template<typename T >
 Raster (const std::string &fname, const std::vector< T > &buffer, size_t length)
 
template<typename T >
 Raster (const std::string &fname, const std::valarray< T > &buffer, size_t length)
 
 Raster (const std::string &fname, const std::vector< Raster > &rastVec)
 Create a VRT raster dataset with collection of bands from Rasters. More...
 
 Raster (isce3::io::gdal::Raster &)
 Create legacy raster reference to isce3::io::gdal::Raster.
 
 Raster (const Raster &)
 Copy constructor. More...
 
 Raster (GDALDataset *inputDataset, bool owner=true)
 Constructor from an existing GDAL Dataset. More...
 
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.
 
 ~Raster ()
 Destructor.
 
Rasteroperator= (const Raster &)
 Assignment operator.
 
size_t length () const
 Length getter.
 
size_t width () const
 Width getter.
 
size_t numBands () const
 Number of bands getter.
 
GDALAccess access () const
 Access mode getter.
 
GDALDataset * dataset () const
 GDALDataset pointer getter.
 
void dataset (GDALDataset *ds)
 GDALDataset pointer setter. More...
 
GDALDataType dtype (const size_t band=1) const
 Return GDALDatatype of specified band. More...
 
bool match (const Raster &rast) const
 Check dimensions compatibility with another raster. More...
 
void open (const std::string &fname, GDALAccess access)
 Open file with GDAL. More...
 
void addRasterToVRT (const isce3::io::Raster &rast)
 Add a raster to VRT. More...
 
void addBandToVRT (GDALRasterBand *inBand)
 Add a GDALRasterBand to VRT. More...
 
void addRawBandToVRT (const std::string &fname, GDALDataType dtype)
 Add a raw data band to VRT. More...
 
template<typename T >
void getSetValue (T &buffer, size_t xidz, size_t yidx, size_t band, GDALRWFlag)
 Get/Set single value for given band. More...
 
template<typename T >
void getValue (T &buffer, size_t xidx, size_t yidx, size_t band=1)
 
template<typename T >
void setValue (T &buffer, size_t xidx, size_t yidx, size_t band=1)
 
template<typename T >
void getSetLine (T *buffer, size_t yidx, size_t iowidth, size_t band, GDALRWFlag iodir)
 Get/Set line in a band from raw pointer. More...
 
template<typename T >
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. More...
 
template<typename T >
void getLine (std::vector< T > &vec, size_t yidx, size_t band=1)
 
template<typename T >
void getLine (std::valarray< T > &arr, size_t yidx, size_t band=1)
 
template<typename T >
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. More...
 
template<typename T >
void setLine (std::vector< T > &vec, size_t yidx, size_t band=1)
 
template<typename T >
void setLine (std::valarray< T > &arr, size_t yidx, size_t band=1)
 
template<typename T >
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. More...
 
template<typename T >
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. More...
 
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)
 
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)
 
template<typename T >
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. More...
 
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)
 
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)
 
template<typename T >
void getBlock (isce3::core::Matrix< T > &mat, size_t xidx, size_t yidx, size_t band=1)
 Read/write block of data from given band to/from Matrix<T>
 
template<typename T >
void setBlock (isce3::core::Matrix< T > &mat, size_t xidx, size_t yidx, size_t band=1)
 
template<typename T >
void getSetBlock (pyre::grid::View< T > &view, size_t xidx, size_t yidx, size_t band, GDALRWFlag iodir)
 Read/Write block of data from given band to/from Matrix<T>::view_type.
 
template<typename T >
void getBlock (pyre::grid::View< T > &view, size_t xidx, size_t yidx, size_t band=1)
 
template<typename T >
void setBlock (pyre::grid::View< T > &view, size_t xidx, size_t yidx, size_t band=1)
 
int getEPSG ()
 Return EPSG code corresponding to raster. More...
 
int setEPSG (int code)
 Set EPSG code. More...
 
void setGeoTransform (double *arr)
 Set Raster GeoTransform from buffer, vector, or valarray. More...
 
void setGeoTransform (std::vector< double > &)
 
void setGeoTransform (std::valarray< double > &)
 
void getGeoTransform (double *) const
 Copy Raster GeoTransform into a buffer, vector, or valarray. More...
 
void getGeoTransform (std::vector< double > &) const
 
void getGeoTransform (std::valarray< double > &) const
 
double x0 () const
 Return Western Limit of Raster.
 
double y0 () const
 Return Northern Limit of Raster.
 
double dx () const
 Return EW pixel spacing of Raster.
 
double dy () const
 Return NS pixel spacing of Raster.
 

Detailed Description

Data structure meant to handle Raster I/O operations.

This is currently a thin wrapper over GDAL's Dataset class with some simpler interfaces for I/O. ISCE is expected to only support North-up and West-left oriented rasters.

Constructor & Destructor Documentation

isce3::io::Raster::Raster ( const std::string &  fname,
GDALAccess  access = GA_ReadOnly 
)

Constructor to open an existing file with specified Access mode - defaults to read-only.

Parameters
[in]fnameExisting filename
[in]accessGDAL access mode

Files are opened with GDALOpenShared

isce3::io::Raster::Raster ( const std::string &  fname,
size_t  width,
size_t  length,
size_t  numBands,
GDALDataType  dtype = isce3::io::defaultGDALDataType,
const std::string &  driverName = isce3::io::defaultGDALDriver 
)

Constructor to create a dataset.

Parameters
[in]fnameFilename to create
[in]widthWidth of raster image
[in]lengthLength of raster image
[in]numBandsNumber of bands in raster image
[in]dtypeGDALDataType associated with dataset
[in]driverNameGDAL Driver to use

In general, GDAL is used to create dataset. When VRT driver is used, the dataset is interpreted in a special manner - it is assumed that the user expects a flat binary file with a VRT pointing to the data using VRTRawRasterBand

isce3::io::Raster::Raster ( const std::string &  fname,
size_t  width,
size_t  length,
GDALDataType  dtype = isce3::io::defaultGDALDataType 
)

Constructor to create a 1 band dataset with default Driver.

Parameters
[in]fnameFile name to create
[in]widthWidth of raster image
[in]lengthLength of raster image
[in]dtypeGDALDataType associated with dataset
isce3::io::Raster::Raster ( const std::string &  fname,
const Raster rast 
)

Create new raster object like another.

Parameters
[in]fnameFile name to create
[in]rastReference raster object
isce3::io::Raster::Raster ( const std::string &  fname,
const std::vector< Raster > &  rastVec 
)

Create a VRT raster dataset with collection of bands from Rasters.

Parameters
[in]fnameOutput VRT filename to create
[in]rastVecstd::vector of Raster objects
isce3::io::Raster::Raster ( const Raster rast)

Copy constructor.

Parameters
[in]rastSource raster.

It increments GDAL's reference counter after weak-copying the pointer

isce3::io::Raster::Raster ( GDALDataset *  inputDataset,
bool  owner = true 
)

Constructor from an existing GDAL Dataset.

Parameters
[in]inputDatasetPointer to an existing dataset

Member Function Documentation

void isce3::io::Raster::addBandToVRT ( GDALRasterBand *  inBand)
inline

Add a GDALRasterBand to VRT.

Parameters
[in]inBandGDALRasterBand pointer
void isce3::io::Raster::addRasterToVRT ( const isce3::io::Raster rast)
inline

Add a raster to VRT.

Parameters
[in]rastInput raster dataset
void isce3::io::Raster::addRawBandToVRT ( const std::string &  fname,
GDALDataType  dtype 
)
inline

Add a raw data band to VRT.

Parameters
[in]fnameRaw file name
[in]dtypeGDALDataType
void isce3::io::Raster::dataset ( GDALDataset *  ds)
inline

GDALDataset pointer setter.

Parameters
[in]dsGDALDataset pointer
GDALDataType isce3::io::Raster::dtype ( const size_t  band = 1) const
inline

Return GDALDatatype of specified band.

Parameters
[in]bandBand number in 1-index
template<typename T >
void isce3::io::Raster::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.

Parameters
[in]bufferRaw pointer to buffer
[in]xidxPixel index (0-based)
[in]yidxLine index (0-based)
[in]iowidthNumber of pixels to read
[in]iolengthNumber of lines to read
[in]bandBand index (1-based)
int isce3::io::Raster::getEPSG ( )

Return EPSG code corresponding to raster.

Uses GDAL's inbuilt OSRFindMatches to determine the EPSG code from the WKT representation of the projection system.

This is designed to work with GDAL 2.3+

void isce3::io::Raster::getGeoTransform ( double *  arr) const
inline

Copy Raster GeoTransform into a buffer, vector, or valarray.

Parameters
[in]arrpointer to buffer of 6 double precision numbers

No memory check is performed

void isce3::io::Raster::getGeoTransform ( std::vector< double > &  arr) const
inline
Parameters
[in]arrstd::vector to copy GeoTransform into
void isce3::io::Raster::getGeoTransform ( std::valarray< double > &  arr) const
inline
Parameters
[in]arrstd::valarray to copy GeoTransform into
template<typename T >
void isce3::io::Raster::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.

Parameters
[in]bufferRaw pointer to buffer
[in]yidxLine index (0-based)
[in]iowidthNumber of samples to read
[in]bandBand index (1-based)
template<typename T >
void isce3::io::Raster::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.

Parameters
[in]bufferRaw pointer for I/O
[in]xidxPixel index (0-based)
[in]yidxLine index (0-based)
[in]iowidthNumber of pixels to read/write
[in]iolengthNumber of lines to read/write

Datatype translation is automatically determined from the type of buffer

template<typename T >
void isce3::io::Raster::getSetLine ( T *  buffer,
size_t  yidx,
size_t  iowidth,
size_t  band,
GDALRWFlag  iodir 
)

Get/Set line in a band from raw pointer.

Parameters
[in,out]bufferRaw pointer to buffer
[in]xidxLine location within band (0-based)
[in]iowidthWidth of I/O buffer
[in]bandBand index (1-based)
[in]iodirGDALRWFlag to indicate read / write

Datatype translation is automatically determined using type of pointer passed

template<typename T >
void isce3::io::Raster::getSetValue ( T &  buffer,
size_t  xidx,
size_t  yidx,
size_t  band,
GDALRWFlag  iodir 
)

Get/Set single value for given band.

Parameters
[in,out]bufferBuffer of type T
[in]xidxPixel index (0-based)
[in]yidxLine index (0-based)
[in]bandBand index (1-based)
[in]GDALRWFlagDetermines datatype translation to use from the type of buffer passed in
template<typename T >
void isce3::io::Raster::getValue ( T &  buffer,
size_t  xidx,
size_t  yidx,
size_t  band = 1 
)
Parameters
[out]bufferBuffer to copy data into
[in]xidxPixel index (0-based)
[in]yidxLine index (0-based)
[in]bandBand index (1-based)
bool isce3::io::Raster::match ( const Raster rast) const
inline

Check dimensions compatibility with another raster.

Parameters
[in]rastReference raster to compare against
void isce3::io::Raster::open ( const std::string &  fname,
GDALAccess  access = GA_ReadOnly 
)
inline

Open file with GDAL.

Parameters
[in]fnameFilename to open
[in]accessAccess mode
template<typename T >
void isce3::io::Raster::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.

Parameters
[in]bufferRaw pointer to buffer
[in]xidxPixel index (0-based)
[in]yidxLine index (0-based)
[in]iowidthNumber of pixels to read
[in]iolengthNumber of lines to read
[in]bandBand index (1-based)
int isce3::io::Raster::setEPSG ( int  epsgcode)

Set EPSG code.

Parameters
[in]epsgcodeEPSG code corresponding to projection system

GDAL relies on GDAL_DATA environment variable to interpret these codes. Make sure that these are set.

void isce3::io::Raster::setGeoTransform ( double *  arr)
inline

Set Raster GeoTransform from buffer, vector, or valarray.

Parameters
[in]arrArray of 6 double precision numbers

No memory check performed for length of array

void isce3::io::Raster::setGeoTransform ( std::vector< double > &  arr)
inline
Parameters
[in]arrstd::vector of 6 double precision numbers
void isce3::io::Raster::setGeoTransform ( std::valarray< double > &  arr)
inline
Parameters
[in]arrstd::valarray of 6 double precision numbers
template<typename T >
void isce3::io::Raster::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.

Parameters
[in]bufferRaw pointer to buffer
[in]yidxLine index (0-based)
[in]iowidthNumber of samples to write
[in]bandBand index (1-based)
template<typename T >
void isce3::io::Raster::setValue ( T &  buffer,
size_t  xidx,
size_t  yidx,
size_t  band = 1 
)
Parameters
[in]bufferBuffer to copy data from
[in]xidxPixel index (0-based)
[in]yidxLine index (0-based)
[in]bandBand index (1-based)

The documentation for this class was generated from the following files:

Generated for ISCE3.0 by doxygen 1.8.5.