Subgroup: Raster
Class: QgsRasterBlock¶
-
class
qgis.core.
QgsRasterBlock
¶ Bases:
sip.wrapper
Raster data container.
Methods
applyNoDataValues
applyScaleOffset
Apply band scale and offset to raster block values color
Read a single color convert
Convert data to different type. data
Get access to raw data. dataType
Returns data type dataTypeSize
error
Get error hasNoData
Returns true if the block may contain no data. hasNoDataValue
True if the block has no data value. height
Returns the height (number of rows) of the raster block. image
Get image if type is color. isEmpty
Returns true if block is empty, i.e. isNoData
Check if value at position is no data isValid
Returns true if the block is valid (correctly filled with data). noDataValue
Return no data value. printValue
Print double value with all necessary significant digits. reset
Reset block resetNoDataValue
Reset no data value: if there was a no data value previously set, it will be discarded. setColor
Set color on position setData
Rewrite raw pixel data. setError
Set error setImage
set image. setIsData
Remove no data flag on pixel. setIsNoData
Set no data on pixel setIsNoDataExcept
Set the whole block to no data except specified rectangle setNoDataValue
Sets cell value that will be considered as “no data”. setValid
Mark block as valid or invalid setValue
Set value on position subRect
For extent and width, height find rectangle covered by subextent. toString
typeIsColor
Returns true if data type is color typeIsNumeric
Returns true if data type is numeric typeSize
typeWithNoDataValue
For given data type returns wider type and sets no data value value
Read a single value if type of block is numeric. valueBytes
Get byte array representing a value. width
Returns the width (number of columns) of the raster block. Attributes
-
applyNoDataValues
(self, rangeList: object)¶
-
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¶ Get 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¶ Get 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¶ Get image if type is color.
Returns: image *
-
isEmpty
(self) → bool¶ 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).
-
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 *
- 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 *
-
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¶ Return 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.
New in version 3.0.
See also
-
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)¶ Set error
-
setImage
(self, image: QImage) → bool¶ set image.
Parameters: image – 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”.
New in version 3.0.
See also
-
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 *
- value(self, index: int) -> float
- Read 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 *
-
valueBytes
(dataType: Qgis.DataType, value: float) → QByteArray¶ Get byte array representing a value.
Parameters: - dataType – data type
- value – value
Returns: byte array representing the value *
-