Class: QgsRasterInterface

Base class for processing filters like renderers, reprojector, resampler etc.

Class Hierarchy

Inheritance diagram of qgis.core.QgsRasterInterface

Subclasses

QgsBrightnessContrastFilter

Brightness/contrast and gamma correction filter pipe for rasters.

QgsRasterRenderer

Raster renderer pipe that applies colors to a raster.

QgsHueSaturationFilter

Color and saturation filter pipe for rasters.

QgsRasterDataProvider

Base class for raster data providers.

QgsRasterNuller

Raster pipe that deals with null values.

QgsRasterProjector

Implements approximate projection support for optimised raster transformation.

QgsRasterResampleFilter

Resample filter pipe for rasters.

class qgis.core.QgsRasterInterface[source]

Bases: object

Capability

alias of RasterInterfaceCapability

bandCount(self) int[source]

Gets number of bands

Return type:

int

bandStatistics(self, bandNo: int, stats: int, extent: QgsRectangle = QgsRectangle(), sampleSize: int = 0, feedback: QgsRasterBlockFeedback | None = None) QgsRasterBandStats[source]

Returns the band statistics.

Parameters:
  • bandNo (int) – The band (number).

  • stats (int) – Requested statistics

  • extent (QgsRectangle = QgsRectangle()) – Extent used to calc statistics, if empty, whole raster extent is used.

  • sampleSize (int = 0) – Approximate number of cells in sample. If 0, all cells (whole raster will be used). If raster does not have exact size (WCS without exact size for example), provider decides size of sample.

  • feedback (Optional[QgsRasterBlockFeedback] = None) – optional feedback object

Deprecated since version 3.40: Use Qgis.RasterBandStatistic instead of int for stats argument.

bandStatistics(self, bandNo: int, stats: Union[Qgis.RasterBandStatistics, Qgis.RasterBandStatistic] = Qgis.RasterBandStatistic.All, extent: QgsRectangle = QgsRectangle(), sampleSize: int = 0, feedback: Optional[QgsRasterBlockFeedback] = None) -> QgsRasterBandStats Returns the band statistics.

Parameters:
  • bandNo – The band (number).

  • stats – Requested statistics

  • extent – Extent used to calc statistics, if empty, whole raster extent is used.

  • sampleSize – Approximate number of cells in sample. If 0, all cells (whole raster will be used). If raster does not have exact size (WCS without exact size for example), provider decides size of sample.

  • feedback – optional feedback object

Return type:

QgsRasterBandStats

block(self, bandNo: int, extent: QgsRectangle, width: int, height: int, feedback: QgsRasterBlockFeedback | None = None) QgsRasterBlock | None[source]

Read block of data using given extent and size. Returns pointer to data. Caller is responsible to free the memory returned.

Parameters:
  • bandNo (int) – band number

  • extent (QgsRectangle) – extent of block

  • width (int) – pixel width of block

  • height (int) – pixel height of block

  • feedback (Optional[QgsRasterBlockFeedback] = None) – optional raster feedback object for cancellation/preview. Added in QGIS 3.0.

Return type:

Optional[QgsRasterBlock]

capabilities(self) Qgis.RasterInterfaceCapabilities[source]

Returns the capabilities supported by the interface.

Return type:

Qgis.RasterInterfaceCapabilities

capabilitiesString(self) str[source]

Returns the raster interface capabilities in friendly format.

Deprecated since version 3.40: Will be removed in QGIS 4.0.

Return type:

str

clone(self) QgsRasterInterface | None[source]

Clone itself, create deep copy

Return type:

Optional[QgsRasterInterface]

colorInterpretationName(self, bandNumber: int) str[source]

Returns the name of the color interpretation for the specified bandNumber. It is translated since QGIS 3.40

Added in version 3.18.

Parameters:

bandNumber (int)

Return type:

str

cumulativeCut(self, bandNo: int, lowerCount: float, upperCount: float, extent: QgsRectangle = QgsRectangle(), sampleSize: int = 0)[source]

Find values for cumulative pixel count cut.

Parameters:
  • bandNo (int) – The band (number).

  • lowerCount (float) – The lower count as fraction of 1, e.g. 0.02 = 2%

  • upperCount (float) – The upper count as fraction of 1, e.g. 0.98 = 98%

  • lowerValue – Location into which the lower value will be set.

  • upperValue – Location into which the upper value will be set.

  • extent (QgsRectangle = QgsRectangle()) – Extent used to calc histogram, if empty, whole raster extent is used.

  • sampleSize (int = 0) -> (float) – Approximate number of cells in sample. If 0, all cells (whole raster will be used). If raster does not have exact size (WCS without exact size for example), provider decides size of sample.

dataType(self, bandNo: int) Qgis.DataType[source]

Returns data type for the band specified by number

Parameters:

bandNo (int)

Return type:

Qgis.DataType

dataTypeSize(self, bandNo: int) int[source]

Returns the size (in bytes) for the data type for the specified band.

Parameters:

bandNo (int)

Return type:

int

displayBandName(self, bandNumber: int) str[source]

Generates a friendly, descriptive name for the specified bandNumber.

Added in version 3.18.

Parameters:

bandNumber (int)

Return type:

str

extent(self) QgsRectangle[source]

Gets the extent of the interface.

Return type:

QgsRectangle

Returns:

QgsRectangle containing the extent of the layer

generateBandName(self, bandNumber: int) str[source]

helper function to create zero padded band names

Parameters:

bandNumber (int)

Return type:

str

hasHistogram(self, bandNo: int, binCount: int, minimum: Any = Py_None, maximum: Any = Py_None, extent: QgsRectangle = QgsRectangle(), sampleSize: int = 0, includeOutOfRange: bool = False) bool[source]

