QGIS API Documentation 3.36.0-Maidenhead (09951dc0acf)
|
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. | |
virtual | ~QgsRasterBlock () |
void | applyNoDataValues (const QgsRasterRangeList &rangeList) |
void | applyScaleOffset (double scale, double offset) |
Apply band scale and offset to raster block values. | |
char * | bits () |
Returns a pointer to block data. | |
char * | bits (int row, int column) |
Returns a pointer to block data. | |
char * | bits (qgssize index) |
Returns a pointer to block data. | |
const quint8 * | byteData () const |
Gives direct access to the raster block data. | |
QRgb | color (int row, int column) const |
Read a single color. | |
QRgb | color (qgssize index) const |
Read a single value. | |
QRgb * | colorData () |
Gives direct read/write access to the raster RGB data. | |
bool | convert (Qgis::DataType destDataType) |
Convert data to different type. | |
QByteArray | data () const |
Gets access to raw data. | |
Qgis::DataType | dataType () const |
Returns data type. | |
int | dataTypeSize () const |
Data type size in bytes. | |
QgsError | error () const |
Returns the last error. | |
bool | hasNoData () const |
Returns true if the block may contain no data. | |
bool | hasNoDataValue () const |
true if the block has no data value. | |
int | height () const |
Returns the height (number of rows) of the raster block. | |
QImage | image () const |
Returns an image containing the block data, if the block's data type is color. | |
bool | isEmpty () const |
Returns true if block is empty, i.e. | |
bool | isNoData (int row, int column) const |
Checks if value at position is no data. | |
bool | isNoData (qgssize index) const |
Check if value at position is no data. | |
bool | isNoData (qgssize row, qgssize column) const |
Check if value at position is no data. | |
bool | isValid () const |
Returns true if the block is valid (correctly filled with data). | |
double | noDataValue () const |
Returns no data value. | |
bool | reset (Qgis::DataType dataType, int width, int height) |
Reset block. | |
void | resetNoDataValue () |
Reset no data value: if there was a no data value previously set, it will be discarded. | |
bool | setColor (int row, int column, QRgb color) |
Set color on position. | |
bool | setColor (qgssize index, QRgb color) |
Set color on index (indexed line by line) | |
void | setData (const QByteArray &data, int offset=0) |
Rewrite raw pixel data. | |
void | setError (const QgsError &error) |
Sets the last error. | |
bool | setImage (const QImage *image) |
Sets the block data via an image. | |
void | setIsData (int row, int column) |
Remove no data flag on pixel. | |
void | setIsData (qgssize index) |
Remove no data flag on pixel. | |
bool | setIsNoData () |
Set the whole block to no data. | |
bool | setIsNoData (int row, int column) |
Set no data on pixel. | |
bool | setIsNoData (qgssize index) |
Set no data on pixel. | |
bool | setIsNoDataExcept (QRect exceptRect) |
Set the whole block to no data except specified rectangle. | |
void | setNoDataValue (double noDataValue) |
Sets cell value that will be considered as "no data". | |
void | setValid (bool valid) |
Mark block as valid or invalid. | |
bool | setValue (int row, int column, double value) |
Set value on position. | |
bool | setValue (qgssize index, double value) |
Set value on index (indexed line by line) | |
QString | toString () const |
double | value (int row, int column) const |
Read a single value if type of block is numeric. | |
double | value (qgssize index) const |
Reads a single value if type of block is numeric. | |
double | valueAndNoData (int row, int column, bool &isNoData) const |
Reads a single value from the pixel at row and column, if type of block is numeric. | |
double | valueAndNoData (qgssize index, bool &isNoData) const |
Reads a single value from the pixel at the specified data matrix index, if type of block is numeric. | |
int | width () const |
Returns the width (number of columns) of the raster block. | |
Static Public Member Functions | |
static QString | printValue (double value) |
Print double value with all necessary significant digits. | |
static QString | printValue (float value) |
Print float value with all necessary significant digits. | |
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. | |
static bool | typeIsColor (Qgis::DataType type) |
Returns true if data type is color. | |
static bool | typeIsNumeric (Qgis::DataType type) |
Returns true if data type is numeric. | |
static int | typeSize (Qgis::DataType dataType) |
Returns the size in bytes for the specified dataType. | |
static Qgis::DataType | typeWithNoDataValue (Qgis::DataType dataType, double *noDataValue) |
For given data type returns wider type and sets no data value. | |
static QByteArray | valueBytes (Qgis::DataType dataType, double value) |
Gets byte array representing a value. | |
static void | writeValue (void *data, Qgis::DataType type, qgssize index, double value) |
Raster data container.
Definition at line 36 of file qgsrasterblock.h.
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.
dataType | raster data type |
width | width of data matrix |
height | height of data matrix |
Definition at line 35 of file qgsrasterblock.cpp.
|
virtual |
Definition at line 44 of file qgsrasterblock.cpp.
void QgsRasterBlock::applyNoDataValues | ( | const QgsRasterRangeList & | rangeList | ) |
Definition at line 584 of file qgsrasterblock.cpp.
void QgsRasterBlock::applyScaleOffset | ( | double | scale, |
double | offset | ||
) |
Apply band scale and offset to raster block values.
Definition at line 571 of file qgsrasterblock.cpp.
char * QgsRasterBlock::bits | ( | ) |
Returns a pointer to block data.
Definition at line 522 of file qgsrasterblock.cpp.
char * QgsRasterBlock::bits | ( | int | row, |
int | column | ||
) |
Returns a pointer to block data.
row | row index |
column | column index |
Definition at line 517 of file qgsrasterblock.cpp.
char * QgsRasterBlock::bits | ( | qgssize | index | ) |
Returns a pointer to block data.
index | data matrix index (long type in Python) |
Definition at line 497 of file qgsrasterblock.cpp.
|
inline |
Gives direct access to the raster block data.
The data type of the block must be Qgis::DataType::Byte otherwise it returns nullptr
. Useful for most efficient read access.
Definition at line 247 of file qgsrasterblock.h.
|
inline |
Read a single color.
row | row index |
column | column index |
Definition at line 260 of file qgsrasterblock.h.
|
inline |
Read a single value.
index | data matrix index (long type in Python) |
Definition at line 272 of file qgsrasterblock.h.
|
inline |
Gives direct read/write access to the raster RGB data.
The data type of the block must be Qgis::DataType::ARGB32 or Qgis::DataType::ARGB32_Premultiplied otherwise it returns nullptr
. Useful for most efficient read/write access to RGB blocks.
Definition at line 419 of file qgsrasterblock.h.
bool QgsRasterBlock::convert | ( | Qgis::DataType | destDataType | ) |
Convert data to different type.
destDataType | dest data type |
true
on success Definition at line 536 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.
Definition at line 470 of file qgsrasterblock.cpp.
|
inline |
Returns data type.
Definition at line 135 of file qgsrasterblock.h.
|
inline |
Data type size in bytes.
Definition at line 123 of file qgsrasterblock.h.
|
inline |
Returns the last error.
Definition at line 613 of file qgsrasterblock.h.
|
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().
true
if the block may contain no data Definition at line 153 of file qgsrasterblock.h.
|
inline |
true
if the block has no data value.
true
if the block has no data value Definition at line 145 of file qgsrasterblock.h.
|
inline |
Returns the height (number of rows) of the raster block.
Definition at line 642 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 603 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.
|
inline |
Checks if value at position is no data.
row | row index |
column | column index |
true
if value is no data Definition at line 286 of file qgsrasterblock.h.
|
inline |
Check if value at position is no data.
index | data matrix index (long type in Python) |
true
if value is no data Definition at line 309 of file qgsrasterblock.h.
Check if value at position is no data.
row | row index |
column | column index |
true
if value is no data Definition at line 298 of file qgsrasterblock.h.
|
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.
|
inline |
Returns no data value.
If the block does not have a no data value the returned value is undefined.
Definition at line 177 of file qgsrasterblock.h.
|
static |
Print double value with all necessary significant digits.
It is ensured that conversion back to double gives the same number.
value | the value to be printed |
Definition at line 627 of file qgsrasterblock.cpp.
|
static |
Print float value with all necessary significant digits.
It is ensured that conversion back to float gives the same number.
value | the value to be printed |
Definition at line 666 of file qgsrasterblock.cpp.
|
inlinestatic |
Definition at line 732 of file qgsrasterblock.h.
bool QgsRasterBlock::reset | ( | Qgis::DataType | dataType, |
int | width, | ||
int | height | ||
) |
Reset block.
dataType | raster data type |
width | width of data matrix |
height | height of data matrix |
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.
Definition at line 237 of file qgsrasterblock.cpp.
|
inline |
Set color on position.
row | row index |
column | column index |
color | the color to be set, QRgb value |
true
on success Definition at line 381 of file qgsrasterblock.h.
|
inline |
Set color on index (indexed line by line)
index | data matrix index (long type in Python) |
color | the color to be set, QRgb value |
true
on success Definition at line 392 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.
Definition at line 480 of file qgsrasterblock.cpp.
|
inline |
Sets the last error.
Definition at line 616 of file qgsrasterblock.h.
bool QgsRasterBlock::setImage | ( | const QImage * | image | ) |
Sets the block data via an image.
true
on success Definition at line 612 of file qgsrasterblock.cpp.
|
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.
row | row index |
column | column index |
Definition at line 489 of file qgsrasterblock.h.
|
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.
index | data matrix index (long type in Python) |
Definition at line 501 of file qgsrasterblock.h.
bool QgsRasterBlock::setIsNoData | ( | ) |
Set the whole block to no data.
true
on success Definition at line 243 of file qgsrasterblock.cpp.
|
inline |
Set no data on pixel.
row | row index |
column | column index |
true
on success Definition at line 432 of file qgsrasterblock.h.
|
inline |
Set no data on pixel.
index | data matrix index (long type in Python) |
true
on success Definition at line 442 of file qgsrasterblock.h.
bool QgsRasterBlock::setIsNoDataExcept | ( | QRect | exceptRect | ) |
Set the whole block to no data except specified rectangle.
true
on success Definition at line 305 of file qgsrasterblock.cpp.
void QgsRasterBlock::setNoDataValue | ( | double | noDataValue | ) |
Sets cell value that will be considered as "no data".
Definition at line 231 of file qgsrasterblock.cpp.
|
inline |
Mark block as valid or invalid.
Definition at line 71 of file qgsrasterblock.h.
|
inline |
Set value on position.
row | row index |
column | column index |
value | the value to be set |
true
on success Definition at line 347 of file qgsrasterblock.h.
|
inline |
Set value on index (indexed line by line)
index | data matrix index (long type in Python) |
value | the value to be set |
true
on success Definition at line 358 of file qgsrasterblock.h.
|
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).
extent | extent, usually the larger |
width | numbers of columns in theExtent |
height | numbers of rows in theExtent |
subExtent | extent, usually smaller than theExtent |
Definition at line 783 of file qgsrasterblock.cpp.
QString QgsRasterBlock::toString | ( | ) | const |
Definition at line 777 of file qgsrasterblock.cpp.
|
static |
Returns true
if data type is color.
Definition at line 165 of file qgsrasterblock.cpp.
|
static |
Returns true
if data type is numeric.
Definition at line 139 of file qgsrasterblock.cpp.
|
inlinestatic |
Returns the size in bytes for the specified dataType.
Definition at line 83 of file qgsrasterblock.h.
|
static |
For given data type returns wider type and sets no data value.
Definition at line 191 of file qgsrasterblock.cpp.
|
inline |
Read a single value if type of block is numeric.
If type is color, returned value is undefined.
row | row index |
column | column index |
Definition at line 195 of file qgsrasterblock.h.
|
inline |
Reads a single value if type of block is numeric.
If type is color, returned value is undefined.
index | data matrix index (long type in Python) |
Definition at line 813 of file qgsrasterblock.h.
|
inline |
Reads a single value from the pixel at row and column, if type of block is numeric.
If type is color, returned value is undefined.
Additionally, the isNoData argument will be set to true
if the pixel represents a nodata value. This method is more efficient then calling isNoData() and value() separately.
Definition at line 212 of file qgsrasterblock.h.
|
inline |
Reads a single value from the pixel at the specified data matrix index, if type of block is numeric.
If type is color, returned value is undefined.
Additionally, the isNoData argument will be set to true
if the pixel represents a nodata value. This method is more efficient then calling isNoData() and value() separately.
Definition at line 823 of file qgsrasterblock.h.
|
static |
Gets byte array representing a value.
dataType | data type |
value | value |
Definition at line 701 of file qgsrasterblock.cpp.
|
inline |
Returns the width (number of columns) of the raster block.
Definition at line 636 of file qgsrasterblock.h.
|
inlinestatic |
Definition at line 771 of file qgsrasterblock.h.