3030from qgis .PyQt .QtGui import QIcon
3131
3232from qgis .analysis import QgsSlopeFilter
33-
33+ from qgis .core import (QgsProcessingParameterRasterLayer ,
34+ QgsProcessingParameterNumber ,
35+ QgsProcessingParameterRasterDestination )
3436from processing .algs .qgis .QgisAlgorithm import QgisAlgorithm
35- from processing .core .parameters import ParameterRaster
36- from processing .core .parameters import ParameterNumber
37- from processing .core .outputs import OutputRaster
3837from processing .tools import raster
38+ from processing .tools .dataobjects import exportRasterLayer
39+
3940
4041pluginPath = os .path .split (os .path .split (os .path .dirname (__file__ ))[0 ])[0 ]
4142
4243
4344class Slope (QgisAlgorithm ):
4445
45- INPUT_LAYER = 'INPUT_LAYER '
46+ INPUT = 'INPUT '
4647 Z_FACTOR = 'Z_FACTOR'
47- OUTPUT_LAYER = 'OUTPUT_LAYER '
48+ OUTPUT = 'OUTPUT '
4849
4950 def icon (self ):
5051 return QIcon (os .path .join (pluginPath , 'images' , 'dem.png' ))
@@ -56,12 +57,12 @@ def __init__(self):
5657 super ().__init__ ()
5758
5859 def initAlgorithm (self , config = None ):
59- self .addParameter (ParameterRaster (self .INPUT_LAYER ,
60- self .tr ('Elevation layer' )))
61- self .addParameter (ParameterNumber (self .Z_FACTOR ,
62- self .tr ('Z factor' ), 1.0 , 999999.99 , 1.0 ))
63- self . addOutput ( OutputRaster ( self . OUTPUT_LAYER ,
64- self .tr ('Slope' )))
60+ self .addParameter (QgsProcessingParameterRasterLayer (self .INPUT ,
61+ self .tr ('Elevation layer' )))
62+ self .addParameter (QgsProcessingParameterNumber (self .Z_FACTOR ,
63+ self .tr ('Z factor' ), QgsProcessingParameterNumber . Double ,
64+ 1 , False , 1 , 999999.99 ))
65+ self . addParameter ( QgsProcessingParameterRasterDestination ( self . OUTPUT , self .tr ('Slope' )))
6566
6667 def name (self ):
6768 return 'slope'
@@ -70,12 +71,15 @@ def displayName(self):
7071 return self .tr ('Slope' )
7172
7273 def processAlgorithm (self , parameters , context , feedback ):
73- inputFile = self .getParameterValue (self .INPUT_LAYER )
74- zFactor = self .getParameterValue (self .Z_FACTOR )
75- outputFile = self .getOutputValue (self .OUTPUT_LAYER )
74+ inputFile = exportRasterLayer (self .parameterAsRasterLayer (parameters , self .INPUT , context ))
75+ zFactor = self .parameterAsDouble (parameters , self .Z_FACTOR , context )
76+
77+ outputFile = self .parameterAsOutputLayer (parameters , self .OUTPUT , context )
7678
7779 outputFormat = raster .formatShortNameFromFileName (outputFile )
7880
7981 slope = QgsSlopeFilter (inputFile , outputFile , outputFormat )
8082 slope .setZFactor (zFactor )
81- slope .processRaster (None )
83+ slope .processRaster (feedback )
84+
85+ return {self .OUTPUT : outputFile }
0 commit comments