-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocessing-script.py
More file actions
97 lines (80 loc) · 3.27 KB
/
processing-script.py
File metadata and controls
97 lines (80 loc) · 3.27 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
"""
Model exported as python.
Name : secondattempt
Group :
With QGIS : 31607
"""
from qgis.core import QgsProcessing
from qgis.core import QgsProcessingAlgorithm
from qgis.core import QgsProcessingMultiStepFeedback
from qgis.core import QgsProcessingParameterRasterLayer
from qgis.core import QgsProcessingParameterVectorDestination
from qgis.core import QgsProcessingParameterRasterDestination
import processing
#Run after creating directories
class Secondattempt(QgsProcessingAlgorithm):
def initAlgorithm(self, config=None):
self.addParameter(QgsProcessingParameterRasterLayer('rasterinput', 'raster_input', defaultValue=None))
self.addParameter(QgsProcessingParameterVectorDestination('Contour', 'contour', type=QgsProcessing.TypeVectorLine, createByDefault=True, defaultValue=None))
self.addParameter(QgsProcessingParameterRasterDestination('Hill', 'hill', createByDefault=True, defaultValue=None))
def processAlgorithm(self, parameters, context, model_feedback):
# Use a multi-step feedback, so that individual child algorithm progress reports are adjusted for the
# overall progress through the model
feedback = QgsProcessingMultiStepFeedback(4, model_feedback)
results = {}
outputs = {}
# Create Hillshade directory
alg_params = {
'PATH': 'C:/Users/Dell/Desktop/Hillshade'
}
outputs['CreateHillshadeDirectory'] = processing.run('native:createdirectory', alg_params, context=context, feedback=feedback, is_child_algorithm=True)
feedback.setCurrentStep(1)
if feedback.isCanceled():
return {}
# Hillshade
alg_params = {
'AZIMUTH': 300,
'INPUT': parameters['rasterinput'],
'V_ANGLE': 40,
'Z_FACTOR': 1,
'OUTPUT': parameters['Hill']
}
outputs['Hillshade'] = processing.run('native:hillshade', alg_params, context=context, feedback=feedback, is_child_algorithm=True)
results['Hill'] = outputs['Hillshade']['OUTPUT']
feedback.setCurrentStep(2)
if feedback.isCanceled():
return {}
# Contour
alg_params = {
'PATH': 'C:/Users/Dell/Desktop/Contour'
}
outputs['Contour'] = processing.run('native:createdirectory', alg_params, context=context, feedback=feedback, is_child_algorithm=True)
feedback.setCurrentStep(3)
if feedback.isCanceled():
return {}
# Contour
alg_params = {
'BAND': 1,
'CREATE_3D': False,
'EXTRA': '',
'FIELD_NAME': 'ELEV',
'IGNORE_NODATA': False,
'INPUT': outputs['Hillshade']['OUTPUT'],
'INTERVAL': 10,
'NODATA': None,
'OFFSET': 0,
'OUTPUT': parameters['Contour']
}
outputs['Contour'] = processing.run('gdal:contour', alg_params, context=context, feedback=feedback, is_child_algorithm=True)
results['Contour'] = outputs['Contour']['OUTPUT']
return results
def name(self):
return 'secondattempt'
def displayName(self):
return 'secondattempt'
def group(self):
return ''
def groupId(self):
return ''
def createInstance(self):
return Secondattempt()