QGIS API Documentation  3.4.15-Madeira (e83d02e274)
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 dataType, int width, int height)
 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. More...
 
char * bits (int row, int column)
 Returns a pointer to block data. More...
 
char * bits (qgssize index)
 Returns a pointer to block data. More...
 
char * bits ()
 Returns a pointer to block data. More...
 
const quint8 * byteData () const
 Gives direct access to the raster block data. More...
 
QRgb color (int row, int column) const
 Read a single color. More...
 
QRgb color (qgssize index) const
 Read a single value. More...
 
QRgb * colorData ()
 Gives direct read/write access to the raster RGB data. More...
 
bool convert (Qgis::DataType destDataType)
 Convert data to different type. More...
 
QByteArray data () const
 Gets access to raw data. More...
 
Qgis::DataType dataType () const
 Returns data type. More...
 
int dataTypeSize () const
 
QgsError error () const
 Returns the last 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
 Returns an image containing the block data, if the block's data type is color. More...
 
bool isEmpty () const
 Returns true if block is empty, i.e. More...
 
bool isNoData (int row, int column) const
 Check if value at position is no data. More...
 
bool isNoData (qgssize row, qgssize column) const
 Check if value at position is no data. More...
 
bool isNoData (qgssize index) const
 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
 Returns no data value. More...
 
bool reset (Qgis::DataType dataType, int width, int height)
 Reset block. More...
 
void resetNoDataValue ()
 Reset no data value: if there was a no data value previously set, it will be discarded. 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 setData (const QByteArray &data, int offset=0)
 Rewrite raw pixel data. More...
 
void setError (const QgsError &error)
 Sets the last error. More...
 
bool setImage (const QImage *image)
 Sets the block data via an 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 exceptRect)
 Set the whole block to no data except specified rectangle. More...
 
void setNoDataValue (double noDataValue)
 Sets cell value that will be considered as "no data". 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 &extent, int width, int height, const QgsRectangle &subExtent)
 For extent and width, height 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 dataType, double value)
 Gets 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 36 of file qgsrasterblock.h.

Constructor & Destructor Documentation

QgsRasterBlock::QgsRasterBlock ( )

Definition at line 30 of file qgsrasterblock.cpp.

QgsRasterBlock::QgsRasterBlock ( Qgis::DataType  dataType,
int  width,
int  height 
)

Constructor which allocates data block in memory.

Parameters
dataTyperaster data type
widthwidth of data matrix
heightheight of data matrix

Definition at line 35 of file qgsrasterblock.cpp.

QgsRasterBlock::~QgsRasterBlock ( )
virtual

Definition at line 44 of file qgsrasterblock.cpp.

Member Function Documentation

void QgsRasterBlock::applyNoDataValues ( const QgsRasterRangeList rangeList)

Definition at line 575 of file qgsrasterblock.cpp.

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

Apply band scale and offset to raster block values.

Since
QGIS 2.3

Definition at line 562 of file qgsrasterblock.cpp.

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

Returns a pointer to block data.

Parameters
rowrow index
columncolumn index
Note
not available in Python bindings

Definition at line 508 of file qgsrasterblock.cpp.

char * QgsRasterBlock::bits ( qgssize  index)

Returns a pointer to block data.

Parameters
indexdata matrix index (long type in Python)
Note
not available in Python bindings

Definition at line 488 of file qgsrasterblock.cpp.

char * QgsRasterBlock::bits ( )

Returns a pointer to block data.

Note
not available in Python bindings

Definition at line 513 of file qgsrasterblock.cpp.

const quint8* QgsRasterBlock::byteData ( ) const
inline

Gives direct access to the raster block data.

The data type of the block must be Qgis::Byte otherwise it returns null pointer. Useful for most efficient read access.

Note
not available in Python bindings
Since
QGIS 3.4

Definition at line 206 of file qgsrasterblock.h.

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

Read a single color.

Parameters
rowrow index
columncolumn index
Returns
color

