Geographic Information Systems Asked on July 20, 2021
I have a repetitive process where I duplicate a raster layer twice so I have 3 instances and I can display hillshade, elevation, and contour styles – I’m trying to create a model to run this process for me, but can’t seem to find a duplicate raster algorithm.
Am I missing something or is this not possible with model designer?
You can use pyqgis:
baselayer = QgsProject.instance().mapLayersByName('DEM')[0] #Change DEM to the name of your layer
for name, rend in [['hillshade', QgsHillshadeRenderer(baselayer.dataProvider(), 1, 315, 45)],
['contour', QgsRasterContourRenderer(baselayer.dataProvider())]]:
newlyr = QgsRasterLayer(baselayer.source(), baselayer.name()+'_'+name)
newlyr.setRenderer(rend)
if 'setContourInterval' in dir(rend): #If it has this method it's the contours
rend.setContourInterval(50)
rend.setContourSymbol(QgsLineSymbol.createSimple({'line_style': 'solid', 'color': 'white'}))
else: #if no it's the hillshade
rend.setZFactor(3)
rend.setOpacity(0.5)
QgsProject.instance().addMapLayer(newlyr)
Correct answer by BERA on July 20, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP