[Qgis-user] [pyQGIS] legend of QgsSingleBandPseudoColorRenderer

andrea antonello andrea.antonello at gmail.com
Wed May 17 01:58:17 PDT 2023


Thanks to the help in an issue I opened, the legend part has been sorted
out.

Turns out that setting min and mx in the ram shader fixes legend:

crsh = QgsColorRampShader(minimumValue=minV, maximumValue=maxV)

There is still an issue with the layer properties not properly set (the
style panel does not show the right colortable).

Cheers,
Andrea



On Tue, May 9, 2023 at 8:54 AM andrea antonello <andrea.antonello at gmail.com>
wrote:

> Hello again,
> I styled a raster using a colorramp like:
>
> crsh = QgsColorRampShader()
> crsh.setColorRampType(QgsColorRampShader.Interpolated)
> lst = [
> QgsColorRampShader.ColorRampItem(minV, QColor(255,0,0)),
> QgsColorRampShader.ColorRampItem(minV + (maxV-minV)/2, QColor(0,255,0)),
> QgsColorRampShader.ColorRampItem(maxV, QColor(0,0,255))
> ]
> crsh.setColorRampItemList(lst)
> shader = QgsRasterShader()
> shader.setRasterShaderFunction(crsh)
>
> renderer = QgsSingleBandPseudoColorRenderer(dtmLayer.dataProvider(), 1,
> shader)
> dtmLayer.setRenderer(renderer)
>
>
> The raster shows up properly styled, but the legend is not handled
> properly. Even if the minV and maxV are values between 800 and 2200, the
> resulting legend is flat read and between 0 and 255:
>
> [image: image.png]
>
> Is there something I am doing wrong here?
> Thanks,
> Andrea
>
>
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20230517/a4b39d18/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image.png
Type: image/png
Size: 145935 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20230517/a4b39d18/attachment-0001.png>


More information about the QGIS-User mailing list