QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
Public Member Functions | Static Public Member Functions | List of all members
QgsRasterBlock Class Reference

Raster data container. More...

#include <qgsrasterblock.h>

Public Member Functions

 QgsRasterBlock ()
 
 QgsRasterBlock (QGis::DataType theDataType, int theWidth, int theHeight)
 Constructor which allocates data block in memory. More...
 
 QgsRasterBlock (QGis::DataType theDataType, int theWidth, int theHeight, double theNoDataValue)
 Constructor which allocates data block in memory. More...
 
virtual ~QgsRasterBlock ()
 
void applyNoDataValues (const QgsRasterRangeList &rangeList)
 
void applyScaleOffset (double scale, double offset)
 Apply band scale and offset to raster block values @note added in 2.3. More...
 
char * bits (int row, int column)
 Get pointer to data. More...
 
char * bits (qgssize index)
 Get pointer to data. More...
 
char * bits ()
 Get pointer to data. More...
 
QRgb color (int row, int column) const
 Read a single color. More...
 
QRgb color (qgssize index) const
 Read a single value. More...
 
bool convert (QGis::DataType destDataType)
 Convert data to different type. More...
 
QGis::DataType dataType () const
 Returns data type. More...
 
int dataTypeSize () const
 
QgsError error () const
 Get error. More...
 
bool hasNoData () const
 Returns true if the block may contain no data. More...
 
bool hasNoDataValue () const
 True if the block has no data value. More...
 
int height () const
 Returns the height (number of rows) of the raster block. More...
 
QImage image () const
 Get image if type is color. More...
 
bool isEmpty () const
 Returns true if block is empty, i.e. More...
 
bool isNoData (int row, int column)
 Check if value at position is no data. More...
 
bool isNoData (qgssize index)
 Check if value at position is no data. More...
 
bool isValid () const
 Returns true if the block is valid (correctly filled with data). More...
 
double noDataValue () const
 Return no data value. More...
 
bool reset (QGis::DataType theDataType, int theWidth, int theHeight)
 Reset block. More...
 
bool reset (QGis::DataType theDataType, int theWidth, int theHeight, double theNoDataValue)
 Reset block. More...
 
bool setColor (int row, int column, QRgb color)
 Set color on position. More...
 
bool setColor (qgssize index, QRgb color)
 Set color on index (indexed line by line) More...
 
void setError (const QgsError &theError)
 Set error. More...
 
bool setImage (const QImage *image)
 set image. More...
 
void setIsData (int row, int column)
 Remove no data flag on pixel. More...
 
void setIsData (qgssize index)
 Remove no data flag on pixel. More...
 
bool setIsNoData (int row, int column)
 Set no data on pixel. More...
 
bool setIsNoData (qgssize index)
 Set no data on pixel. More...
 
bool setIsNoData ()
 Set the whole block to no data. More...
 
bool setIsNoDataExcept (QRect theExceptRect)
 Set the whole block to no data except specified rectangle. More...
 
void setValid (bool valid)
 Mark block as valid or invalid. More...
 
bool setValue (int row, int column, double value)
 Set value on position. More...
 
bool setValue (qgssize index, double value)
 Set value on index (indexed line by line) More...
 
QString toString () const
 
double value (int row, int column) const
 Read a single value if type of block is numeric. More...
 
double value (qgssize index) const
 Read a single value if type of block is numeric. More...
 
int width () const
 Returns the width (number of columns) of the raster block. More...
 

Static Public Member Functions

static QString printValue (double value)
 Print double value with all necessary significant digits. More...
 
static QString printValue (float value)
 Print float value with all necessary significant digits. More...
 
static double readValue (void *data, QGis::DataType type, qgssize index)
 
static QRect subRect (const QgsRectangle &theExtent, int theWidth, int theHeight, const QgsRectangle &theSubExtent)
 For theExtent and theWidht, theHeight find rectangle covered by subextent. More...
 
static bool typeIsColor (QGis::DataType type)
 Returns true if data type is color. More...
 
static bool typeIsNumeric (QGis::DataType type)
 Returns true if data type is numeric. More...
 
static int typeSize (int dataType)
 
static QGis::DataType typeWithNoDataValue (QGis::DataType dataType, double *noDataValue)
 For given data type returns wider type and sets no data value. More...
 
static QByteArray valueBytes (QGis::DataType theDataType, double theValue)
 Get byte array representing a value. More...
 
static void writeValue (void *data, QGis::DataType type, qgssize index, double value)
 

Detailed Description

Raster data container.

Definition at line 32 of file qgsrasterblock.h.

Constructor & Destructor Documentation

◆ QgsRasterBlock() [1/3]

QgsRasterBlock::QgsRasterBlock ( )

