pktools 2.6.7
Processing Kernel for geospatial data
Public Member Functions | Protected Attributes | Friends | List of all members
ImgRasterGdal Class Reference

#include <ImgRasterGdal.h>

Inheritance diagram for ImgRasterGdal:
Inheritance graph
[legend]
Collaboration diagram for ImgRasterGdal:
Collaboration graph
[legend]

Public Member Functions

 ImgRasterGdal (void)
 default constructor More...
 
virtual ~ImgRasterGdal (void)
 destructor More...
 
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. More...
 
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. More...
 
virtual void close (void)
 Close the image. More...
 
std::string getFileName () const
 Get the filename of this dataset. More...
 
int nrOfCol (void) const
 Get the number of columns of this dataset. More...
 
int nrOfRow (void) const
 Get the number of rows of this dataset. More...
 
int nrOfBand (void) const
 Get the number of bands of this dataset. More...
 
bool isGeoRef () const
 Is this dataset georeferenced (pixel size in y must be negative) ? More...
 
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. More...
 
double getUly () const
 Get the upper left corner y (georeferenced) coordinate of this dataset. More...
 
double getLrx () const
 Get the lower right corner x (georeferenced) coordinate of this dataset. More...
 
double getLry () const
 Get the lower right corner y (georeferenced) coordinate of this dataset. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
double getDeltaY (void) const
 Get the pixel cell spacing in y. More...
 
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) More...
 
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 Attributes

std::string m_filename
 filename of this dataset More...
 
GDALDataset * m_gds
 instance of the GDAL dataset of this dataset More...
 
int m_ncol
 number of columns in this dataset More...
 
int m_nrow
 number of rows in this dataset More...
 
int m_nband
 number of bands in this dataset More...
 
GDALDataType m_dataType
 GDAL data type for this dataset. More...
 
double m_gt [6]
 geotransform information of this dataset More...
 
std::string m_projection
 
std::vector< double > m_noDataValues
 no data values for this dataset More...
 
std::vector< double > m_scale
 Vector containing the scale factor to be applied (one scale value for each band) More...
 
std::vector< double > m_offset
 Vector containing the offset factor to be applied (one offset value for each band) More...
 

Friends

class ImgReaderGdal
 
class ImgWriterGdal
 

Detailed Description

Base class for raster dataset (read and write) in a format supported by GDAL. This general raster class is used to store e.g., filename, number of columns, rows and bands of the dataset.

Definition at line 67 of file ImgRasterGdal.h.

Constructor & Destructor Documentation

◆ ImgRasterGdal()

ImgRasterGdal::ImgRasterGdal ( void  )

default constructor

Definition at line 24 of file ImgRasterGdal.cc.

25 : m_gds(NULL), m_ncol(0), m_nrow(0), m_nband(0), m_dataType(GDT_Unknown)
26{}
int m_nband
number of bands in this dataset
int m_ncol
number of columns in this dataset
GDALDataset * m_gds
instance of the GDAL dataset of this dataset
int m_nrow
number of rows in this dataset
GDALDataType m_dataType
GDAL data type for this dataset.

◆ ~ImgRasterGdal()

ImgRasterGdal::~ImgRasterGdal ( void  )
virtual

destructor

Definition at line 28 of file ImgRasterGdal.cc.

29{
30}

Member Function Documentation

◆ close()

void ImgRasterGdal::close ( void  )
virtual

Close the image.

Reimplemented in ImgUpdaterGdal, ImgReaderGdal, ImgUpdaterGdal, and ImgWriterGdal.

Definition at line 32 of file ImgRasterGdal.cc.

33{
34 GDALClose(m_gds);
35}

◆ copyGeoTransform()

void ImgRasterGdal::copyGeoTransform ( const ImgRasterGdal imgSrc)

Copy geotransform information from another georeferenced image.

Parameters
imgSrcUse this source image as a template to copy geotranform information

Definition at line 166 of file ImgRasterGdal.cc.

