-
Notifications
You must be signed in to change notification settings - Fork 1
/
fill_dem.py
80 lines (65 loc) · 2.45 KB
/
fill_dem.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
from qgis.PyQt.QtCore import QCoreApplication
from qgis.core import (QgsProcessing,
QgsProcessingAlgorithm,
QgsProcessingParameterFeatureSource,
QgsProcessingParameterRasterLayer,
QgsProcessingParameterRasterDestination,
QgsProcessingParameterVectorLayer,
QgsProcessingParameterVectorDestination,
QgsCoordinateReferenceSystem)
from qgis import processing
class FillDemProcessingAlgorithm(QgsProcessingAlgorithm):
# Constants used to refer to parameters and outputs. They will be
# used when calling the algorithm from another algorithm, or when
# calling from the QGIS console.
FILL_DEM = 'filled_dem'
CLIP_DEM = 'clipped_dem'
def tr(self, string):
return QCoreApplication.translate('Processing', string)
def createInstance(self):
return FillDemProcessingAlgorithm()
def name(self):
return 'fill_dem'
def displayName(self):
return self.tr('Fill Dem')
def shortHelpString(self):
return self.tr("Fill missing data cells using interpolation")
def initAlgorithm(self, config=None):
self.addParameter(
QgsProcessingParameterFeatureSource(
self.CLIP_DEM,
self.tr('Input DEM'),
[QgsProcessing.TypeVectorAnyGeometry]
)
)
self.addParameter(
QgsProcessingParameterRasterLayer(
self.FILL_DEM,
self.tr('Output Filled DEM')
[QgsProcessing.TypeRaster]
)
)
def processAlgorithm(self, parameters, context, feedback):
farm_shape= self.parameterAsRasterLayer(
parameters,
self.CLIP_DEM,
context
)
# Send some information to the user
feedback.pushInfo('Starting filling')
filledgaps = processing.run(
'gdal:fillnodata',
{
'INPUT':parameters['clipped_dem'],
'BAND':1,
'DISTANCE':10,
'ITERATIONS':0,
'NO_MASK':False,
'MASK_LAYER':None,
'OPTIONS':'',
'EXTRA':'',
'OUTPUT':parameters['filled_dem']
}
)
feedback.pushInfo('DEM filled correctly')
return {'filled_dem': filledgaps['OUTPUT']}