Definition at line 29 of file qgsrasterblock.cpp.

◆ QgsRasterBlock() [2/3]

QgsRasterBlock::QgsRasterBlock ( QGis::DataType  theDataType,
int  theWidth,
int  theHeight 
)

Constructor which allocates data block in memory.

Parameters
theDataTyperaster data type
theWidthwidth of data matrix
theHeightheight of data matrix
Note
not available in python bindings (use variant with theNoDataValue)

Definition at line 45 of file qgsrasterblock.cpp.

◆ QgsRasterBlock() [3/3]

QgsRasterBlock::QgsRasterBlock ( QGis::DataType  theDataType,
int  theWidth,
int  theHeight,
double  theNoDataValue 
)

Constructor which allocates data block in memory.

Parameters
theDataTyperaster data type
theWidthwidth of data matrix
theHeightheight of data matrix
theNoDataValuethe value representing no data (NULL)

Definition at line 62 of file qgsrasterblock.cpp.

◆ ~QgsRasterBlock()

QgsRasterBlock::~QgsRasterBlock ( )
virtual

Definition at line 79 of file qgsrasterblock.cpp.

Member Function Documentation

◆ applyNoDataValues()

void QgsRasterBlock::applyNoDataValues ( const QgsRasterRangeList rangeList)

Definition at line 752 of file qgsrasterblock.cpp.

◆ applyScaleOffset()

void QgsRasterBlock::applyScaleOffset ( double  scale,
double  offset 
)

Apply band scale and offset to raster block values @note added in 2.3.

Definition at line 738 of file qgsrasterblock.cpp.

◆ bits() [1/3]

char * QgsRasterBlock::bits ( int  row,
int  column 
)

Get pointer to data.

Parameters
rowrow index
columncolumn index
Returns
pointer to data
Note
not available in python bindings

Definition at line 684 of file qgsrasterblock.cpp.

◆ bits() [2/3]

char * QgsRasterBlock::bits ( qgssize  index)

Get pointer to data.

Parameters
indexdata matrix index (long type in Python)
Returns
pointer to data
Note
not available in python bindings

Definition at line 664 of file qgsrasterblock.cpp.

◆ bits() [3/3]

char * QgsRasterBlock::bits ( )

Get pointer to data.

Returns
pointer to data
Note
not available in python bindings

Definition at line 689 of file qgsrasterblock.cpp.

◆ color() [1/2]

QRgb QgsRasterBlock::color ( int  row,
int  column 
) const

Read a single color.

Parameters
rowrow index
columncolumn index
Returns
color

Definition at line 305 of file qgsrasterblock.cpp.

◆ color() [2/2]

QRgb QgsRasterBlock::color ( qgssize  index) const

Read a single value.

Parameters
indexdata matrix index (long type in Python)
Returns
color

Definition at line 298 of file qgsrasterblock.cpp.

◆ convert()

bool QgsRasterBlock::convert ( QGis::DataType  destDataType)

Convert data to different type.

Parameters
destDataTypedest data type
Returns
true on success

Definition at line 703 of file qgsrasterblock.cpp.

◆ dataType()

QGis::DataType QgsRasterBlock::dataType ( ) const
inline

Returns data type.

Definition at line 139 of file qgsrasterblock.h.

◆ dataTypeSize()

int QgsRasterBlock::dataTypeSize ( ) const
inline

Definition at line 127 of file qgsrasterblock.h.

◆ error()

QgsError QgsRasterBlock::error ( ) const
inline

Get error.

Definition at line 325 of file qgsrasterblock.h.

◆ hasNoData()

bool QgsRasterBlock::hasNoData ( ) const

Returns true if the block may contain no data.

It does not guarantee that it really contains any no data. It can be used to speed up processing. Not the difference between this method and hasNoDataValue().

Returns
true if the block may contain no data

Definition at line 275 of file qgsrasterblock.cpp.

◆ hasNoDataValue()

bool QgsRasterBlock::hasNoDataValue ( ) const
inline

True if the block has no data value.

Returns
true if the block has no data value

Definition at line 146 of file qgsrasterblock.h.

◆ height()

int QgsRasterBlock::height ( ) const
inline

Returns the height (number of rows) of the raster block.

See also
width
Note
added in QGIS 2.10

Definition at line 353 of file qgsrasterblock.h.

◆ image()

QImage QgsRasterBlock::image ( ) const

Get image if type is color.

Returns
image

Definition at line 771 of file qgsrasterblock.cpp.

◆ isEmpty()

bool QgsRasterBlock::isEmpty ( ) const

Returns true if block is empty, i.e.

its size is 0 (zero rows or cols). This method does not return true if size is not zero and all values are 'no data' (null).

Definition at line 179 of file qgsrasterblock.cpp.

◆ isNoData() [1/2]

