Class: QgsRasterInterface

class qgis.core.QgsRasterInterface

Bases: sip.wrapper

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

Methods

bandCount

Gets number of bands

bandStatistics

Returns the band statistics.

block

Read block of data using given extent and size.

capabilities

Returns a bitmask containing the supported capabilities

capabilitiesString

Returns the above in friendly format.

clone

Clone itself, create deep copy

cumulativeCut

Find values for cumulative pixel count cut.

dataType

Returns data type for the band specified by number

dataTypeSize

param bandNo

extent

Gets the extent of the interface.

generateBandName

helper function to create zero padded band names

hasHistogram

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

hasStatistics

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

histogram

Returns a band histogram.

initHistogram

Fill in histogram defaults if not specified

initStatistics

Fill in statistics defaults if not specified

input

Current input

on

Returns whether the interface is on or off

readXml

Sets base class members from xml.

setInput

Set input.

setOn

Sets whether the interface is on or off

sourceDataType

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

sourceInput

Gets source / raw input, the first in pipe, usually provider.

writeXml

Write base class members to xml.

xBlockSize

Gets block size

xSize

Gets raster size

yBlockSize

rtype

int

ySize

rtype

int

Attributes

BuildPyramids

Create

Identify

IdentifyFeature

IdentifyHtml

IdentifyText

IdentifyValue

NoCapabilities

Remove

Size

BuildPyramids = 16
class Capability

Bases: int

Create = 4
Identify = 32
IdentifyFeature = 512
IdentifyHtml = 256
IdentifyText = 128
IdentifyValue = 64
NoCapabilities = 0
Remove = 8
Size = 2
bandCount(self) → int

Gets number of bands

Return type

int

bandStatistics(self, bandNo: int, stats: int = QgsRasterBandStats.All, extent: QgsRectangle = QgsRectangle(), sampleSize: int = 0, feedback: QgsRasterBlockFeedback = None) → QgsRasterBandStats

Returns the band statistics.

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

  • stats (int = QgsRasterBandStats.All) – 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 (QgsRasterBlockFeedback = None) – optional feedback object

Return type

QgsRasterBandStats

block(self, bandNo: int, extent: QgsRectangle, width: int, height: int, feedback: QgsRasterBlockFeedback = None) → QgsRasterBlock

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 (QgsRasterBlockFeedback = None) – optional raster feedback object for cancellation/preview. Added in QGIS 3.0.

Return type

QgsRasterBlock

capabilities(self) → int

Returns a bitmask containing the supported capabilities

Return type

int

capabilitiesString(self) → str

Returns the above in friendly format.

Return type

str

clone(self) → QgsRasterInterface

Clone itself, create deep copy

Return type

QgsRasterInterface

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

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) – 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.

Return type

Tuple[float, float]

dataType(self, bandNo: int) → Qgis.DataType

Returns data type for the band specified by number

Parameters

bandNo (int) –

Return type

Qgis.DataType

dataTypeSize(self, bandNo: int) → int
Parameters

bandNo (int) –

Return type

int

extent(self) → QgsRectangle

Gets the extent of the interface.

Return type

QgsRectangle

Returns

QgsRectangle containing the extent of the layer

generateBandName(self, bandNumber: int) → str

helper function to create zero padded band names

Parameters

bandNumber (int) –

Return type

str

hasHistogram(self, bandNo: int, binCount: int, minimum: object = Py_None, maximum: object = Py_None, extent: QgsRectangle = QgsRectangle(), sampleSize: int = 0, includeOutOfRange: bool = False) → bool

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

Note

the parameters are the same as in histogram()

Parameters
  • bandNo (int) –

  • binCount (int) –

  • minimum (object = Py_None) –

  • maximum (object = Py_None) –

  • extent (QgsRectangle = QgsRectangle()) –

  • sampleSize (int = 0) –

  • includeOutOfRange (bool = False) –

Return type

bool

hasStatistics(self, bandNo: int, stats: int = QgsRasterBandStats.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 = QgsRasterBandStats.All) –

  • extent (QgsRectangle = QgsRectangle()) –

  • sampleSize (int = 0) –

histogram(self, bandNo: int, binCount: int = 0, minimum: object = Py_None, maximum: object = Py_None, extent: QgsRectangle = QgsRectangle(), sampleSize: int = 0, includeOutOfRange: bool = False, feedback: QgsRasterBlockFeedback = None) → QgsRasterHistogram

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 (object = Py_None) – Minimum value, if NaN (None for Python), raster minimum value will be used.

  • maximum (object = 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 (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: object = Py_None, maximum: object = Py_None, boundingBox: QgsRectangle = QgsRectangle(), sampleSize: int = 0, includeOutOfRange: bool = False)

Fill in histogram defaults if not specified

Note

the parameters are the same as in histogram()

Parameters
  • histogram (QgsRasterHistogram) –

  • bandNo (int) –

  • binCount (int) –

  • minimum (object = Py_None) –

  • maximum (object = Py_None) –

  • boundingBox (QgsRectangle = QgsRectangle()) –

  • sampleSize (int = 0) –

  • includeOutOfRange (bool = False) –

initStatistics(self, statistics: QgsRasterBandStats, bandNo: int, stats: int = QgsRasterBandStats.All, boundingBox: QgsRectangle = QgsRectangle(), binCount: int = 0)

Fill in statistics defaults if not specified

Parameters
  • statistics (QgsRasterBandStats) –

  • bandNo (int) –

  • stats (int = QgsRasterBandStats.All) –

  • boundingBox (QgsRectangle = QgsRectangle()) –

  • binCount (int = 0) –

input(self) → QgsRasterInterface

Current input

Return type

QgsRasterInterface

on(self) → bool

Returns whether the interface is on or off

Return type

bool

readXml(self, filterElem: QDomElement)

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

Parameters

filterElem (QDomElement) –

setInput(self, input: QgsRasterInterface) → bool

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

Parameters

input (QgsRasterInterface) –

Return type

bool

setOn(self, on: bool)

Sets whether the interface is on or off

Parameters

on (bool) –

sourceDataType(self, bandNo: int) → Qgis.DataType

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

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

QgsRasterInterface

writeXml(self, doc: QDomDocument, parentElem: QDomElement)

Write base class members to xml.

Parameters
  • doc (QDomDocument) –

  • parentElem (QDomElement) –

xBlockSize(self) → int

Gets block size

Return type

int

xSize(self) → int

Gets raster size

Return type

int

yBlockSize(self) → int
Return type

int

ySize(self) → int
Return type

int