30
30
from qgis .PyQt .QtGui import QIcon
31
31
32
32
from qgis .analysis import QgsAspectFilter
33
-
34
- from processing .algs .qgis import QgisAlgorithm
33
+ from qgis .core import (QgsProcessingParameterRasterLayer ,
34
+ QgsProcessingParameterNumber ,
35
+ QgsProcessingParameterRasterOutput ,
36
+ QgsProcessingOutputRasterLayer )
37
+ from processing .algs .qgis .QgisAlgorithm import QgisAlgorithm
35
38
from processing .core .parameters import ParameterRaster
36
39
from processing .core .parameters import ParameterNumber
37
40
from processing .core .outputs import OutputRaster
38
41
from processing .tools import raster
42
+ from processing .tools .dataobjects import exportRasterLayer
39
43
40
44
pluginPath = os .path .split (os .path .split (os .path .dirname (__file__ ))[0 ])[0 ]
41
45
@@ -54,12 +58,14 @@ def group(self):
54
58
55
59
def __init__ (self ):
56
60
super ().__init__ ()
57
- self .addParameter (ParameterRaster (self .INPUT_LAYER ,
58
- self .tr ('Elevation layer' )))
59
- self .addParameter (ParameterNumber (self .Z_FACTOR ,
60
- self .tr ('Z factor' ), 1.0 , 999999.99 , 1.0 ))
61
- self .addOutput (OutputRaster (self .OUTPUT_LAYER ,
62
- self .tr ('Aspect' )))
61
+
62
+ self .addParameter (QgsProcessingParameterRasterLayer (self .INPUT_LAYER ,
63
+ self .tr ('Elevation layer' )))
64
+ self .addParameter (QgsProcessingParameterNumber (self .Z_FACTOR ,
65
+ self .tr ('Z factor' ), QgsProcessingParameterNumber .Double ,
66
+ 1 , False , 1 , 999999.99 ))
67
+ self .addParameter (QgsProcessingParameterRasterOutput (self .OUTPUT_LAYER , self .tr ('Aspect' )))
68
+ self .addOutput (QgsProcessingOutputRasterLayer (self .OUTPUT_LAYER , self .tr ('Aspect' )))
63
69
64
70
def name (self ):
65
71
return 'aspect'
@@ -68,12 +74,15 @@ def displayName(self):
68
74
return self .tr ('Aspect' )
69
75
70
76
def processAlgorithm (self , parameters , context , feedback ):
71
- inputFile = self .getParameterValue (self .INPUT_LAYER )
72
- zFactor = self .getParameterValue (self .Z_FACTOR )
73
- outputFile = self .getOutputValue (self .OUTPUT_LAYER )
77
+ inputFile = exportRasterLayer (self .parameterAsRasterLayer (parameters , self .INPUT_LAYER , context ))
78
+ zFactor = self .parameterAsDouble (parameters , self .Z_FACTOR , context )
79
+
80
+ outputFile = self .parameterAsRasterOutputLayer (parameters , self .OUTPUT_LAYER , context )
74
81
75
82
outputFormat = raster .formatShortNameFromFileName (outputFile )
76
83
77
84
aspect = QgsAspectFilter (inputFile , outputFile , outputFormat )
78
85
aspect .setZFactor (zFactor )
79
86
aspect .processRaster (None )
87
+
88
+ return {self .OUTPUT_LAYER : outputFile }
0 commit comments