Returns True if histogram is available (cached, already calculated)

Note

the parameters are the same as in histogram()

Parameters:
  • bandNo (int)

  • binCount (int)

  • minimum (Any = Py_None)

  • maximum (Any = Py_None)

  • extent (QgsRectangle = QgsRectangle())

  • sampleSize (int = 0)

  • includeOutOfRange (bool = False)

Return type:

bool

hasStatistics(self, bandNo: int, stats: int, extent: QgsRectangle = QgsRectangle(), sampleSize: int = 0) bool[source]

Returns True if histogram is available (cached, already calculated). The parameters are the same as in bandStatistics()

Returns:

True if statistics are available (ready to use)

Deprecated since version 3.40: Use Qgis.RasterBandStatistic instead of int for stats argument.

hasStatistics(self, bandNo: int, stats: Union[Qgis.RasterBandStatistics, Qgis.RasterBandStatistic] = Qgis.RasterBandStatistic.All, extent: QgsRectangle = QgsRectangle(), sampleSize: int = 0) -> bool Returns True if histogram is available (cached, already calculated). The parameters are the same as in bandStatistics()

Return type:

bool

Returns:

True if statistics are available (ready to use)

Parameters:
  • bandNo (int)

  • stats (int)

  • extent (QgsRectangle = QgsRectangle())

  • sampleSize (int = 0)

histogram(self, bandNo: int, binCount: int = 0, minimum: Any = Py_None, maximum: Any = Py_None, extent: QgsRectangle = QgsRectangle(), sampleSize: int = 0, includeOutOfRange: bool = False, feedback: QgsRasterBlockFeedback | None = None) QgsRasterHistogram[source]

Returns a band histogram. Histograms are cached in providers.

Parameters:
  • bandNo (int) – The band (number).

  • binCount (int = 0) – Number of bins (intervals,buckets). If 0, the number of bins is decided automatically according to data type, raster size etc.

  • minimum (Any = Py_None) – Minimum value, if NaN (None for Python), raster minimum value will be used.

  • maximum (Any = Py_None) – Maximum value, if NaN (None for Python), raster maximum value will be used.

  • extent (QgsRectangle = QgsRectangle()) – Extent used to calc histogram, if empty, whole raster extent is used.

  • sampleSize (int = 0) – Approximate number of cells in sample. If 0, all cells (whole raster will be used). If raster does not have exact size (WCS without exact size for example), provider decides size of sample.

  • includeOutOfRange (bool = False) – include out of range values

  • feedback (Optional[QgsRasterBlockFeedback] = None) – optional feedback object

Return type:

QgsRasterHistogram

Returns:

Vector of non NULL cell counts for each bin.

Note

binCount, minimum and maximum not optional in Python bindings

initHistogram(self, histogram: QgsRasterHistogram, bandNo: int, binCount: int, minimum: Any = Py_None, maximum: Any = Py_None, boundingBox: QgsRectangle = QgsRectangle(), sampleSize: int = 0, includeOutOfRange: bool = False)[source]

Fill in histogram defaults if not specified

Note

the parameters are the same as in histogram()

Parameters:
  • histogram (QgsRasterHistogram)

  • bandNo (int)

  • binCount (int)

  • minimum (Any = Py_None)

  • maximum (Any = Py_None)

  • boundingBox (QgsRectangle = QgsRectangle())

  • sampleSize (int = 0)

  • includeOutOfRange (bool = False)

initStatistics(self, statistics: QgsRasterBandStats, bandNo: int, stats: int, boundingBox: QgsRectangle = QgsRectangle(), binCount: int = 0)[source]

Fill in statistics defaults if not specified

Deprecated since version 3.40: Use Qgis.RasterBandStatistic instead of int for stats argument.

initStatistics(self, statistics: QgsRasterBandStats, bandNo: int, stats: Union[Qgis.RasterBandStatistics, Qgis.RasterBandStatistic] = Qgis.RasterBandStatistic.All, boundingBox: QgsRectangle = QgsRectangle(), binCount: int = 0) Fill in statistics defaults if not specified

Parameters:
input(self) QgsRasterInterface | None[source]

Current input

Return type:

Optional[QgsRasterInterface]

on(self) bool[source]

Returns whether the interface is on or off

Return type:

bool

readXml(self, filterElem: QDomElement)[source]

Sets base class members from xml. Usually called from create() methods of subclasses

Parameters:

filterElem (QDomElement)

setInput(self, input: QgsRasterInterface | None) bool[source]

Set input. Returns True if set correctly, False if cannot use that input

Parameters:

input (Optional[QgsRasterInterface])

Return type:

bool

setOn(self, on: bool)[source]

Sets whether the interface is on or off

Parameters:

on (bool)

sourceDataType(self, bandNo: int) Qgis.DataType[source]

Returns source data type for the band specified by number, source data type may be shorter than dataType

Parameters:

bandNo (int)

Return type:

Qgis.DataType

sourceInput(self) QgsRasterInterface | None[source]

Gets source / raw input, the first in pipe, usually provider. It may be used to get info about original data, e.g. resolution to decide resampling etc.

Return type:

Optional[QgsRasterInterface]

writeXml(self, doc: QDomDocument, parentElem: QDomElement)[source]

Write base class members to xml.

Parameters:
  • doc (QDomDocument)

  • parentElem (QDomElement)

xBlockSize(self) int[source]

Gets block size

Return type:

int

xSize(self) int[source]

Gets raster size

Return type:

int

yBlockSize(self) int[source]
Return type:

int

ySize(self) int[source]
Return type:

int