167{
169 double gt[6];
170 imgSrc.getGeoTransform(gt);
171 setGeoTransform(gt);
172}
std::string getProjection(void) const
Get the projection string (deprecated, use getProjectionRef instead)
std::string getGeoTransform() const
Get the geotransform data for this dataset as a string.
CPLErr setGeoTransform(double *gt)
Set the geotransform data for this dataset.
CPLErr setProjection(const std::string &projection)
Set the projection for this dataset in well known text (wkt) format.

◆ covers() [1/2]

bool ImgRasterGdal::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.

assuming adfGeotransform[0]: ULX (upper left X coordinate) adfGeotransform[1]: $cos(\alpha)\cdot\textrm{Xres}$ adfGeotransform[2]: $-sin(\alpha)\cdot\textrm{Xres}$ adfGeotransform[3]: ULY (upper left Y coordinate) adfGeotransform[4]: $-sin(\alpha)\cdot\textrm{Yres}$ adfGeotransform[5]: $-cos(\alpha)\cdot\textrm{Yres}$

Parameters
ulxupper left coordinate in x
ulyupper left coordinate in y
lrxlower left coordinate in x
lrylower left coordinate in y
Returns
true if image (partially) covers the bounding box

Definition at line 467 of file ImgRasterGdal.cc.

468{
469 double theULX, theULY, theLRX, theLRY;
470 getBoundingBox(theULX,theULY,theLRX,theLRY);
471 return((ulx < theLRX)&&(lrx > theULX)&&(lry < theULY)&&(uly > theLRY));
472}
bool getBoundingBox(double &ulx, double &uly, double &lrx, double &lry) const
Get the bounding box of this dataset in georeferenced coordinates.

◆ covers() [2/2]

bool ImgRasterGdal::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.

assuming adfGeotransform[0]: ULX (upper left X coordinate) adfGeotransform[1]: $cos(\alpha)\cdot\textrm{Xres}$ adfGeotransform[2]: $-sin(\alpha)\cdot\textrm{Xres}$ adfGeotransform[3]: ULY (upper left Y coordinate) adfGeotransform[4]: $-sin(\alpha)\cdot\textrm{Yres}$ adfGeotransform[5]: $-cos(\alpha)\cdot\textrm{Yres}$

Parameters
x,ygeoreferenced coordinates in x and y
Returns
true if image covers the georeferenced location

Definition at line 443 of file ImgRasterGdal.cc.

444{
445 double theULX, theULY, theLRX, theLRY;
446 getBoundingBox(theULX,theULY,theLRX,theLRY);
447 return((x > theULX)&&
448 (x < theLRX)&&
449 (y < theULY)&&
450 (y >theLRY));
451}

◆ GDALSetNoDataValue()

CPLErr ImgRasterGdal::GDALSetNoDataValue ( double  noDataValue,
int  band = 0 
)
inline

Set the GDAL (internal) no data value for this data set. Only a single no data value per band is supported.

Definition at line 142 of file ImgRasterGdal.h.

142{return getRasterBand(band)->SetNoDataValue(noDataValue);};
GDALRasterBand * getRasterBand(int band=0) const
Get the GDAL rasterband for this dataset.

◆ geo2image()

bool ImgRasterGdal::geo2image ( double  x,
double  y,
double &  i,
double &  j 
) const

Convert georeferenced coordinates (x and y) to image coordinates (column and row)

assuming adfGeotransform[0]: ULX (upper left X coordinate) adfGeotransform[1]: $cos(\alpha)\cdot\textrm{Xres}$ adfGeotransform[2]: $-sin(\alpha)\cdot\textrm{Xres}$ adfGeotransform[3]: ULY (upper left Y coordinate) adfGeotransform[4]: $-sin(\alpha)\cdot\textrm{Yres}$ adfGeotransform[5]: $-cos(\alpha)\cdot\textrm{Yres}$

Parameters
x,ygeoreferenced coordinates in x and y
i,jimage coordinates (can be fraction of pixels)
Returns
true if image is georeferenced

Definition at line 387 of file ImgRasterGdal.cc.

