pktools
2.6.7
Processing Kernel for geospatial data
|
#include <ImgReaderGdal.h>
Public Member Functions | |
ImgReaderGdal (void) | |
default constructor. Image needs to be opened later with one of the open methods. | |
ImgReaderGdal (const std::string &filename, const GDALAccess &readMode=GA_ReadOnly) | |
constructor opening an image. Set memory (in MB) to cache a number of rows in memory | |
~ImgReaderGdal (void) | |
destructor | |
void | open (const std::string &filename, const GDALAccess &readMode=GA_ReadOnly) |
Open an image. More... | |
void | close (void) |
Set the memory (in MB) to cache a number of rows in memory. More... | |
template<typename T > | |
void | readData (T &value, int col, int row, int band=0) |
Read a single pixel cell value at a specific column and row for a specific band (all indices start counting from 0) More... | |
template<typename T > | |
void | readData (std::vector< T > &buffer, int minCol, int maxCol, int row, int band=0) |
Read pixel cell values for a range of columns for a specific row and band (all indices start counting from 0) More... | |
template<typename T > | |
void | readData (std::vector< T > &buffer, int minCol, int maxCol, double row, int band=0, RESAMPLE resample=NEAR) |
Read pixel cell values for a range of columns for a specific row and band (all indices start counting from 0). The row counter can be floating, in which case a resampling is applied at the row level. You still must apply the resampling at column level. This function will be deprecated, as the GDAL API now supports rasterIO resampling (see http://www.gdal.org/structGDALRasterIOExtraArg.html) More... | |
template<typename T > | |
void | readDataBlock (Vector2d< T > &buffer2d, int minCol, int maxCol, int minRow, int maxRow, int band=0) |
Read pixel cell values for a range of columns and rows for a specific band (all indices start counting from 0). The buffer is a two dimensional vector (stl vector of stl vector) representing [row][col]. More... | |
template<typename T > | |
void | readDataBlock (std::vector< T > &buffer, int minCol, int maxCol, int minRow, int maxRow, int band=0) |
Read pixel cell values for a range of columns and rows for a specific band (all indices start counting from 0). The buffer is a one dimensional stl vector representing all pixel values read starting from upper left to lower right. More... | |
template<typename T > | |
void | readData (std::vector< T > &buffer, int row, int band=0) |
Read pixel cell values for an entire row for a specific band (all indices start counting from 0) More... | |
template<typename T > | |
void | readData (std::vector< T > &buffer, double row, int band=0, RESAMPLE resample=NEAR) |
Read pixel cell values for an entire row for a specific band (all indices start counting from 0). The row counter can be floating, in which case a resampling is applied at the row level. You still must apply the resampling at column level. This function will be deprecated, as the GDAL API now supports rasterIO resampling (see http://www.gdal.org/structGDALRasterIOExtraArg.html) More... | |
void | getMinMax (int startCol, int endCol, int startRow, int endRow, int band, double &minValue, double &maxValue) |
Get the minimum and maximum cell values for a specific band in a region of interest defined by startCol, endCol, startRow and endRow (all indices start counting from 0). More... | |
void | getMinMax (double &minValue, double &maxValue, int band=0) |
Get the minimum and maximum cell values for a specific band (all indices start counting from 0). More... | |
double | getMin (int &col, int &row, int band=0) |
Get the minimum cell values for a specific band and report the column and row in which the minimum value was found (all indices start counting from 0). More... | |
double | getMax (int &col, int &row, int band=0) |
Get the maximum cell values for a specific band and report the column and row in which the maximum value was found (all indices start counting from 0). More... | |
double | getHistogram (std::vector< double > &histvector, double &min, double &max, unsigned int &nbin, int theBand=0, bool kde=false) |
Calculate the image histogram for a specific band using a defined number of bins and constrained by a minimum and maximum value. A kernel density function can also be applied (default is false). More... | |
void | getRefPix (double &refX, double &refY, int band=0) |
Calculate the reference pixel as the centre of gravity pixel (weighted average of all values not taking into account no data values) for a specific band (start counting from 0). More... | |
void | getRange (std::vector< short > &range, int Band=0) |
Calculate the range of cell values in the image for a specific band (start counting from 0). More... | |
unsigned long int | getNvalid (int band) |
Calculate the number of valid pixels (with a value not defined as no data). More... | |
Public Member Functions inherited from ImgRasterGdal | |
ImgRasterGdal (void) | |
default constructor | |
virtual | ~ImgRasterGdal (void) |
destructor | |
void | setScale (double theScale, int band=0) |
Set scale for a specific band when writing the raster data values. The scaling and offset are applied on a per band basis. You need to set the scale for each band. | |
void | setOffset (double theOffset, int band=0) |
Set offset for a specific band when writing the raster data values. The scaling and offset are applied on a per band basis. You need to set the offset for each band. | |
std::string | getFileName () const |
Get the filename of this dataset. | |
int | nrOfCol (void) const |
Get the number of columns of this dataset. | |
int | nrOfRow (void) const |
Get the number of rows of this dataset. | |
int | nrOfBand (void) const |
Get the number of bands of this dataset. | |
bool | isGeoRef () const |
Is this dataset georeferenced (pixel size in y must be negative) ? | |
std::string | getProjection (void) const |
Get the projection string (deprecated, use getProjectionRef instead) More... | |
std::string | getProjectionRef (void) const |
Get the projection reference. More... | |
std::string | getGeoTransform () const |
Get the geotransform data for this dataset as a string. More... | |
void | getGeoTransform (double *gt) const |
Get the geotransform data for this dataset. More... | |
CPLErr | setGeoTransform (double *gt) |
Set the geotransform data for this dataset. More... | |
void | copyGeoTransform (const ImgRasterGdal &imgSrc) |
Copy geotransform information from another georeferenced image. More... | |
CPLErr | setProjection (const std::string &projection) |
Set the projection for this dataset in well known text (wkt) format. More... | |
CPLErr | setProjectionProj4 (const std::string &projection) |
Set the projection for this dataset from user input (supports epsg:<number> format) More... | |
bool | getBoundingBox (double &ulx, double &uly, double &lrx, double &lry) const |
Get the bounding box of this dataset in georeferenced coordinates. More... | |
bool | getCenterPos (double &x, double &y) const |
Get the center position of this dataset in georeferenced coordinates. More... | |
double | getUlx () const |
Get the upper left corner x (georeferenced) coordinate of this dataset. | |
double | getUly () const |
Get the upper left corner y (georeferenced) coordinate of this dataset. | |
double | getLrx () const |
Get the lower right corner x (georeferenced) coordinate of this dataset. | |
double | getLry () const |
Get the lower right corner y (georeferenced) coordinate of this dataset. | |
int | getNoDataValues (std::vector< double > &noDataValues) const |
Get the no data values of this dataset as a standard template library (stl) vector. More... | |
bool | isNoData (double value) const |
Check if value is nodata in this dataset. | |
int | pushNoDataValue (double noDataValue) |
Push a no data value for this dataset. More... | |
int | setNoData (const std::vector< double > nodata) |
Set the no data values of this dataset using a standard template library (stl) vector as input. | |
CPLErr | GDALSetNoDataValue (double noDataValue, int band=0) |
Set the GDAL (internal) no data value for this data set. Only a single no data value per band is supported. | |
bool | covers (double x, double y) const |
Check if a geolocation is covered by this dataset. Only the bounding box is checked, irrespective of no data values. More... | |
bool | covers (double ulx, double uly, double lrx, double lry) const |
Check if a region of interest is (partially) covered by this dataset. Only the bounding box is checked, irrespective of no data values. More... | |
bool | geo2image (double x, double y, double &i, double &j) const |
Convert georeferenced coordinates (x and y) to image coordinates (column and row) More... | |
bool | image2geo (double i, double j, double &x, double &y) const |
Convert image coordinates (column and row) to georeferenced coordinates (x and y) More... | |
double | getDeltaX (void) const |
Get the pixel cell spacing in x. | |
double | getDeltaY (void) const |
Get the pixel cell spacing in y. | |
GDALDataType | getDataType (int band=0) const |
Get the GDAL datatype for this dataset. More... | |
GDALRasterBand * | getRasterBand (int band=0) const |
Get the GDAL rasterband for this dataset. More... | |
GDALColorTable * | getColorTable (int band=0) const |
Get the GDAL color table for this dataset as an instance of the GDALColorTable class. More... | |
std::string | getDriverDescription () const |
Get the GDAL driver description of this dataset. More... | |
std::string | getImageType () const |
Get the image type (implemented as the driver description) | |
std::string | getInterleave () const |
Get the band coding (interleave) More... | |
std::string | getCompression () const |
Get the compression from the metadata of this dataset. More... | |
GDALDataset * | getDataset () |
char ** | getMetadata () |
Get the metadata of this dataset. More... | |
char ** | getMetadata () const |
Get the metadata of this dataset (const version) More... | |
void | getMetadata (std::list< std::string > &metadata) const |
Get the metadata of this dataset in the form of a list of strings (const version) More... | |
std::string | getDescription () const |
Get the image description from the driver of this dataset. More... | |
std::string | getMetadataItem () const |
Get metadata item of this dataset. More... | |
std::string | getImageDescription () const |
Get the image description from the metadata of this dataset. More... | |
int | nrOfBlockX (int band=0) |
int | nrOfBlockY (int band=0) |
Protected Member Functions | |
void | setCodec (const GDALAccess &readMode=GA_ReadOnly) |
Set GDAL dataset number of columns, rows, bands and geotransform. More... | |
Additional Inherited Members | |
Protected Attributes inherited from ImgRasterGdal | |
std::string | m_filename |
filename of this dataset | |
GDALDataset * | m_gds |
instance of the GDAL dataset of this dataset | |
int | m_ncol |
number of columns in this dataset | |
int | m_nrow |
number of rows in this dataset | |
int | m_nband |
number of bands in this dataset | |
GDALDataType | m_dataType |
GDAL data type for this dataset. | |
double | m_gt [6] |
geotransform information of this dataset | |
std::string | m_projection |
std::vector< double > | m_noDataValues |
no data values for this dataset | |
std::vector< double > | m_scale |
Vector containing the scale factor to be applied (one scale value for each band) | |
std::vector< double > | m_offset |
Vector containing the offset factor to be applied (one offset value for each band) | |
Class to read a raster dataset in a format supported by GDAL. Data are cached in memory for a number of rows (if memory>0) before read from file.
This class inherits from ImgRasterGdal, a general raster class to store e.g., filename, number of columns, rows and bands of the dataset.
Definition at line 36 of file ImgReaderGdal.h.
|
virtual |
Set the memory (in MB) to cache a number of rows in memory.
Close the image.
Reimplemented from ImgRasterGdal.
Reimplemented in ImgUpdaterGdal.
Definition at line 42 of file ImgReaderGdal.cc.
double ImgReaderGdal::getHistogram | ( | std::vector< double > & | histvector, |
double & | min, | ||
double & | max, | ||
unsigned int & | nbin, | ||
int | theBand = 0 , |
||
bool | kde = false |
||
) |
Calculate the image histogram for a specific band using a defined number of bins and constrained by a minimum and maximum value. A kernel density function can also be applied (default is false).
histvector | The reported histogram with counts per bin |
min,max | Only calculate histogram for values between min and max. If min>=max, calculate min and max from the image |
nbin | Number of bins used for calculating the histogram. If nbin is 0, the number of bins is automatically calculated from min and max |
theBand | The band for which to calculate the histogram (start counting from 0) |
kde | Apply kernel density function for a Gaussian basis function |
Definition at line 257 of file ImgReaderGdal.cc.
double ImgReaderGdal::getMax | ( | int & | x, |
int & | y, | ||
int | band = 0 |
||
) |
Get the maximum cell values for a specific band and report the column and row in which the maximum value was found (all indices start counting from 0).
x | Reported column where maximum value in image was found (start counting from 0) |
y | Reported row where maximum value in image was found (start counting from 0) |
band | Search mininum value in image for this band |
Definition at line 125 of file ImgReaderGdal.cc.
double ImgReaderGdal::getMin | ( | int & | x, |
int & | y, | ||
int | band = 0 |
||
) |
Get the minimum cell values for a specific band and report the column and row in which the minimum value was found (all indices start counting from 0).
x | Reported column where minimum value in image was found (start counting from 0) |
y | Reported row where minimum value in image was found (start counting from 0) |
band | Search mininum value in image for this band |
Definition at line 89 of file ImgReaderGdal.cc.
void ImgReaderGdal::getMinMax | ( | int | startCol, |
int | endCol, | ||
int | startRow, | ||
int | endRow, | ||
int | band, | ||
double & | minValue, | ||
double & | maxValue | ||
) |
Get the minimum and maximum cell values for a specific band in a region of interest defined by startCol, endCol, startRow and endRow (all indices start counting from 0).
startCol,endCol,startRow,endRow | Search extreme value in this region of interest (all indices start counting from 0) |
band | Search extreme value in image for this band |
minValue | Reported minimum value within searched region |
maxValue | Reported maximum value within searched region |
Definition at line 161 of file ImgReaderGdal.cc.
void ImgReaderGdal::getMinMax | ( | double & | minValue, |
double & | maxValue, | ||
int | band = 0 |
||
) |
Get the minimum and maximum cell values for a specific band (all indices start counting from 0).
minValue | Reported minimum value in image |
maxValue | Reported maximum value in image |
band | Search extreme value in image for this band |
Definition at line 208 of file ImgReaderGdal.cc.
unsigned long int ImgReaderGdal::getNvalid | ( | int | band | ) |
Calculate the number of valid pixels (with a value not defined as no data).
band | The band for which to calculate the number of valid pixels |
Definition at line 373 of file ImgReaderGdal.cc.
void ImgReaderGdal::getRange | ( | std::vector< short > & | range, |
int | band = 0 |
||
) |
Calculate the range of cell values in the image for a specific band (start counting from 0).
range | Sorted vector containing the range of image values |
band | The band for which to calculate the range |
Definition at line 355 of file ImgReaderGdal.cc.
void ImgReaderGdal::getRefPix | ( | double & | refX, |
double & | refY, | ||
int | band = 0 |
||
) |
Calculate the reference pixel as the centre of gravity pixel (weighted average of all values not taking into account no data values) for a specific band (start counting from 0).
refX,refY | Calculated reference pixel position in geo-refererenced coordinates |
band | The band for which to calculate the number of valid pixels |
Definition at line 398 of file ImgReaderGdal.cc.
void ImgReaderGdal::open | ( | const std::string & | filename, |
const GDALAccess & | readMode = GA_ReadOnly |
||
) |
Open an image.
filename | Open a raster dataset with this filename |
readMode | Open dataset in ReadOnly or Update mode |
memory | Available memory to cache image raster data (in MB) |
Definition at line 36 of file ImgReaderGdal.cc.
void ImgReaderGdal::readData | ( | T & | value, |
int | col, | ||
int | row, | ||
int | band = 0 |
||
) |
Read a single pixel cell value at a specific column and row for a specific band (all indices start counting from 0)
[out] | value | The cell value that was read |
[in] | col | The column number to read (counting starts from 0) |
[in] | row | The row number to read (counting starts from 0) |
[in] | band | The band number to read (counting starts from 0) |
Definition at line 95 of file ImgReaderGdal.h.
void ImgReaderGdal::readData | ( | std::vector< T > & | buffer, |
int | minCol, | ||
int | maxCol, | ||
int | row, | ||
int | band = 0 |
||
) |
Read pixel cell values for a range of columns for a specific row and band (all indices start counting from 0)
[out] | buffer | The vector with all cell values that were read |
[in] | minCol | First column from where to start reading (counting starts from 0) |
[in] | maxCol | Last column that must be read (counting starts from 0) |
[in] | row | The row number to read (counting starts from 0) |
[in] | band | The band number to read (counting starts from 0) |
Definition at line 126 of file ImgReaderGdal.h.
void ImgReaderGdal::readData | ( | std::vector< T > & | buffer, |
int | minCol, | ||
int | maxCol, | ||
double | row, | ||
int | band = 0 , |
||
RESAMPLE | resample = NEAR |
||
) |
Read pixel cell values for a range of columns for a specific row and band (all indices start counting from 0). The row counter can be floating, in which case a resampling is applied at the row level. You still must apply the resampling at column level. This function will be deprecated, as the GDAL API now supports rasterIO resampling (see http://www.gdal.org/structGDALRasterIOExtraArg.html)
[out] | buffer | The vector with all cell values that were read |
[in] | minCol | First column from where to start reading (counting starts from 0) |
[in] | maxCol | Last column that must be read (counting starts from 0) |
[in] | row | The row number to read (counting starts from 0) |
[in] | band | The band number to read (counting starts from 0) |
[in] | resample | The resampling method (currently only BILINEAR and NEAR are supported) |
Definition at line 163 of file ImgReaderGdal.h.
void ImgReaderGdal::readData | ( | std::vector< T > & | buffer, |
int | row, | ||
int | band = 0 |
||
) |
Read pixel cell values for an entire row for a specific band (all indices start counting from 0)
[out] | buffer | The vector with all cell values that were read |
[in] | row | The row number to read (counting starts from 0) |
[in] | band | The band number to read (counting starts from 0) |
Definition at line 280 of file ImgReaderGdal.h.
void ImgReaderGdal::readData | ( | std::vector< T > & | buffer, |
double | row, | ||
int | band = 0 , |
||
RESAMPLE | resample = NEAR |
||
) |
Read pixel cell values for an entire row for a specific band (all indices start counting from 0). The row counter can be floating, in which case a resampling is applied at the row level. You still must apply the resampling at column level. This function will be deprecated, as the GDAL API now supports rasterIO resampling (see http://www.gdal.org/structGDALRasterIOExtraArg.html)
[out] | buffer | The vector with all cell values that were read |
[in] | row | The row number to read (counting starts from 0) |
[in] | band | The band number to read (counting starts from 0) |
[in] | resample | The resampling method (currently only BILINEAR and NEAR are supported). |
Definition at line 291 of file ImgReaderGdal.h.
void ImgReaderGdal::readDataBlock | ( | Vector2d< T > & | buffer2d, |
int | minCol, | ||
int | maxCol, | ||
int | minRow, | ||
int | maxRow, | ||
int | band = 0 |
||
) |
Read pixel cell values for a range of columns and rows for a specific band (all indices start counting from 0). The buffer is a two dimensional vector (stl vector of stl vector) representing [row][col].
[out] | buffer2d | Two dimensional vector of type Vector2d (stl vector of stl vector) representing [row][col]. This vector contains all cell values that were read |
[in] | minCol | First column from where to start reading (counting starts from 0) |
[in] | maxCol | Last column that must be read (counting starts from 0) |
[in] | minRow | First row from where to start reading (counting starts from 0) |
[in] | maxRow | Last row that must be read (counting starts from 0) |
[in] | band | The band number to read (counting starts from 0) |
Definition at line 220 of file ImgReaderGdal.h.
void ImgReaderGdal::readDataBlock | ( | std::vector< T > & | buffer, |
int | minCol, | ||
int | maxCol, | ||
int | minRow, | ||
int | maxRow, | ||
int | band = 0 |
||
) |
Read pixel cell values for a range of columns and rows for a specific band (all indices start counting from 0). The buffer is a one dimensional stl vector representing all pixel values read starting from upper left to lower right.
[out] | buffer | One dimensional vector representing all pixel values read starting from upper left to lower right. |
[in] | minCol | First column from where to start reading (counting starts from 0) |
[in] | maxCol | Last column that must be read (counting starts from 0) |
[in] | minRow | First row from where to start reading (counting starts from 0) |
[in] | maxRow | Last row that must be read (counting starts from 0) |
[in] | band | The band number to read (counting starts from 0) |
Definition at line 243 of file ImgReaderGdal.h.
|
protected |
Set GDAL dataset number of columns, rows, bands and geotransform.
readMode | Open dataset in ReadOnly or Update mode |
Definition at line 50 of file ImgReaderGdal.cc.