Class: QgsRasterTransparency

class qgis.core.QgsRasterTransparency

Bases: sip.wrapper

Defines the list of pixel values to be considered as transparent or semi transparent when rendering rasters.

QgsRasterTransparency() Constructor for QgsRasterTransparency.

QgsRasterTransparency(QgsRasterTransparency)

Methods

alphaValue

Returns the transparency value for a single value pixel.

initializeTransparentPixelList

Resets the transparency list to a single value.

isEmpty

True if there are no entries in the pixel lists except the nodata value

opacityForRgbValues

Returns the opacity (as a value from 0 to 1) for a set of RGB pixel values.

opacityForValue

Returns the opacity (as a value from 0 to 1) for a single value pixel.

readXml

Reads the transparency information from an XML document.

setTransparentSingleValuePixelList

Sets the transparent single value pixel list, replacing the whole existing list.

setTransparentThreeValuePixelList

Sets the transparent three value pixel list, replacing the whole existing list.

transparentSingleValuePixelList

Returns the transparent single value pixel list.

transparentThreeValuePixelList

Returns the transparent three value pixel list.

writeXml

Writes the transparency information to an XML document.

class TransparentSingleValuePixel(minimum: float = 0, maximum: float = 0, opacity: float = 0, includeMinimum: bool = True, includeMaximum: bool = True)

Bases: sip.wrapper

Constructor for TransparentSingleValuePixel.

Parameters:
  • minimum – minimum pixel value to include in range

  • maximum – maximum pixel value to include in range

  • opacity – opacity for pixel, between 0 and 1.0

  • includeMinimum – whether the minimum value should be included in the range

  • includeMaximum – whether the maximum value should be included in the range

New in version 3.38.

QgsRasterTransparency.TransparentSingleValuePixel(QgsRasterTransparency.TransparentSingleValuePixel)

includeMaximum
includeMinimum
max
min
opacity
property percentTransparent
class TransparentThreeValuePixel(red: float = 0, green: float = 0, blue: float = 0, opacity: float = 0)

Bases: sip.wrapper

Constructor for TransparentThreeValuePixel.

Parameters:
  • red – red pixel value

  • green – green pixel value

  • blue – blue pixel value

  • opacity – opacity for pixel, between 0 and 1.0

New in version 3.38.

QgsRasterTransparency.TransparentThreeValuePixel(QgsRasterTransparency.TransparentThreeValuePixel)

blue
green
opacity
property percentTransparent
red
alphaValue(self, value: float, globalTransparency: int = 255) int

Returns the transparency value for a single value pixel.

Searches through the transparency list, and if a match is found, the global transparency value is scaled by the stored transparency value.

Parameters:
  • value (float) – the needle to search for in the transparency hay stack

  • globalTransparency (int = 255) – the overall transparency level for the layer

Deprecated since version use: opacityForValue() instead.

alphaValue(self, redValue: float, greenValue: float, blueValue: float, globalTransparency: int = 255) -> int Returns the transparency value for a RGB pixel.

Searches through the transparency list, if a match is found, the global transparency value is scaled by the stored transparency value.

Parameters:
  • redValue – the red portion of the needle to search for in the transparency hay stack

  • greenValue – the green portion of the needle to search for in the transparency hay stack

  • blueValue – the green portion of the needle to search for in the transparency hay stack

  • globalTransparency – the overall transparency level for the layer

Deprecated since version use: opacityForRgbValues() instead.

Return type:

int

initializeTransparentPixelList(self, value: float)

Resets the transparency list to a single value.

initializeTransparentPixelList(self, redValue: float, greenValue: float, blueValue: float) Resets the transparency list to single red, green, and blue values.

Parameters:

value (float) –

isEmpty(self) bool

True if there are no entries in the pixel lists except the nodata value

Return type:

bool

opacityForRgbValues(self, redValue: float, greenValue: float, blueValue: float) float

Returns the opacity (as a value from 0 to 1) for a set of RGB pixel values.

Searches through the transparency list, and if a match is found, returns the opacity corresponding to the values. Returns 1 if no matches are found.

If any of the red, green or blue values are NaN, 0 will be returned.

New in version 3.38.

Parameters:
  • redValue (float) –

  • greenValue (float) –

  • blueValue (float) –

Return type:

float

opacityForValue(self, value: float) float

Returns the opacity (as a value from 0 to 1) for a single value pixel.

Searches through the transparency list, and if a match is found, returns the opacity corresponding to the value. Returns 1 if no matches are found.

New in version 3.38.

Parameters:

value (float) –

Return type:

float

readXml(self, elem: QDomElement)

Reads the transparency information from an XML document.

Parameters:

elem (QDomElement) –

setTransparentSingleValuePixelList(self, newList: Iterable[QgsRasterTransparency.TransparentSingleValuePixel])

Sets the transparent single value pixel list, replacing the whole existing list.

Parameters:

newList (Iterable[QgsRasterTransparency.TransparentSingleValuePixel]) –

setTransparentThreeValuePixelList(self, newList: Iterable[QgsRasterTransparency.TransparentThreeValuePixel])

Sets the transparent three value pixel list, replacing the whole existing list.

Parameters:

newList (Iterable[QgsRasterTransparency.TransparentThreeValuePixel]) –

transparentSingleValuePixelList(self) List[QgsRasterTransparency.TransparentSingleValuePixel]

Returns the transparent single value pixel list.

Return type:

List[QgsRasterTransparency.TransparentSingleValuePixel]

transparentThreeValuePixelList(self) List[QgsRasterTransparency.TransparentThreeValuePixel]

Returns the transparent three value pixel list.

Return type:

List[QgsRasterTransparency.TransparentThreeValuePixel]

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

Writes the transparency information to an XML document.

Parameters:
  • doc (QDomDocument) –

  • parentElem (QDomElement) –