388{
389 double gt[6];// { 444720, 30, 0, 3751320, 0, -30 };
390 getGeoTransform(gt);
391
392 double denom=(gt[1]-gt[2]*gt[4]/gt[5]);
393 double eps=0.00001;
394 if(fabs(denom)>eps){
395 i=(x-gt[0]-gt[2]/gt[5]*(y-gt[3]))/denom;
396 j=(y-gt[3]-gt[4]*(x-gt[0]-gt[2]/gt[5]*(y-gt[3]))/denom)/gt[5];
397 }
398 if(isGeoRef())
399 return true;
400 else
401 return false;
402}
bool isGeoRef() const
Is this dataset georeferenced (pixel size in y must be negative) ?

◆ getBoundingBox()

bool ImgRasterGdal::getBoundingBox ( double &  ulx,
double &  uly,
double &  lrx,
double &  lry 
) const

Get the bounding box of this dataset in georeferenced coordinates.

assuming adfGeotransform[0]: ULX (upper left X coordinate) adfGeotransform[1]: $cos(\alpha)\cdot\textrm{Xres}$ adfGeotransform[2]: $-sin(\alpha)\cdot\textrm{Xres}$ adfGeotransform[3]: ULY (upper left Y coordinate) adfGeotransform[4]: $-sin(\alpha)\cdot\textrm{Yres}$ adfGeotransform[5]: $-cos(\alpha)\cdot\textrm{Yres}$

Parameters
ulxupper left coordinate in x
ulyupper left coordinate in y
lrxlower left coordinate in x
lrylower left coordinate in y
Returns
true if image is georeferenced

Definition at line 333 of file ImgRasterGdal.cc.

334{
335 double gt[6];// { 444720, 30, 0, 3751320, 0, -30 };
336 getGeoTransform(gt);
337
338 ulx=gt[0];
339 uly=gt[3];
340 lrx=gt[0]+nrOfCol()*gt[1]+nrOfRow()*gt[2];
341 lry=gt[3]+nrOfCol()*gt[4]+nrOfRow()*gt[5];
342 if(isGeoRef())
343 return true;
344 else
345 return false;
346}
int nrOfRow(void) const
Get the number of rows of this dataset.
int nrOfCol(void) const
Get the number of columns of this dataset.
Definition: ImgRasterGdal.h:98

◆ getCenterPos()

bool ImgRasterGdal::getCenterPos ( double &  x,
double &  y 
) const

Get the center position of this dataset in georeferenced coordinates.

assuming adfGeotransform[0]: ULX (upper left X coordinate) adfGeotransform[1]: $cos(\alpha)\cdot\textrm{Xres}$ adfGeotransform[2]: $-sin(\alpha)\cdot\textrm{Xres}$ adfGeotransform[3]: ULY (upper left Y coordinate) adfGeotransform[4]: $-sin(\alpha)\cdot\textrm{Yres}$ adfGeotransform[5]: $-cos(\alpha)\cdot\textrm{Yres}$

Parameters
x,ycentre coordinates in x and y
Returns
true if image is georeferenced

Definition at line 359 of file ImgRasterGdal.cc.

360{
361 double gt[6];// { 444720, 30, 0, 3751320, 0, -30 };
362 getGeoTransform(gt);
363
364 x=gt[0]+(nrOfCol()/2.0)*gt[1]+(nrOfRow()/2.0)*gt[2];
365 y=gt[3]+(nrOfCol()/2.0)*gt[4]+(nrOfRow()/2.0)*gt[5];
366 if(isGeoRef()){
367 // x=m_ulx+(nrOfCol()/2.0)*m_delta_x;
368 // y=m_uly-(nrOfRow()/2.0)*m_delta_y;
369 return true;
370 }
371 else
372 return false;
373}

◆ getColorTable()

GDALColorTable * ImgRasterGdal::getColorTable ( int  band = 0) const

Get the GDAL color table for this dataset as an instance of the GDALColorTable class.

Parameters
bandget GDAL color table for this band (start counting from 0)
Returns
the GDAL color table of this data set for the selected band

Definition at line 118 of file ImgRasterGdal.cc.

119{
120 assert(band<m_nband+1);
121 GDALRasterBand* theRasterBand=getRasterBand(band);
122 if(theRasterBand)
123 return(theRasterBand->GetColorTable());
124 else
125 return(0);
126}

◆ getCompression()

std::string ImgRasterGdal::getCompression ( ) const

Get the compression from the metadata of this dataset.

