pktools
2.6.7
Processing Kernel for geospatial data
|
#include <ImgWriterGdal.h>
Public Member Functions | |
ImgWriterGdal (void) | |
default constructor. Image needs to be opened later with one of the open methods. | |
ImgWriterGdal (const std::string &filename, const ImgReaderGdal &imgSrc, const std::vector< std::string > &options=std::vector< std::string >()) | |
constructor opening an image for writing, copying image attributes from a source image. Image is directly writen to file. | |
ImgWriterGdal (const std::string &filename, int ncol, int nrow, int nband, const GDALDataType &dataType, const std::string &imageType, const std::vector< std::string > &options=std::vector< std::string >()) | |
constructor opening an image for writing, defining all image attributes. Image is directly written to file. | |
~ImgWriterGdal (void) | |
destructor | |
void | open (const std::string &filename, const ImgReaderGdal &imgSrc, const std::vector< std::string > &options=std::vector< std::string >()) |
Open an image for writing, copying image attributes from a source image. Image is directly written to file. More... | |
void | open (const std::string &filename, int ncol, int nrow, int nband, const GDALDataType &dataType, const std::string &imageType, const std::vector< std::string > &options=std::vector< std::string >()) |
Open an image for writing, defining all image attributes. Image is directly written to file. More... | |
void | close (void) |
Close the image. | |
void | setImageDescription (const std::string &imageDescription) |
Set the image description (only for GeoTiff format: TIFFTAG_IMAGEDESCRIPTION) | |
template<typename T > | |
bool | writeData (T &value, int col, int row, int band=0) |
Write 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 > | |
bool | writeData (std::vector< T > &buffer, int minCol, int maxCol, int row, int band=0) |
Write pixel cell values for a range of columns for a specific row and band (all indices start counting from 0) More... | |
template<typename T > | |
bool | writeData (std::vector< T > &buffer, int row, int band=0) |
Write pixel cell values for an entire row for a specific band (all indices start counting from 0) More... | |
template<typename T > | |
bool | writeDataBlock (Vector2d< T > &buffer2d, int minCol, int maxCol, int minRow, int maxRow, int band=0) |
Write 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... | |
void | setColorTable (const std::string &filename, int band=0) |
Set the color table using an (ASCII) file with 5 columns (value R G B alpha) More... | |
void | setColorTable (GDALColorTable *colorTable, int band=0) |
Set the color table using the GDAL class GDALColorTable. More... | |
void | setMetadata (char **metadata) |
Set specific metadata (driver specific) More... | |
void | rasterizeOgr (ImgReaderOgr &ogrReader, const std::vector< double > &burnValues, const std::vector< std::string > &controlOptions=std::vector< std::string >(), const std::vector< std::string > &layernames=std::vector< std::string >()) |
Rasterize an OGR vector dataset using the gdal algorithm "GDALRasterizeLayers". More... | |
void | rasterizeBuf (ImgReaderOgr &ogrReader, const std::vector< double > &burnValues, const std::vector< std::string > &controlOptions=std::vector< std::string >(), const std::vector< std::string > &layernames=std::vector< std::string >()) |
Rasterize an OGR vector dataset in memory using the gdal algorithm "GDALRasterizeLayersBuf". | |
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 | |
virtual void | setCodec (const std::string &imageType) |
Register GDAL driver, setting the datatype, imagetype and some metadata. More... | |
virtual void | setCodec (const ImgReaderGdal &ImgSrc) |
Register GDAL driver, setting the datatype, imagetype and some metadata. More... | |
Protected Attributes | |
std::vector< std::string > | m_options |
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 write a raster dataset in a format supported by GDAL. Currently only those formats where the drivers support the Create method can be written.
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 37 of file ImgWriterGdal.h.
void ImgWriterGdal::open | ( | const std::string & | filename, |
const ImgReaderGdal & | imgSrc, | ||
const std::vector< std::string > & | options = std::vector<std::string>() |
||
) |
Open an image for writing, copying image attributes from a source image. Image is directly written to file.
filename | Open a raster dataset with this filename |
imgSrc | Use this source image as a template to copy image attributes |
options | Creation options |
Definition at line 43 of file ImgWriterGdal.cc.
void ImgWriterGdal::open | ( | const std::string & | filename, |
int | ncol, | ||
int | nrow, | ||
int | nband, | ||
const GDALDataType & | dataType, | ||
const std::string & | imageType, | ||
const std::vector< std::string > & | options = std::vector<std::string>() |
||
) |
Open an image for writing, defining all image attributes. Image is directly written to file.
filename | Open a raster dataset with this filename |
ncol | Number of columns in image |
nrow | Number of rows in image |
nband | Number of bands in image |
dataType | The data type of the image (one of the GDAL supported datatypes: GDT_Byte, GDT_[U]Int[16|32], GDT_Float[32|64]) |
imageType | Image type. Currently only those formats where the drivers support the Create method can be written |
options | Creation options |
Definition at line 63 of file ImgWriterGdal.cc.
void ImgWriterGdal::rasterizeOgr | ( | ImgReaderOgr & | ogrReader, |
const std::vector< double > & | burnValues, | ||
const std::vector< std::string > & | controlOptions = std::vector<std::string>() , |
||
const std::vector< std::string > & | layernames = std::vector<std::string>() |
||
) |
Rasterize an OGR vector dataset using the gdal algorithm "GDALRasterizeLayers".
ogrReader | Vector dataset as an instance of the ImgReaderOgr that must be rasterized |
burnValues | Values to burn into raster cells (one value for each band) |
controlOptions | special options controlling rasterization (ATTRIBUTE|CHUNKYSIZE|ALL_TOUCHED|BURN_VALUE_FROM|MERGE_ALG) "ATTRIBUTE": Identifies an attribute field on the features to be used for a burn in value. The value will be burned into all output bands. If specified, padfLayerBurnValues will not be used and can be a NULL pointer. "CHUNKYSIZE": The height in lines of the chunk to operate on. The larger the chunk size the less times we need to make a pass through all the shapes. If it is not set or set to zero the default chunk size will be used. Default size will be estimated based on the GDAL cache buffer size using formula: cache_size_bytes/scanline_size_bytes, so the chunk will not exceed the cache. "ALL_TOUCHED": May be set to TRUE to set all pixels touched by the line or polygons, not just those whose center is within the polygon or that are selected by brezenhams line algorithm. Defaults to FALSE. "BURN_VALUE_ May be set to "Z" to use the Z values of the geometries. The value from padfLayerBurnValues or the attribute field value is added to this before burning. In default case dfBurnValue is burned as it is. This is implemented properly only for points and lines for now. Polygons will be burned using the Z value from the first point. The M value may be supported in the future. "MERGE_ALG": May be REPLACE (the default) or ADD. REPLACE results in overwriting of value, while ADD adds the new value to the existing raster, suitable for heatmaps for instance. |
layernames | Names of the vector dataset layers to process. Leave empty to process all layers |
Definition at line 314 of file ImgWriterGdal.cc.
|
protectedvirtual |
Register GDAL driver, setting the datatype, imagetype and some metadata.
dataType | The data type of the image (one of the GDAL supported datatypes: GDT_Byte, GDT_[U]Int[16|32], GDT_Float[32|64]) |
imageType | Image type. Currently only those formats where the drivers support the Create method can be written |
Definition at line 161 of file ImgWriterGdal.cc.
|
protectedvirtual |
Register GDAL driver, setting the datatype, imagetype and some metadata.
imgSrc | Use this source image as a template to copy image attributes |
Definition at line 88 of file ImgWriterGdal.cc.
void ImgWriterGdal::setColorTable | ( | const std::string & | filename, |
int | band = 0 |
||
) |
Set the color table using an (ASCII) file with 5 columns (value R G B alpha)
filename | ASCII file containing 5 columns: index R G B ALFA (0:transparent, 255:solid) |
band | band number to set color table (starting counting from 0) |
Definition at line 254 of file ImgWriterGdal.cc.
void ImgWriterGdal::setColorTable | ( | GDALColorTable * | colorTable, |
int | band = 0 |
||
) |
Set the color table using the GDAL class GDALColorTable.
colorTable | Instance of the GDAL class GDALColorTable |
band | band number to set color table (starting counting from 0) |
Definition at line 278 of file ImgWriterGdal.cc.
void ImgWriterGdal::setMetadata | ( | char ** | metadata | ) |
Set specific metadata (driver specific)
metadata | Set this metadata when writing the image (if supported byt the driver) |
Definition at line 224 of file ImgWriterGdal.cc.
bool ImgWriterGdal::writeData | ( | T & | value, |
int | col, | ||
int | row, | ||
int | band = 0 |
||
) |
Write a single pixel cell value at a specific column and row for a specific band (all indices start counting from 0)
[in] | value | The cell value to write |
[in] | col | The column number to write (counting starts from 0) |
[in] | row | The row number to write (counting starts from 0) |
[in] | band | The band number to write (counting starts from 0) |
Definition at line 96 of file ImgWriterGdal.h.
bool ImgWriterGdal::writeData | ( | std::vector< T > & | buffer, |
int | minCol, | ||
int | maxCol, | ||
int | row, | ||
int | band = 0 |
||
) |
Write pixel cell values for a range of columns for a specific row and band (all indices start counting from 0)
[in] | buffer | The vector with all cell values to write |
[in] | minCol | First column from where to start writing (counting starts from 0) |
[in] | maxCol | Last column that must be written (counting starts from 0) |
[in] | row | The row number to write (counting starts from 0) |
[in] | band | The band number to write (counting starts from 0) |
Definition at line 146 of file ImgWriterGdal.h.
bool ImgWriterGdal::writeData | ( | std::vector< T > & | buffer, |
int | row, | ||
int | band = 0 |
||
) |
Write pixel cell values for an entire row for a specific band (all indices start counting from 0)
[in] | buffer | The vector with all cell values to write |
[in] | row | The row number to write (counting starts from 0) |
[in] | band | The band number to write (counting starts from 0) |
Definition at line 201 of file ImgWriterGdal.h.
bool ImgWriterGdal::writeDataBlock | ( | Vector2d< T > & | buffer2d, |
int | minCol, | ||
int | maxCol, | ||
int | minRow, | ||
int | maxRow, | ||
int | band = 0 |
||
) |
Write 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].
[in] | buffer2d | Two dimensional vector of type Vector2d (stl vector of stl vector) representing [row][col]. This vector contains all cell values that must be written |
[in] | minCol | First column from where to start writing (counting starts from 0) |
[in] | maxCol | Last column that must be written (counting starts from 0) |
[in] | row | The row number to write (counting starts from 0) |
[in] | band | The band number to write (counting starts from 0) |
Definition at line 214 of file ImgWriterGdal.h.