-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathModeloAPP.py
115 lines (96 loc) · 4.26 KB
/
ModeloAPP.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
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
"""
Model exported as python.
Name : APP
Group :
With QGIS : 32209
"""
from qgis.core import QgsProcessing
from qgis.core import QgsProcessingAlgorithm
from qgis.core import QgsProcessingMultiStepFeedback
from qgis.core import QgsProcessingParameterVectorLayer
from qgis.core import QgsProcessingParameterDistance
from qgis.core import QgsProcessingParameterFeatureSink
from qgis.core import QgsCoordinateReferenceSystem
import processing
class App(QgsProcessingAlgorithm):
def initAlgorithm(self, config=None):
self.addParameter(QgsProcessingParameterVectorLayer('area', 'Area', types=[QgsProcessing.TypeVectorPolygon], defaultValue=None))
self.addParameter(QgsProcessingParameterVectorLayer('hidrografia', 'Hidrografia', types=[QgsProcessing.TypeVectorLine], defaultValue=None))
self.addParameter(QgsProcessingParameterDistance('margem', 'Margem', parentParameterName='hidrografia', minValue=0, maxValue=600, defaultValue=30))
self.addParameter(QgsProcessingParameterVectorLayer('nascente', 'Nascente', types=[QgsProcessing.TypeVectorPoint], defaultValue=None))
self.addParameter(QgsProcessingParameterFeatureSink('App', 'APP', type=QgsProcessing.TypeVectorAnyGeometry, 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(5, model_feedback)
results = {}
outputs = {}
# Buffer
alg_params = {
'DISSOLVE': False,
'DISTANCE': 50,
'END_CAP_STYLE': 0, # Arredondado
'INPUT': parameters['nascente'],
'JOIN_STYLE': 0, # Arredondado
'MITER_LIMIT': 2,
'SEGMENTS': 5,
'OUTPUT': QgsProcessing.TEMPORARY_OUTPUT
}
outputs['Buffer'] = processing.run('native:buffer', alg_params, context=context, feedback=feedback, is_child_algorithm=True)
feedback.setCurrentStep(1)
if feedback.isCanceled():
return {}
# Buffer
alg_params = {
'DISSOLVE': False,
'DISTANCE': parameters['margem'],
'END_CAP_STYLE': 0, # Arredondado
'INPUT': parameters['hidrografia'],
'JOIN_STYLE': 0, # Arredondado
'MITER_LIMIT': 2,
'SEGMENTS': 5,
'OUTPUT': QgsProcessing.TEMPORARY_OUTPUT
}
outputs['Buffer'] = processing.run('native:buffer', alg_params, context=context, feedback=feedback, is_child_algorithm=True)
feedback.setCurrentStep(2)
if feedback.isCanceled():
return {}
# Mesclar camadas vetoriais
alg_params = {
'CRS': QgsCoordinateReferenceSystem('EPSG:31982'),
'LAYERS': [outputs['Buffer']['OUTPUT'],outputs['Buffer']['OUTPUT']],
'OUTPUT': QgsProcessing.TEMPORARY_OUTPUT
}
outputs['MesclarCamadasVetoriais'] = processing.run('native:mergevectorlayers', alg_params, context=context, feedback=feedback, is_child_algorithm=True)
feedback.setCurrentStep(3)
if feedback.isCanceled():
return {}
# Dissolver
alg_params = {
'FIELD': [''],
'INPUT': outputs['MesclarCamadasVetoriais']['OUTPUT'],
'OUTPUT': QgsProcessing.TEMPORARY_OUTPUT
}
outputs['Dissolver'] = processing.run('native:dissolve', alg_params, context=context, feedback=feedback, is_child_algorithm=True)
feedback.setCurrentStep(4)
if feedback.isCanceled():
return {}
# Recortar
alg_params = {
'INPUT': outputs['Dissolver']['OUTPUT'],
'OVERLAY': parameters['area'],
'OUTPUT': parameters['App']
}
outputs['Recortar'] = processing.run('native:clip', alg_params, context=context, feedback=feedback, is_child_algorithm=True)
results['App'] = outputs['Recortar']['OUTPUT']
return results
def name(self):
return 'APP'
def displayName(self):
return 'APP'
def group(self):
return ''
def groupId(self):
return ''
def createInstance(self):
return App()