Returns
the compression meta data of this data set in string format

Definition at line 308 of file ImgRasterGdal.cc.

309{
310 if(m_gds){
311 if(m_gds->GetMetadataItem( "COMPRESSION", "IMAGE_STRUCTURE"))
312 return m_gds->GetMetadataItem( "COMPRESSION", "IMAGE_STRUCTURE");
313 }
314 else
315 return("NONE");
316}

◆ getDataset()

GDALDataset * ImgRasterGdal::getDataset ( )
inline

Definition at line 170 of file ImgRasterGdal.h.

170{return m_gds;};

◆ getDataType()

GDALDataType ImgRasterGdal::getDataType ( int  band = 0) const

Get the GDAL datatype for this dataset.

Parameters
bandget data type for this band (start counting from 0)
Returns
the GDAL data type of this data set for the selected band

Definition at line 92 of file ImgRasterGdal.cc.

93{
94 assert(band<m_nband+1);
95 if(getRasterBand(band))
96 return((getRasterBand(band)->GetRasterDataType()));
97 else
98 return(m_dataType);
99}

◆ getDeltaX()

double ImgRasterGdal::getDeltaX ( void  ) const
inline

Get the pixel cell spacing in x.

Definition at line 152 of file ImgRasterGdal.h.

152{double gt[6];getGeoTransform(gt);return gt[1];};

◆ getDeltaY()

double ImgRasterGdal::getDeltaY ( void  ) const
inline

Get the pixel cell spacing in y.

Definition at line 154 of file ImgRasterGdal.h.

154{double gt[6];getGeoTransform(gt);return -gt[5];};

◆ getDescription()

std::string ImgRasterGdal::getDescription ( ) const

Get the image description from the driver of this dataset.

Returns
the description of this data set in string format

Definition at line 254 of file ImgRasterGdal.cc.

255{
256 if(m_gds){
257 if(m_gds->GetDriver()->GetDescription()!=NULL)
258 return m_gds->GetDriver()->GetDescription();
259 }
260 else
261 return("");
262}

◆ getDriverDescription()

std::string ImgRasterGdal::getDriverDescription ( ) const

Get the GDAL driver description of this dataset.

Returns
the driver description of this data set in string format

Definition at line 131 of file ImgRasterGdal.cc.

132{
133 std::string driverDescription;
134 if(m_gds)
135 driverDescription=m_gds->GetDriver()->GetDescription();
136 return(driverDescription);
137}

◆ getFileName()

std::string ImgRasterGdal::getFileName ( ) const
inline

Get the filename of this dataset.

Definition at line 96 of file ImgRasterGdal.h.

96{return m_filename;};
std::string m_filename
filename of this dataset

◆ getGeoTransform() [1/2]

std::string ImgRasterGdal::getGeoTransform ( ) const

Get the geotransform data for this dataset as a string.

Returns
the geotransform of this data set in string format

Definition at line 200 of file ImgRasterGdal.cc.

201{
202 std::string gtString;
203 double gt[6];// { 444720, 30, 0, 3751320, 0, -30 };
204 getGeoTransform(gt);
205 std::ostringstream s;
206 s << "[" << gt[0] << "," << gt[1] << "," << gt[2] << "," << gt[3] << "," << gt[4] << "," << gt[5] << "]";
207 gtString=s.str();
208 return(s.str());
209}

◆ getGeoTransform() [2/2]

void ImgRasterGdal::getGeoTransform ( double *  gt) const

Get the geotransform data for this dataset.

Parameters
gtpointer to the six geotransform parameters:
adfGeoTransform[0]top left x
GeoTransform[1]w-e pixel resolution
GeoTransform[2]rotation, 0 if image is "north up"
GeoTransform[3]top left y
GeoTransform[4]rotation, 0 if image is "north up"
GeoTransform[5]n-s pixel resolution

Definition at line 183 of file ImgRasterGdal.cc.

183 {
184 // if(m_gds){
185 // m_gds->GetGeoTransform(gt);
186 // }
187 // else{
188 gt[0]=m_gt[0];
189 gt[1]=m_gt[1];
190 gt[2]=m_gt[2];
191 gt[3]=m_gt[3];
192 gt[4]=m_gt[4];
193 gt[5]=m_gt[5];
194 // }
195}
double m_gt[6]
geotransform information of this dataset