bool QgsRasterBlock::isNoData ( int  row,
int  column 
)

Check if value at position is no data.

Parameters
rowrow index
columncolumn index
Returns
true if value is no data

Definition at line 342 of file qgsrasterblock.cpp.

◆ isNoData() [2/2]

bool QgsRasterBlock::isNoData ( qgssize  index)

Check if value at position is no data.

Parameters
indexdata matrix index (long type in Python)
Returns
true if value is no data

Definition at line 312 of file qgsrasterblock.cpp.

◆ isValid()

bool QgsRasterBlock::isValid ( ) const
inline

Returns true if the block is valid (correctly filled with data).

An empty block may still be valid (if zero size block was requested). If the block is not valid, error may be retrieved by error() method.

Definition at line 79 of file qgsrasterblock.h.

◆ noDataValue()

double QgsRasterBlock::noDataValue ( ) const
inline

Return no data value.

If the block does not have a no data value the returned value is undefined.

Returns
No data value

Definition at line 157 of file qgsrasterblock.h.

◆ printValue() [1/2]

QString QgsRasterBlock::printValue ( double  value)
static

Print double value with all necessary significant digits.

It is ensured that conversion back to double gives the same number.

Parameters
valuethe value to be printed
Returns
string representing the value

Definition at line 795 of file qgsrasterblock.cpp.

◆ printValue() [2/2]

QString QgsRasterBlock::printValue ( float  value)
static

Print float value with all necessary significant digits.

It is ensured that conversion back to float gives the same number.

Parameters
valuethe value to be printed
Returns
string representing the value
Note
added in QGIS 2.16
not available in python bindings

Definition at line 834 of file qgsrasterblock.cpp.

◆ readValue()

double QgsRasterBlock::readValue ( void *  data,
QGis::DataType  type,
qgssize  index 
)
inlinestatic
Note
not available in python bindings

Definition at line 428 of file qgsrasterblock.h.

◆ reset() [1/2]

bool QgsRasterBlock::reset ( QGis::DataType  theDataType,
int  theWidth,
int  theHeight 
)

Reset block.

Parameters
theDataTyperaster data type
theWidthwidth of data matrix
theHeightheight of data matrix
Returns
true on success
Note
not available in python bindings (use variant with theNoDataValue)

Definition at line 87 of file qgsrasterblock.cpp.

◆ reset() [2/2]

bool QgsRasterBlock::reset ( QGis::DataType  theDataType,
int  theWidth,
int  theHeight,
double  theNoDataValue 
)

Reset block.

Parameters
theDataTyperaster data type
theWidthwidth of data matrix
theHeightheight of data matrix
theNoDataValuethe value representing no data (NULL)
Returns
true on success

Definition at line 99 of file qgsrasterblock.cpp.

◆ setColor() [1/2]

bool QgsRasterBlock::setColor ( int  row,
int  column,
QRgb  color 
)

Set color on position.

Parameters
rowrow index
columncolumn index
colorthe color to be set, QRgb value
Returns
true on success

Definition at line 368 of file qgsrasterblock.cpp.

◆ setColor() [2/2]

bool QgsRasterBlock::setColor ( qgssize  index,
QRgb  color 
)

Set color on index (indexed line by line)

Parameters
indexdata matrix index (long type in Python)
colorthe color to be set, QRgb value
Returns
true on success

Definition at line 373 of file qgsrasterblock.cpp.

◆ setError()

void QgsRasterBlock::setError ( const QgsError theError)
inline

Set error.

Definition at line 328 of file qgsrasterblock.h.

◆ setImage()

bool QgsRasterBlock::setImage ( const QImage image)

set image.

Parameters
imageimage
Returns
true on success

Definition at line 780 of file qgsrasterblock.cpp.

◆ setIsData() [1/2]

void QgsRasterBlock::setIsData ( int  row,
int  column 
)

Remove no data flag on pixel.

If the raster block does not have an explicit no data value set then an internal map of no data pixels is maintained for the block. In this case it is possible to reset a pixel to flag it as having valid data using this method. This method has no effect for raster blocks with an explicit no data value set.

Parameters
rowrow index
columncolumn index
Note
added in QGIS 2.10

Definition at line 637 of file qgsrasterblock.cpp.

◆ setIsData() [2/2]

void QgsRasterBlock::setIsData ( qgssize  index)

Remove no data flag on pixel.

If the raster block does not have an explicit no data value set then an internal map of no data pixels is maintained for the block. In this case it is possible to reset a pixel to flag it as having valid data using this method. This method has no effect for raster blocks with an explicit no data value set.

Parameters
indexdata matrix index (long type in Python)
Note
added in QGIS 2.10

Definition at line 642 of file qgsrasterblock.cpp.

◆ setIsNoData() [1/3]

bool QgsRasterBlock::setIsNoData ( int  row,
int  column 
)

Set no data on pixel.

Parameters
rowrow index
columncolumn index
Returns
true on success

Definition at line 393 of file qgsrasterblock.cpp.

◆ setIsNoData() [2/3]

bool QgsRasterBlock::setIsNoData ( qgssize  index)

Set no data on pixel.

Parameters
indexdata matrix index (long type in Python)
Returns
true on success

Definition at line 398 of file qgsrasterblock.cpp.

◆ setIsNoData() [3/3]

bool QgsRasterBlock::setIsNoData ( )

Set the whole block to no data.

Returns
true on success

Definition at line 425 of file qgsrasterblock.cpp.

◆ setIsNoDataExcept()

bool QgsRasterBlock::setIsNoDataExcept ( QRect  theExceptRect)

Set the whole block to no data except specified rectangle.

Returns
true on success

Definition at line 477 of file qgsrasterblock.cpp.

◆ setValid()

void QgsRasterBlock::setValid ( bool  valid)
inline

Mark block as valid or invalid.

Definition at line 82 of file qgsrasterblock.h.

◆ setValue() [1/2]

bool QgsRasterBlock::setValue ( int  row,
int  column,
double  value 
)

Set value on position.

Parameters
rowrow index
columncolumn index
valuethe value to be set
Returns
true on success

Definition at line 363 of file qgsrasterblock.cpp.

◆ setValue() [2/2]

bool QgsRasterBlock::setValue ( qgssize  index,
double  value 
)

Set value on index (indexed line by line)

Parameters
indexdata matrix index (long type in Python)
valuethe value to be set
Returns
true on success

Definition at line 347 of file qgsrasterblock.cpp.

◆ subRect()

QRect QgsRasterBlock::subRect ( const QgsRectangle theExtent,
int  theWidth,
int  theHeight,
const QgsRectangle theSubExtent 
)
static

For theExtent and theWidht, theHeight find rectangle covered by subextent.

The output rect has x oriented from left to right and y from top to bottom (upper-left to lower-right orientation).

Parameters
theExtentextent, usually the larger
theWidthnumbers of columns in theExtent
theHeightnumbers of rows in theExtent
theSubExtentextent, usually smaller than theExtent
Returns
the rectangle covered by sub extent

Definition at line 939 of file qgsrasterblock.cpp.

◆ toString()

QString QgsRasterBlock::toString ( ) const

Definition at line 933 of file qgsrasterblock.cpp.

◆ typeIsColor()

bool QgsRasterBlock::typeIsColor ( QGis::DataType  type)
static

Returns true if data type is color.

Definition at line 217 of file qgsrasterblock.cpp.

◆ typeIsNumeric()

bool QgsRasterBlock::typeIsNumeric ( QGis::DataType  type)
static

Returns true if data type is numeric.

Definition at line 192 of file qgsrasterblock.cpp.

◆ typeSize()

static int QgsRasterBlock::typeSize ( int  dataType)
inlinestatic

Definition at line 91 of file qgsrasterblock.h.

◆ typeWithNoDataValue()

QGis::DataType QgsRasterBlock::typeWithNoDataValue ( QGis::DataType  dataType,
double *  noDataValue 
)
static

For given data type returns wider type and sets no data value.

Definition at line 242 of file qgsrasterblock.cpp.

◆ value() [1/2]

double QgsRasterBlock::value ( int  row,
int  column 
) const

Read a single value if type of block is numeric.

If type is color, returned value is undefined.

Parameters
rowrow index
columncolumn index
Returns
value

Definition at line 293 of file qgsrasterblock.cpp.

◆ value() [2/2]

double QgsRasterBlock::value ( qgssize  index) const
inline

Read a single value if type of block is numeric.

If type is color, returned value is undefined.

Parameters
indexdata matrix index (long type in Python)
Returns
value

Definition at line 499 of file qgsrasterblock.h.

◆ valueBytes()

QByteArray QgsRasterBlock::valueBytes ( QGis::DataType  theDataType,
double  theValue 
)
static

Get byte array representing a value.

Parameters
theDataTypedata type
theValuevalue
Returns
byte array representing the value

Definition at line 869 of file qgsrasterblock.cpp.

◆ width()

int QgsRasterBlock::width ( ) const
inline

Returns the width (number of columns) of the raster block.

See also
height
Note
added in QGIS 2.10

Definition at line 347 of file qgsrasterblock.h.

◆ writeValue()

void QgsRasterBlock::writeValue ( void *  data,
QGis::DataType  type,
qgssize  index,
double  value 
)
inlinestatic
Note
not available in python bindings

Definition at line 466 of file qgsrasterblock.h.


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