3.1.1.4.1.1. thyrsis.meshlayer.glmesh module

class thyrsis.meshlayer.glmesh.ColorLegend(parent=None)

Bases : PyQt5.QtWidgets.QGraphicsScene

A legend provides the symbology for a layer. The legend is responsible for the translation of values into color. For performace and flexibility reasons the legend provide shader functions that will take a value and return a color.

static availableRamps()

Return the available color ramps

Renvoie

dictionnary of color ramps

Type renvoyé

dict

colorRamp()

Getter function for colorRampFile value

Renvoie

color ramp file name

Type renvoyé

string

colorRampImg()

Getter function for colorRamp image value

Renvoie

color ramp

Type renvoyé

QImage

createItems()

Returns a QGraphicsItemGroup that contains legend items

Renvoie

legend items

Type renvoyé

QGraphicsItemGroup

graduated()

Getter for graduated attribute. Graduated is boolean

Renvoie

continuous/graduated flag

Type renvoyé

bool

graduation()

Getter for graduation attribute. Graduation is a list of tuple (Qcolor, min, max)

Renvoie

graduation attributes that is a list of tuple (color, min, max)

Type renvoyé

list

hasLogScale()

Getter function to set linear/log scale

Renvoie

bool to evaluate if it uses log scale

Type renvoyé

bool

image()

Return an image representing the legend

Renvoie

image of the legend

Type renvoyé

QImage

maskUnits(flag)

Function to mask unit in the legend, used for probability map

maxValue()

Getter function for max value

Renvoie

max value

Type renvoyé

float

minValue()

Getter function for min value

Renvoie

min value

Type renvoyé

float

nbClass()

Getter for nbClass attribute. Nbclass is a int used for graduated symbology

Renvoie

nbClass attribute

Type renvoyé

integer

readXml(node, rwcontext)

Function to read mesh legend information from project

Paramètres
  • node (QDomElement) – base element of the xml

  • rwcontext (QgsReadWriteContext) – QgsReadWriteContext

setColorRamp(rampImageFile)

Setter function to change the color ramp with a file path

Paramètres

rampImageFile (string) – rampcolor file name

setGraduation(graduation)

Set graduation attributes, that is a list of tuple (color, min, max) the alpha componant is not considered

Paramètres

graduation (list) – list of tuple (color, min, max)

setLogScale(trueOrFalse=True)

Setter function to set linear/log scale

Paramètres

trueOrFalse (bool) – flag

setMaxValue(value)

Setter function to update max value legend

Paramètres

value (float) – max value

setMinValue(value)

Setter function to update min value legend

Paramètres

value (float) – min value

setNbClass(nbClass)

Setter for nbClass attribute. Nbclass is a int used for graduated symbology

Paramètres

nbClass (integer) – number of class requested for graduated scale

setTitle(text)

Setter function to set the legend title

Paramètres

text (string) – title to set

setTransparency(value)

Setter function to update transparency values

Paramètres

value (float) – transparency value

setTransparencyPercent(value)

Setter function to update transparency values, from percent to float value

Paramètres

value (integer) – transparency value

setUnits(text)

set the units to display in legend

Paramètres

text (string) – title to set

symbologyChanged
title()

Getter function to get the legend title

Renvoie

title

Type renvoyé

string

toggleGraduation(flag)

Activate or remove graduate symbology by sending pixelColor code.

Paramètres

flag (bool) – flag to get continuous/graduated color ramp

transparencyPercent()

Getter function for transparency value, from float value to percent

Renvoie

transparency value

Type renvoyé

integer

units()

Getter function to get the units

Renvoie

units

Type renvoyé

string

values(nbValues=7)

Return list of numerical values at “equal” or “logequal” intervals

Paramètres

nbValues (integer) – number of values requested for graduated scale

Renvoie

values needed to create intervals

Type renvoyé

list

writeXml(node, doc, rwcontext)

Function to save mesh legend information in project

Paramètres
  • node (QDomElement) – base element of the xml

  • doc (QDomDocument) – document

  • rwcontext (QgsReadWriteContext) – QgsReadWriteContext

class thyrsis.meshlayer.glmesh.GlMesh(vtx, idx, legend)

Bases : PyQt5.QtCore.QObject

This class provides basic function to render results on a 2D mesh. The class must be instanciated in the main thread, but the draw function can be called in another thread. This class encapsulates the transformation between an extend and an image size.

colorPerElement()

Return if the mesh is element based or node based

Renvoie

flag

Type renvoyé

bool

image(values, imageSize, center, mapUnitsPerPixel, rotation=0)

Return the rendered image of a given size for values defined at each vertex or at each element depending on setColorPerElement. Values are normalized using valueRange = (minValue, maxValue).

transparency is in the range [0,1]

Paramètres
  • values (dict) – vertex dictionnary

  • imageSize (QSize) – size of the output image

  • center (list) – center coordinates

  • mapUnitsPerPixel (float) – scale mapUnit/pixel

  • rotation (float) – rotation value

Renvoie

image

Type renvoyé

QImage

resetCoord(vtx)

Reset vertices

Paramètres

vtx (dict) – vertices dictionnary

setColorPerElement(flag)

Apply color per element, is the mesh is based on element

Paramètres
  • flag – flag for element base mesh

  • flag – bool

setLegend(legend)
thyrsis.meshlayer.glmesh.gray2qimage(gray)

Convert the 2D numpy array gray into a 8-bit QImage with a gray colormap. The first dimension represents the vertical image axis. ATTENTION: This QImage carries an attribute ndimage with a reference to the underlying numpy array that holds the data. On Windows, the conversion into a QPixmap does not copy the data, so that you have to take care that the QImage does not get garbage collected (otherwise PyQt will throw away the wrapper, effectively freeing the underlying memory - boom!). :param gray: numpy array :type gray: ndarray

Renvoie

image

Type renvoyé

QImage

thyrsis.meshlayer.glmesh.numpy2qimage(array)

Convert ndarray to image

Paramètres

array (ndarray) – numpy array

Renvoie

image

Type renvoyé

QImage

thyrsis.meshlayer.glmesh.qimage2numpy(qimage, dtype='array')

Convert QImage to numpy.ndarray. The dtype defaults to uint8 for QImage.Format_Indexed8 or bgra_dtype (i.e. a record array) for 32bit color images. You can pass a different dtype to use, or “array” to get a 3D uint8 array for color images.

Paramètres
  • qimage (QImage) – image

  • dtype (string) – dtype to use for numpy conversion

Renvoie

numpy array

Type renvoyé

ndarray

thyrsis.meshlayer.glmesh.rgb2qimage(rgb)

Convert the 3D numpy array rgb into a 32-bit QImage.`rgb` must have three dimensions with the vertical, horizontal and RGB image axes. ATTENTION: This QImage carries an attribute ndimage with a reference to the underlying numpy array that holds the data. On Windows, the conversion into a QPixmap does not copy the data, so that you have to take care that the QImage does not get garbage collected (otherwise PyQt will throw away the wrapper, effectively freeing the underlying memory - boom!).

Paramètres

rgb (ndarray) – numpy array

Renvoie

image

Type renvoyé

QImage

thyrsis.meshlayer.glmesh.roundUpSize(size)

Return size roudup to the nearest power of 2

Paramètres

size (QSize) – size