◆ getImageDescription()

std::string ImgRasterGdal::getImageDescription ( ) const

Get the image description from the metadata of this dataset.

Returns
the image description (TIFFTAG) of this data set in string format

Definition at line 280 of file ImgRasterGdal.cc.

281{
282 if(m_gds){
283 if(m_gds->GetDriver()->GetMetadataItem("TIFFTAG_IMAGEDESCRIPTION")!=NULL)
284 return m_gds->GetDriver()->GetMetadataItem("TIFFTAG_IMAGEDESCRIPTION");
285 }
286 else
287 return("");
288}

◆ getImageType()

std::string ImgRasterGdal::getImageType ( ) const
inline

Get the image type (implemented as the driver description)

Definition at line 164 of file ImgRasterGdal.h.

164{return getDriverDescription();};
std::string getDriverDescription() const
Get the GDAL driver description of this dataset.

◆ getInterleave()

std::string ImgRasterGdal::getInterleave ( ) const

Get the band coding (interleave)

Returns
the band coding interleave of this data set in string format

Definition at line 293 of file ImgRasterGdal.cc.

294{
295 if(m_gds){
296 if(m_gds->GetMetadataItem( "INTERLEAVE", "IMAGE_STRUCTURE"))
297 return m_gds->GetMetadataItem( "INTERLEAVE", "IMAGE_STRUCTURE");
298 else
299 return("BAND");
300 }
301 else
302 return("");
303}

◆ getLrx()

double ImgRasterGdal::getLrx ( ) const
inline

Get the lower right corner x (georeferenced) coordinate of this dataset.

Definition at line 130 of file ImgRasterGdal.h.

130{double ulx, uly, lrx,lry;getBoundingBox(ulx,uly,lrx,lry);return(lrx);};

◆ getLry()

double ImgRasterGdal::getLry ( ) const
inline

Get the lower right corner y (georeferenced) coordinate of this dataset.

Definition at line 132 of file ImgRasterGdal.h.

132{double ulx, uly, lrx,lry;getBoundingBox(ulx,uly,lrx,lry);return(lry);};

◆ getMetadata() [1/3]

char ** ImgRasterGdal::getMetadata ( )

Get the metadata of this dataset.

Returns
the metadata of this data set in string format

Definition at line 214 of file ImgRasterGdal.cc.

215{
216 if(m_gds){
217 if(m_gds->GetMetadata()!=NULL)
218 return(m_gds->GetMetadata());
219 }
220 else
221 return (char**)"";
222}

◆ getMetadata() [2/3]

char ** ImgRasterGdal::getMetadata ( ) const

Get the metadata of this dataset (const version)

Returns
the metadata of this data set in C style string format (const version)

Definition at line 227 of file ImgRasterGdal.cc.

228{
229 if(m_gds){
230 if(m_gds->GetMetadata()!=NULL)
231 return(m_gds->GetMetadata());
232 }
233 else
234 return (char**)"";
235}

◆ getMetadata() [3/3]

void ImgRasterGdal::getMetadata ( std::list< std::string > &  metadata) const

Get the metadata of this dataset in the form of a list of strings (const version)

Returns
the metadata of this data set in standard template library (stl) string format

Definition at line 240 of file ImgRasterGdal.cc.

241{
242 if(m_gds){
243 char** cmetadata=m_gds->GetMetadata();
244 while(*cmetadata!=NULL){
245 metadata.push_back(*(cmetadata));
246 ++cmetadata;
247 }
248 }
249}

◆ getMetadataItem()

std::string ImgRasterGdal::getMetadataItem ( ) const

Get metadata item of this dataset.

Returns
the meta data item of this data set in string format

Definition at line 267 of file ImgRasterGdal.cc.

268{
269 if(m_gds){
270 if(m_gds->GetDriver()->GetMetadataItem( GDAL_DMD_LONGNAME )!=NULL)
271 return m_gds->GetDriver()->GetMetadataItem( GDAL_DMD_LONGNAME );
272 }
273 else
274 return("");
275}

◆ getNoDataValues()

int ImgRasterGdal::getNoDataValues ( std::vector< double > &  noDataValues) const

Get the no data values of this dataset as a standard template library (stl) vector.

Parameters
noDataValuesstandard template library (stl) vector containing no data values
Returns
number of no data values in this dataset

Definition at line 478 of file ImgRasterGdal.cc.

479{
480 if(m_noDataValues.size()){
481 noDataValues=m_noDataValues;
482 return m_noDataValues.size();
483 }
484 else
485 return 0;
486}
std::vector< double > m_noDataValues
no data values for this dataset

◆ getProjection()

std::string ImgRasterGdal::getProjection ( void  ) const

Get the projection string (deprecated, use getProjectionRef instead)

Returns
the projection of this data set in string format

Definition at line 40 of file ImgRasterGdal.cc.

41{
42 // if(m_gds)
43 // return(m_gds->GetProjectionRef());
44 // else
45 return(m_projection);
46}

◆ getProjectionRef()

std::string ImgRasterGdal::getProjectionRef ( void  ) const

Get the projection reference.

Returns
the projection of this data set in string format

Definition at line 51 of file ImgRasterGdal.cc.

52{
53 // if(m_gds)
54 // return(m_gds->GetProjectionRef());
55 // else
56 return(m_projection);
57}

◆ getRasterBand()

GDALRasterBand * ImgRasterGdal::getRasterBand ( int  band = 0) const

Get the GDAL rasterband for this dataset.

Parameters
bandget GDAL raster band for this band (start counting from 0)
Returns
the GDAL raster band of this data set for the selected band

Definition at line 105 of file ImgRasterGdal.cc.

106{
107 assert(band<m_nband+1);
108 if(m_gds)
109 return((m_gds->GetRasterBand(band+1)));
110 else
111 return(0);
112}

◆ getUlx()

double ImgRasterGdal::getUlx ( ) const
inline

Get the upper left corner x (georeferenced) coordinate of this dataset.

Definition at line 126 of file ImgRasterGdal.h.

126{double ulx, uly, lrx,lry;getBoundingBox(ulx,uly,lrx,lry);return(ulx);};

◆ getUly()

double ImgRasterGdal::getUly ( ) const
inline

Get the upper left corner y (georeferenced) coordinate of this dataset.

Definition at line 128 of file ImgRasterGdal.h.

128{double ulx, uly, lrx,lry;getBoundingBox(ulx,uly,lrx,lry);return(uly);};

◆ image2geo()

bool ImgRasterGdal::image2geo ( double  i,
double  j,
double &  x,
double &  y 
) const

Convert image coordinates (column and row) to georeferenced coordinates (x and y)

assuming adfGeotransform[0]: ULX (upper left X coordinate) adfGeotransform[1]: $cos(\alpha)\cdot\textrm{Xres}$ adfGeotransform[2]: $-sin(\alpha)\cdot\textrm{Xres}$ adfGeotransform[3]: ULY (upper left Y coordinate) adfGeotransform[4]: $-sin(\alpha)\cdot\textrm{Yres}$ adfGeotransform[5]: $-cos(\alpha)\cdot\textrm{Yres}$

Parameters
i,jimage coordinates (can be fraction of pixels)
x,ygeoreferenced coordinates in x and y (can be fraction of pixels)
Returns
true if image is georeferenced

Definition at line 416 of file ImgRasterGdal.cc.

417{
418 double gt[6];// { 444720, 30, 0, 3751320, 0, -30 };
419 getGeoTransform(gt);
420
421 x=gt[0]+(0.5+i)*gt[1]+(0.5+j)*gt[2];
422 y=gt[3]+(0.5+i)*gt[4]+(0.5+j)*gt[5];
423 if(isGeoRef()){
424 // x=m_ulx+(0.5+i)*m_delta_x;
425 // y=m_uly-(0.5+j)*m_delta_y;
426 return true;
427 }
428 else
429 return false;
430}

◆ isGeoRef()

bool ImgRasterGdal::isGeoRef ( ) const
inline

Is this dataset georeferenced (pixel size in y must be negative) ?

Definition at line 104 of file ImgRasterGdal.h.

