TransWikia.com

Layer styling - raster symbology

Geographic Information Systems Asked by Ivan Marjanović on February 3, 2021

I have two lists of raster (digital elevation model – DEM) layers by name. The first list of layers should be symbolized as follows:
symbology should be set to hillshade
layer rendering, blend mode should be set to soft light

enter image description here

and transparency, global opacity should be set to 30%

enter image description here

The second list of layers should be symbolized as follows:
symbology should be set to singleband pseudocolor
mode should be set to equal interval
and classes should be set to 5

enter image description here

Is there a way to apply all of these settings with PyQGIS code, since I need to set them manually every single time? I tried to do it myself but this task far surpasses my level of knowledge in PyQGIS.

One Answer

I have managed to partially solve the aforementioned set of problems. The code for the first list of rasters (sets all the parameters properly):

`for i in list_1 :
    layer_1 = QgsProject.instance().mapLayersByName(i)[0]
    r = QgsHillshadeRenderer(layer_1.dataProvider(), 1, 315, 45)
    layer_1.setRenderer(r)
    layer_1.setBlendMode(QPainter.CompositionMode_SoftLight)
    layer_1.renderer().setOpacity(0.3)`

The code for the second list of rasters (only part of the solution):

`for i in list_2 :
    layer_2 = QgsProject.instance().mapLayersByName(i)[0]
    sbps = QgsSingleBandPseudoColorRenderer(layer_2.dataProvider(),1,)
    layer_2.setRenderer(sbps)`

I just don't know how to set Mode to Equal Interval and Classes to 5. I would be extremely grateful if someone would offer a solution to this part of my problem.

Answered by Ivan Marjanović on February 3, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP