Class: QgsRasterBlock¶
-
class
qgis.core.
QgsRasterBlock
¶ Bases:
sip.wrapper
QgsRasterBlock(dataType: Qgis.DataType, width: int, height: int) Constructor which allocates data block in memory
- Parameters
dataType – raster data type
width – width of data matrix
height – height of data matrix
QgsRasterBlock(QgsRasterBlock)
Raster data container.
Enums
Methods
Apply band scale and offset to raster block values
Read a single color
Convert data to different type.
Gets access to raw data.
Returns data type
Returns the last error
Returns
True
if the block may contain no data.True
if the block has no data value.Returns the height (number of rows) of the raster block.
Returns an image containing the block data, if the block’s data type is color.
Returns
True
if block is empty, i.e.Checks if value at position is no data
Returns
True
if the block is valid (correctly filled with data).Returns no data value.
Print double value with all necessary significant digits.
Reset block
Reset no data value: if there was a no data value previously set, it will be discarded.
Set color on position
Rewrite raw pixel data.
Sets the last error
Sets the block data via an
image
.Remove no data flag on pixel.
Set no data on pixel
Set the whole block to no data except specified rectangle
Sets cell value that will be considered as “no data”.
Mark block as valid or invalid
Set value on position
For extent and width, height find rectangle covered by subextent.
Returns
True
if data type is colorReturns
True
if data type is numericFor given data type returns wider type and sets no data value
Read a single value if type of block is numeric.
Gets byte array representing a value.
Returns the width (number of columns) of the raster block.
Signals
Attributes
-
applyNoDataValues
(self, rangeList: Iterable[QgsRasterRange])¶
-
applyScaleOffset
(self, scale: float, offset: float)¶ Apply band scale and offset to raster block values
New in version 2.3.
-
color
(self, row: int, column: int) → int¶ Read a single color
- Parameters
row – row index
column – column index
- Returns
color
color(self, index: int) -> int Read a single value
- Parameters
index – data matrix index (long type in Python)
- Returns
color
-
convert
(self, destDataType: Qgis.DataType) → bool¶ Convert data to different type.
- Parameters
destDataType – dest data type
- Returns
True
on success
-
data
(self) → QByteArray¶ 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
New in version 3.0.
-
dataType
(self) → Qgis.DataType¶ Returns data type
-
dataTypeSize
(self) → int¶
-
error
(self) → QgsError¶ Returns the last error
-
hasNoData
(self) → bool¶ 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
-
hasNoDataValue
(self) → bool¶ True
if the block has no data value.- Returns
True
if the block has no data value
See also
-
height
(self) → int¶ Returns the height (number of rows) of the raster block.
See also
New in version 2.10.
-
image
(self) → QImage¶ Returns an image containing the block data, if the block’s data type is color.
-
isEmpty
(self) → bool¶ Returns
True
if block is empty, i.e. its size is 0 (zero rows or cols). This method does not returnTrue
if size is not zero and all values are ‘no data’ (null).
-
isNoData
(self, row: int, column: int) → bool¶ Checks if value at position is no data
- Parameters
row – row index
column – column index
- Returns
True
if value is no data
See also
valueAndNoData()
isNoData(self, row: int, column: int) -> bool Check if value at position is no data
- Parameters
row – row index
column – column index
- Returns
True
if value is no data
See also
valueAndNoData()
isNoData(self, index: int) -> bool Check if value at position is no data
- Parameters
index – data matrix index (long type in Python)
- Returns
True
if value is no data
See also
valueAndNoData()
-
isValid
(self) → bool¶ 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.
-
noDataValue
(self) → float¶ 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
-
printValue
(value: float) → str¶ Print double value with all necessary significant digits. It is ensured that conversion back to double gives the same number.
- Parameters
value – the value to be printed
- Returns
string representing the value*
-
reset
(self, dataType: Qgis.DataType, width: int, height: int) → bool¶ Reset block
- Parameters
dataType – raster data type
width – width of data matrix
height – height of data matrix
- Returns
True
on success
-
resetNoDataValue
(self)¶ Reset no data value: if there was a no data value previously set, it will be discarded.
See also
New in version 3.0.
-
setColor
(self, row: int, column: int, color: int) → bool¶ Set color on position
- Parameters
row – row index
column – column index
color – the color to be set, QRgb value
- Returns
True
on success
setColor(self, index: int, color: int) -> bool Set color on index (indexed line by line)
- Parameters
index – data matrix index (long type in Python)
color – the color to be set, QRgb value
- Returns
True
on success
-
setData
(self, data: Union[QByteArray, bytes, bytearray], offset: int = 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.
New in version 3.0.
-
setError
(self, error: QgsError)¶ Sets the last error
-
setImage
(self, image: QImage) → bool¶ Sets the block data via an
image
.- Returns
True
on success
-
setIsData
(self, row: int, column: int)¶ 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
row – row index
column – column index
New in version 2.10.
setIsData(self, index: int) 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
index – data matrix index (long type in Python)
New in version 2.10.
-
setIsNoData
(self, row: int, column: int) → bool¶ Set no data on pixel
- Parameters
row – row index
column – column index
- Returns
True
on success
setIsNoData(self, index: int) -> bool Set no data on pixel
- Parameters
index – data matrix index (long type in Python)
- Returns
True
on success
setIsNoData(self) -> bool Set the whole block to no data
- Returns
True
on success
-
setIsNoDataExcept
(self, exceptRect: QRect) → bool¶ Set the whole block to no data except specified rectangle
- Returns
True
on success
-
setNoDataValue
(self, noDataValue: float)¶ Sets cell value that will be considered as “no data”.
See also
New in version 3.0.
-
setValid
(self, valid: bool)¶ Mark block as valid or invalid
-
setValue
(self, row: int, column: int, value: float) → bool¶ Set value on position
- Parameters
row – row index
column – column index
value – the value to be set
- Returns
True
on success
setValue(self, index: int, value: float) -> bool Set value on index (indexed line by line)
- Parameters
index – data matrix index (long type in Python)
value – the value to be set
- Returns
True
on success
-
subRect
(extent: QgsRectangle, width: int, height: int, subExtent: QgsRectangle) → QRect¶ 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
extent – extent, usually the larger
width – numbers of columns in theExtent
height – numbers of rows in theExtent
subExtent – extent, usually smaller than theExtent
- Returns
the rectangle covered by sub extent
-
toString
(self) → str¶
-
typeIsColor
(type: Qgis.DataType) → bool¶ Returns
True
if data type is color
-
typeIsNumeric
(type: Qgis.DataType) → bool¶ Returns
True
if data type is numeric
-
typeSize
(dataType: int) → int¶
-
typeWithNoDataValue
(dataType: Qgis.DataType) → Tuple[Qgis.DataType, float]¶ For given data type returns wider type and sets no data value
-
value
(self, row: int, column: int) → float¶ Read a single value if type of block is numeric. If type is color, returned value is undefined.
- Parameters
row – row index
column – column index
- Returns
value
See also
valueAndNoData()
value(self, index: int) -> float Reads a single value if type of block is numeric. If type is color, returned value is undefined.
- Parameters
index – data matrix index (long type in Python)
- Returns
value
See also
valueAndNoData()
-
valueBytes
(dataType: Qgis.DataType, value: float) → QByteArray¶ Gets byte array representing a value.
- Parameters
dataType – data type
value – value
- Returns
byte array representing the value