104{double gt[6];getGeoTransform(gt);if(gt[5]<0) return true;else return false;};

◆ isNoData()

bool ImgRasterGdal::isNoData ( double  value) const
inline

Check if value is nodata in this dataset.

Definition at line 136 of file ImgRasterGdal.h.

136{if(m_noDataValues.empty()) return false;else return find(m_noDataValues.begin(),m_noDataValues.end(),value)!=m_noDataValues.end();};

◆ nrOfBand()

int ImgRasterGdal::nrOfBand ( void  ) const
inline

Get the number of bands of this dataset.

Definition at line 102 of file ImgRasterGdal.h.

102{ return m_nband;};

◆ nrOfBlockX()

int ImgRasterGdal::nrOfBlockX ( int  band = 0)
inline

Definition at line 183 of file ImgRasterGdal.h.

184 {
185 int nXBlockSize, nYBlockSize;
186 getRasterBand(band)->GetBlockSize( &nXBlockSize, &nYBlockSize );
187 int nXBlocks = (nrOfCol() + nXBlockSize - 1) / nXBlockSize;
188 return nXBlocks;
189 }

◆ nrOfBlockY()

int ImgRasterGdal::nrOfBlockY ( int  band = 0)
inline

Definition at line 190 of file ImgRasterGdal.h.

191 {
192 int nXBlockSize, nYBlockSize;
193 getRasterBand(band)->GetBlockSize( &nXBlockSize, &nYBlockSize );
194 int nYBlocks = (nrOfRow() + nYBlockSize - 1) / nYBlockSize;
195 return nYBlocks;
196 }

◆ nrOfCol()

int ImgRasterGdal::nrOfCol ( void  ) const
inline

Get the number of columns of this dataset.

Definition at line 98 of file ImgRasterGdal.h.

98{ return m_ncol;};

◆ nrOfRow()

int ImgRasterGdal::nrOfRow ( void  ) const
inline

Get the number of rows of this dataset.

Definition at line 100 of file ImgRasterGdal.h.

100{ return m_nrow;};

◆ pushNoDataValue()

int ImgRasterGdal::pushNoDataValue ( double  noDataValue)

Push a no data value for this dataset.

Parameters
noDataValueno data value to be pushed for this dataset
Returns
number of no data values in this dataset

Definition at line 492 of file ImgRasterGdal.cc.

493{
494 if(find(m_noDataValues.begin(),m_noDataValues.end(),noDataValue)==m_noDataValues.end())
495 m_noDataValues.push_back(noDataValue);
496 return(m_noDataValues.size());
497}

◆ setGeoTransform()

CPLErr ImgRasterGdal::setGeoTransform ( double *  gt)

Set the geotransform data for this dataset.

Parameters
gtpointer to the six geotransform parameters:
adfGeoTransform[0]top left x
GeoTransform[1]w-e pixel resolution
GeoTransform[2]rotation, 0 if image is "north up"
GeoTransform[3]top left y
GeoTransform[4]rotation, 0 if image is "north up"
GeoTransform[5]n-s pixel resolution

Definition at line 148 of file ImgRasterGdal.cc.

148 {
149 // m_isGeoRef=true;
150 m_gt[0]=gt[0];
151 m_gt[1]=gt[1];
152 m_gt[2]=gt[2];
153 m_gt[3]=gt[3];
154 m_gt[4]=gt[4];
155 m_gt[5]=gt[5];
156 if(m_gds)
157 return(m_gds->SetGeoTransform(m_gt));
158 else
159 return(CE_Failure);
160
161}

◆ setNoData()

int ImgRasterGdal::setNoData ( const std::vector< double >  nodata)
inline

Set the no data values of this dataset using a standard template library (stl) vector as input.

Definition at line 140 of file ImgRasterGdal.h.

140{m_noDataValues=nodata; return(m_noDataValues.size());};

◆ setOffset()

void ImgRasterGdal::setOffset ( double  theOffset,
int  band = 0 
)
inline

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.

Definition at line 84 of file ImgRasterGdal.h.

