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.
Methods
- param rangeList
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
- rtype
int
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.
Check 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.
- rtype
str
Returns true if data type is color
Returns true if data type is numeric
- param dataType
For 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.
-
applyNoDataValues
(self, rangeList: object)¶ - Parameters
rangeList (object) –
-
applyScaleOffset
(self, scale: float, offset: float)¶ Apply band scale and offset to raster block values
New in version 2.3.
- Parameters
scale (float) –
offset (float) –
-
color
(self, row: int, column: int) → int¶ Read a single color
- Parameters
row (int) – row index
column (int) – column index
- Returns
color *
color(self, index: int) -> int Read a single value
- Parameters
index – data matrix index (long type in Python)
- Return type
int
- Returns
color *
-
convert
(self, destDataType: Qgis.DataType) → bool¶ Convert data to different type.
- Parameters
destDataType (Qgis.DataType) – dest data type
- Return type
bool
- 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 theQgsRasterBlock
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.
- Return type
QByteArray
-
dataType
(self) → Qgis.DataType¶ Returns data type
- Return type
-
dataTypeSize
(self) → int¶ - Return type
int
-
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().
- Return type
bool
- Returns
true if the block may contain no data *
-
hasNoDataValue
(self) → bool¶ True if the block has no data value.
- Return type
bool
- 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.
- Return type
int
-
image
(self) → QImage¶ Returns an image containing the block data, if the block’s data type is color.
- Return type
QImage
-
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).
- Return type
bool
-
isNoData
(self, row: int, column: int) → bool¶ Check if value at position is no data
- Parameters
row (int) – row index
column (int) – column index
- Returns
true if value is no data *
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)
- Return type
bool
- 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.
- Return type
bool
-
noDataValue
(self) → float¶ Returns no data value. If the block does not have a no data value the returned value is undefined.
- Return type
float
- 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 (float) – the value to be printed
- Return type
str
- Returns
string representing the value*
-
reset
(self, dataType: Qgis.DataType, width: int, height: int) → bool¶ Reset block
- Parameters
dataType (Qgis.DataType) – raster data type
width (int) – width of data matrix
height (int) – height of data matrix
- Return type
bool
- 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 (int) – row index
column (int) – column index
color (int) – 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
- Return type
bool
- 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.
- Parameters
data (Union[QByteArray) –
offset (int = 0) –
-
setImage
(self, image: QImage) → bool¶ Sets the block data via an
image
.- Return type
bool
- Returns
true on success
- Parameters
image (QImage) –
-
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 (int) – row index
column (int) – 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 (int) – row index
column (int) – 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
- Return type
bool
- Returns
true on success *
-
setIsNoDataExcept
(self, exceptRect: QRect) → bool¶ Set the whole block to no data except specified rectangle
- Return type
bool
- Returns
true on success *
- Parameters
exceptRect (QRect) –
-
setNoDataValue
(self, noDataValue: float)¶ Sets cell value that will be considered as “no data”.
See also
New in version 3.0.
- Parameters
noDataValue (float) –
-
setValid
(self, valid: bool)¶ Mark block as valid or invalid
- Parameters
valid (bool) –
-
setValue
(self, row: int, column: int, value: float) → bool¶ Set value on position
- Parameters
row (int) – row index
column (int) – column index
value (float) – 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
- Return type
bool
- 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 (QgsRectangle) – extent, usually the larger
width (int) – numbers of columns in theExtent
height (int) – numbers of rows in theExtent
subExtent (QgsRectangle) – extent, usually smaller than theExtent
- Return type
QRect
- Returns
the rectangle covered by sub extent
-
toString
(self) → str¶ - Return type
str
-
typeIsColor
(type: Qgis.DataType) → bool¶ Returns true if data type is color
- Parameters
type (Qgis.DataType) –
- Return type
bool
-
typeIsNumeric
(type: Qgis.DataType) → bool¶ Returns true if data type is numeric
- Parameters
type (Qgis.DataType) –
- Return type
bool
-
typeSize
(dataType: int) → int¶ - Parameters
dataType (int) –
- Return type
int
-
typeWithNoDataValue
(dataType: Qgis.DataType) → Tuple[Qgis.DataType, float]¶ For given data type returns wider type and sets no data value
- Parameters
dataType (Qgis.DataType) –
- Return type
Tuple[Qgis.DataType, float]
-
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 (int) – row index
column (int) – 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)
- Return type
float
- Returns
value *
-
valueBytes
(dataType: Qgis.DataType, value: float) → QByteArray¶ Gets byte array representing a value.
- Parameters
dataType (Qgis.DataType) – data type
value (float) – value
- Return type
QByteArray
- Returns
byte array representing the value *