6.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
- Returns
dictionnary of color ramps
- Return type
dict
- colorRamp()¶
Getter function for colorRampFile value
- Returns
color ramp file name
- Return type
string
- colorRampImg()¶
Getter function for colorRamp image value
- Returns
color ramp
- Return type
QImage
- createItems()¶
Returns a QGraphicsItemGroup that contains legend items
- Returns
legend items
- Return type
QGraphicsItemGroup
- graduated()¶
Getter for graduated attribute. Graduated is boolean
- Returns
continuous/graduated flag
- Return type
bool
- graduation()¶
Getter for graduation attribute. Graduation is a list of tuple (Qcolor, min, max)
- Returns
graduation attributes that is a list of tuple (color, min, max)
- Return type
list
- hasLogScale()¶
Getter function to set linear/log scale
- Returns
bool to evaluate if it uses log scale
- Return type
bool
- image()¶
Return an image representing the legend
- Returns
image of the legend
- Return type
QImage
- maskUnits(flag)¶
Function to mask unit in the legend, used for probability map
- maxValue()¶
Getter function for max value
- Returns
max value
- Return type
float
- minValue()¶
Getter function for min value
- Returns
min value
- Return type
float
- nbClass()¶
Getter for nbClass attribute. Nbclass is a int used for graduated symbology
- Returns
nbClass attribute
- Return type
integer
- readXml(node, rwcontext)¶
Function to read mesh legend information from project
- Parameters
node (QDomElement) – base element of the xml
rwcontext (QgsReadWriteContext) – QgsReadWriteContext
- setColorRamp(rampImageFile)¶
Setter function to change the color ramp with a file path
- Parameters
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
- Parameters
graduation (list) – list of tuple (color, min, max)
- setLogScale(trueOrFalse=True)¶
Setter function to set linear/log scale
- Parameters
trueOrFalse (bool) – flag
- setMaxValue(value)¶
Setter function to update max value legend
- Parameters
value (float) – max value
- setMinValue(value)¶
Setter function to update min value legend
- Parameters
value (float) – min value
- setNbClass(nbClass)¶
Setter for nbClass attribute. Nbclass is a int used for graduated symbology
- Parameters
nbClass (integer) – number of class requested for graduated scale
- setTitle(text)¶
Setter function to set the legend title
- Parameters
text (string) – title to set
- setTransparency(value)¶
Setter function to update transparency values
- Parameters
value (float) – transparency value
- setTransparencyPercent(value)¶
Setter function to update transparency values, from percent to float value
- Parameters
value (integer) – transparency value
- setUnits(text)¶
set the units to display in legend
- Parameters
text (string) – title to set
- symbologyChanged¶
- title()¶
Getter function to get the legend title
- Returns
title
- Return type
string
- toggleGraduation(flag)¶
Activate or remove graduate symbology by sending pixelColor code.
- Parameters
flag (bool) – flag to get continuous/graduated color ramp
- transparencyPercent()¶
Getter function for transparency value, from float value to percent
- Returns
transparency value
- Return type
integer
- units()¶
Getter function to get the units
- Returns
units
- Return type
string
- values(nbValues=7)¶
Return list of numerical values at ‘equal’ or ‘logequal’ intervals
- Parameters
nbValues (integer) – number of values requested for graduated scale
- Returns
values needed to create intervals
- Return type
list
- writeXml(node, doc, rwcontext)¶
Function to save mesh legend information in project
- Parameters
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
- Returns
flag
- Return type
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]
- Parameters
values (dict) – vertex dictionnary
imageSize (QSize) – size of the output image
center (list) – center coordinates
mapUnitsPerPixel (float) – scale mapUnit/pixel
rotation (float) – rotation value
- Returns
image
- Return type
QImage
- resetCoord(vtx)¶
Reset vertices
- Parameters
vtx (dict) – vertices dictionnary
- setColorPerElement(flag)¶
Apply color per element, is the mesh is based on element
- Parameters
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
- Returns
image
- Return type
QImage
- thyrsis.meshlayer.glmesh.numpy2qimage(array)¶
Convert ndarray to image
- Parameters
array (ndarray) – numpy array
- Returns
image
- Return type
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.
- Parameters
qimage (QImage) – image
dtype (string) – dtype to use for numpy conversion
- Returns
numpy array
- Return type
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!).
- Parameters
rgb (ndarray) – numpy array
- Returns
image
- Return type
QImage
- thyrsis.meshlayer.glmesh.roundUpSize(size)¶
Return size roudup to the nearest power of 2
- Parameters
size (QSize) – size