84 {
85 if(m_offset.size()!=nrOfBand()){
86 m_offset.resize(nrOfBand());
87 for(int iband=0;iband<nrOfBand();++iband)
88 m_offset[iband]=0.0;
89 }
90 m_offset[band]=theOffset;
91 };
int nrOfBand(void) const
Get the number of bands of this dataset.
std::vector< double > m_offset
Vector containing the offset factor to be applied (one offset value for each band)

◆ setProjection()

CPLErr ImgRasterGdal::setProjection ( const std::string &  projection)

Set the projection for this dataset in well known text (wkt) format.

Parameters
projectionprojection string to be used for this dataset

Definition at line 79 of file ImgRasterGdal.cc.

80{
81 m_projection=projection;
82 if(m_gds)
83 return(m_gds->SetProjection(projection.c_str()));
84 else
85 return(CE_Failure);
86}

◆ setProjectionProj4()

CPLErr ImgRasterGdal::setProjectionProj4 ( const std::string &  projection)

Set the projection for this dataset from user input (supports epsg:<number> format)

Parameters
projectionprojection string to be used for this dataset
Returns
the projection of this data set in string format

Definition at line 63 of file ImgRasterGdal.cc.

64{
65 OGRSpatialReference theRef;
66 theRef.SetFromUserInput(projection.c_str());
67 char *wktString;
68 theRef.exportToWkt(&wktString);
69 m_projection=wktString;
70 if(m_gds)
71 return(m_gds->SetProjection(wktString));
72 else
73 return(CE_Failure);
74}

◆ setScale()

void ImgRasterGdal::setScale ( double  theScale,
int  band = 0 
)
inline

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.

Definition at line 75 of file ImgRasterGdal.h.

75 {
76 if(m_scale.size()!=nrOfBand()){//initialize
77 m_scale.resize(nrOfBand());
78 for(int iband=0;iband<nrOfBand();++iband)
79 m_scale[iband]=1.0;
80 }
81 m_scale[band]=theScale;
82 };
std::vector< double > m_scale
Vector containing the scale factor to be applied (one scale value for each band)

Friends And Related Function Documentation

◆ ImgReaderGdal

friend class ImgReaderGdal ( void  )
friend

Definition at line 198 of file ImgRasterGdal.h.

◆ ImgWriterGdal

friend class ImgWriterGdal ( void  )
friend

Definition at line 199 of file ImgRasterGdal.h.

Member Data Documentation

◆ m_dataType

GDALDataType ImgRasterGdal::m_dataType
protected

GDAL data type for this dataset.

Definition at line 213 of file ImgRasterGdal.h.

◆ m_filename

std::string ImgRasterGdal::m_filename
protected

filename of this dataset

Definition at line 203 of file ImgRasterGdal.h.

◆ m_gds

GDALDataset* ImgRasterGdal::m_gds
protected

instance of the GDAL dataset of this dataset

Definition at line 205 of file ImgRasterGdal.h.

◆ m_gt

double ImgRasterGdal::m_gt[6]
protected

geotransform information of this dataset

Definition at line 215 of file ImgRasterGdal.h.

◆ m_nband

int ImgRasterGdal::m_nband
protected

number of bands in this dataset

Definition at line 211 of file ImgRasterGdal.h.

◆ m_ncol

int ImgRasterGdal::m_ncol
protected

number of columns in this dataset

Definition at line 207 of file ImgRasterGdal.h.

◆ m_noDataValues

std::vector<double> ImgRasterGdal::m_noDataValues
protected

no data values for this dataset

Definition at line 219 of file ImgRasterGdal.h.

◆ m_nrow

int ImgRasterGdal::m_nrow
protected

number of rows in this dataset

Definition at line 209 of file ImgRasterGdal.h.

◆ m_offset

std::vector<double> ImgRasterGdal::m_offset
protected

Vector containing the offset factor to be applied (one offset value for each band)

Definition at line 223 of file ImgRasterGdal.h.

◆ m_projection

std::string ImgRasterGdal::m_projection
protected

Definition at line 217 of file ImgRasterGdal.h.

◆ m_scale

std::vector<double> ImgRasterGdal::m_scale
protected

Vector containing the scale factor to be applied (one scale value for each band)

Definition at line 221 of file ImgRasterGdal.h.


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