forked from 3liz/QgisProcessingScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Set_multiple_raster_layers_properties.py
45 lines (36 loc) · 1.16 KB
/
Set_multiple_raster_layers_properties.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
##[3liz - Raster]=group
##Set multiple raster layers properties=name
##Raster_layers=multiple raster
##QML_file=file
##Coordinate_Reference_System=crs None
##Refresh_contrast_enhancement=boolean True
##Save_layer_style_as_default=boolean False
from qgis.core import *
from qgis.utils import iface
import os
# rename inputs
crs = Coordinate_Reference_System
qml = QML_file
rce = Refresh_contrast_enhancement
ss = Save_layer_style_as_default
# Iterate over the chosen layers
layersUri = Raster_layers.split(';')
for i, uri in enumerate(layersUri):
progress.setPercentage(int(100 * i / len(layersUri)))
# Get layer from passed uri
layer = processing.getObjectFromUri(uri)
# Set style from QML
if os.path.exists(qml):
layer.loadNamedStyle(qml)
iface.legendInterface().refreshLayerSymbology(layer)
# Set CRS
if crs:
qcrs = QgsCoordinateReferenceSystem()
qcrs.createFromOgcWmsCrs(crs)
layer.setCrs(qcrs)
# Refresh default contrast enhancement
if rce:
layer.setDefaultContrastEnhancement()
# Save style as default
if ss:
layer.saveDefaultStyle()