Definition at line 218 of file qgsrasterblock.h.

QRgb QgsRasterBlock::color ( qgssize  index) const
inline

Read a single value.

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

Definition at line 229 of file qgsrasterblock.h.

QRgb* QgsRasterBlock::colorData ( )
inline

Gives direct read/write access to the raster RGB data.

The data type of the block must be Qgis::ARGB32 or Qgis::ARGB32_Premultiplied otherwise it returns null pointer. Useful for most efficient read/write access to RGB blocks.

Note
not available in Python bindings
Since
QGIS 3.4

Definition at line 366 of file qgsrasterblock.h.

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

Convert data to different type.

Parameters
destDataTypedest data type
Returns
true on success

Definition at line 527 of file qgsrasterblock.cpp.

QByteArray QgsRasterBlock::data ( ) const

Gets access to raw data.

The returned QByteArray instance is not a copy of the data: it only refers to the array owned by the QgsRasterBlock, therefore it is only valid while the QgsRasterBlock object still exists. Writing to the returned QByteArray will not affect the original data: a deep copy of the data will be made and only the local copy will be modified.

Note
in Python the method returns ordinary bytes object as the
Since
QGIS 3.0

Definition at line 461 of file qgsrasterblock.cpp.

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

Returns data type.

Definition at line 129 of file qgsrasterblock.h.

int QgsRasterBlock::dataTypeSize ( ) const
inline

Definition at line 117 of file qgsrasterblock.h.

QgsError QgsRasterBlock::error ( ) const
inline

Returns the last error.

Definition at line 558 of file qgsrasterblock.h.

bool QgsRasterBlock::hasNoData ( ) const
inline

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 146 of file qgsrasterblock.h.

bool QgsRasterBlock::hasNoDataValue ( ) const
inline

True if the block has no data value.

Returns
true if the block has no data value
See also
noDataValue(), setNoDataValue(), resetNoDataValue()

Definition at line 139 of file qgsrasterblock.h.

int QgsRasterBlock::height ( ) const
inline

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

See also
width
Since
QGIS 2.10

Definition at line 589 of file qgsrasterblock.h.

QImage QgsRasterBlock::image ( ) const

Returns an image containing the block data, if the block's data type is color.

Definition at line 594 of file qgsrasterblock.cpp.

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 130 of file qgsrasterblock.cpp.

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

Check if value at position is no data.

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

Definition at line 241 of file qgsrasterblock.h.

bool QgsRasterBlock::isNoData ( qgssize  row,
qgssize  column 
) const
inline

Check if value at position is no data.

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

Definition at line 251 of file qgsrasterblock.h.

bool QgsRasterBlock::isNoData ( qgssize  index) const
inline

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 260 of file qgsrasterblock.h.

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 68 of file qgsrasterblock.h.

double QgsRasterBlock::noDataValue ( ) const
inline

Returns no data value.

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

Returns
No data value
See also
hasNoDataValue(), setNoDataValue(), resetNoDataValue()

Definition at line 172 of file qgsrasterblock.h.

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 618 of file qgsrasterblock.cpp.

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
not available in Python bindings
Since
QGIS 2.16

Definition at line 657 of file qgsrasterblock.cpp.

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

Definition at line 675 of file qgsrasterblock.h.

bool QgsRasterBlock::reset ( Qgis::DataType  dataType,
int  width,
int  height 
)

Reset block.

Parameters
dataTyperaster data type
widthwidth of data matrix
heightheight of data matrix
Returns
true on success

Definition at line 52 of file qgsrasterblock.cpp.

void QgsRasterBlock::resetNoDataValue ( )

Reset no data value: if there was a no data value previously set, it will be discarded.

See also
noDataValue(), hasNoDataValue(), setNoDataValue()
Since
QGIS 3.0

Definition at line 228 of file qgsrasterblock.cpp.

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

Set color on position.

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

Definition at line 329 of file qgsrasterblock.h.

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

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 339 of file qgsrasterblock.h.

void QgsRasterBlock::setData ( const QByteArray &  data,
int  offset = 0 
)

Rewrite raw pixel data.

If the data array is shorter than the internal array within the raster block object, pixels at the end will stay untouched. If the data array is longer than the internal array, only the initial data from the input array will be used. Optionally it is possible to set non-zero offset (in bytes) if the input data should overwrite data somewhere in the middle of the internal buffer.

Since
QGIS 3.0

Definition at line 471 of file qgsrasterblock.cpp.

void QgsRasterBlock::setError ( const QgsError error)
inline

Sets the last error.

Definition at line 561 of file qgsrasterblock.h.

bool QgsRasterBlock::setImage ( const QImage *  image)

Sets the block data via an image.

Returns
true on success

Definition at line 603 of file qgsrasterblock.cpp.

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

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
Since
QGIS 2.10

Definition at line 432 of file qgsrasterblock.h.

void QgsRasterBlock::setIsData ( qgssize  index)
inline

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)
Since
QGIS 2.10

Definition at line 444 of file qgsrasterblock.h.

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

Set no data on pixel.

Parameters
rowrow index
columncolumn index
Returns
true on success

Definition at line 378 of file qgsrasterblock.h.

bool QgsRasterBlock::setIsNoData ( qgssize  index)
inline

Set no data on pixel.

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

Definition at line 387 of file qgsrasterblock.h.

bool QgsRasterBlock::setIsNoData ( )

Set the whole block to no data.

Returns
true on success

Definition at line 234 of file qgsrasterblock.cpp.

bool QgsRasterBlock::setIsNoDataExcept ( QRect  exceptRect)

Set the whole block to no data except specified rectangle.

Returns
true on success

Definition at line 296 of file qgsrasterblock.cpp.

void QgsRasterBlock::setNoDataValue ( double  noDataValue)

Sets cell value that will be considered as "no data".

See also
noDataValue(), hasNoDataValue(), resetNoDataValue()
Since
QGIS 3.0

Definition at line 222 of file qgsrasterblock.cpp.

void QgsRasterBlock::setValid ( bool  valid)
inline

Mark block as valid or invalid.

Definition at line 71 of file qgsrasterblock.h.

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

Set value on position.

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

Definition at line 297 of file qgsrasterblock.h.

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

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 307 of file qgsrasterblock.h.

QRect QgsRasterBlock::subRect ( const QgsRectangle extent,
int  width,
int  height,
const QgsRectangle subExtent 
)
static

For extent and width, height 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
extentextent, usually the larger
widthnumbers of columns in theExtent
heightnumbers of rows in theExtent
subExtentextent, usually smaller than theExtent
Returns
the rectangle covered by sub extent

Definition at line 762 of file qgsrasterblock.cpp.

QString QgsRasterBlock::toString ( ) const

Definition at line 756 of file qgsrasterblock.cpp.

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

Returns true if data type is color.

Definition at line 164 of file qgsrasterblock.cpp.

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

Returns true if data type is numeric.

Definition at line 139 of file qgsrasterblock.cpp.

static int QgsRasterBlock::typeSize ( int  dataType)
inlinestatic

Definition at line 81 of file qgsrasterblock.h.

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 189 of file qgsrasterblock.cpp.

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

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 187 of file qgsrasterblock.h.

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 746 of file qgsrasterblock.h.

QByteArray QgsRasterBlock::valueBytes ( Qgis::DataType  dataType,
double  value 
)
static

Gets byte array representing a value.

Parameters
dataTypedata type
valuevalue
Returns
byte array representing the value

Definition at line 692 of file qgsrasterblock.cpp.

int QgsRasterBlock::width ( ) const
inline

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

See also
height
Since
QGIS 2.10

Definition at line 582 of file qgsrasterblock.h.

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

Definition at line 713 of file qgsrasterblock.h.


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