Skip to content

Commit e86ca50

Browse files
committedDec 30, 2018
restore columns and rows parameters for the extremely rare case if
someone have used native interpolation algs in scripts/models
1 parent 09dbb89 commit e86ca50

File tree

2 files changed

+48
-6
lines changed

2 files changed

+48
-6
lines changed
 

‎python/plugins/processing/algs/qgis/IdwInterpolation.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
QgsProcessingUtils,
3434
QgsProcessingParameterNumber,
3535
QgsProcessingParameterExtent,
36+
QgsProcessingParameterDefinition,
3637
QgsProcessingParameterRasterDestination,
3738
QgsProcessingException)
3839
from qgis.analysis import (QgsInterpolator,
@@ -50,6 +51,8 @@ class IdwInterpolation(QgisAlgorithm):
5051
INTERPOLATION_DATA = 'INTERPOLATION_DATA'
5152
DISTANCE_COEFFICIENT = 'DISTANCE_COEFFICIENT'
5253
PIXEL_SIZE = 'PIXEL_SIZE'
54+
COLUMNS = 'COLUMNS'
55+
ROWS = 'ROWS'
5356
EXTENT = 'EXTENT'
5457
OUTPUT = 'OUTPUT'
5558

@@ -83,6 +86,20 @@ def initAlgorithm(self, config=None):
8386
default=0.1)
8487
self.addParameter(pixel_size_param)
8588

89+
cols_param = QgsProcessingParameterNumber(self.COLUMNS,
90+
self.tr('Number of columns'),
91+
optional=True,
92+
minValue=0, maxValue=10000000)
93+
cols_param.setFlags(cols_param.flags() | QgsProcessingParameterDefinition.FlagHidden)
94+
self.addParameter(cols_param)
95+
96+
rows_param = QgsProcessingParameterNumber(self.ROWS,
97+
self.tr('Number of rows'),
98+
optional=True,
99+
minValue=0, maxValue=10000000)
100+
rows_param.setFlags(rows_param.flags() | QgsProcessingParameterDefinition.FlagHidden)
101+
self.addParameter(rows_param)
102+
86103
self.addParameter(QgsProcessingParameterRasterDestination(self.OUTPUT,
87104
self.tr('Interpolated')))
88105

@@ -99,6 +116,13 @@ def processAlgorithm(self, parameters, context, feedback):
99116
pixel_size = self.parameterAsDouble(parameters, self.PIXEL_SIZE, context)
100117
output = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
101118

119+
columns = self.parameterAsInt(parameters, self.COLUMNS, context)
120+
rows = self.parameterAsInt(parameters, self.ROWS, context)
121+
if columns == 0:
122+
columns = max(round(bbox.width() / pixel_size) + 1, 1)
123+
if rows == 0:
124+
rows = max(round(bbox.height() / pixel_size) + 1, 1)
125+
102126
if interpolationData is None:
103127
raise QgsProcessingException(
104128
self.tr('You need to specify at least one input layer.'))
@@ -127,9 +151,6 @@ def processAlgorithm(self, parameters, context, feedback):
127151
interpolator = QgsIDWInterpolator(layerData)
128152
interpolator.setDistanceCoefficient(coefficient)
129153

130-
rows = max(round(bbox.height() / pixel_size) + 1, 1)
131-
columns = max(round(bbox.width() / pixel_size) + 1, 1)
132-
133154
writer = QgsGridFileWriter(interpolator,
134155
output,
135156
bbox,

‎python/plugins/processing/algs/qgis/TinInterpolation.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
QgsProcessingParameterEnum,
3535
QgsProcessingParameterNumber,
3636
QgsProcessingParameterExtent,
37+
QgsProcessingParameterDefinition,
3738
QgsProcessingParameterRasterDestination,
3839
QgsWkbTypes,
3940
QgsProcessingParameterFeatureSink,
@@ -53,6 +54,8 @@ class TinInterpolation(QgisAlgorithm):
5354
INTERPOLATION_DATA = 'INTERPOLATION_DATA'
5455
METHOD = 'METHOD'
5556
PIXEL_SIZE = 'PIXEL_SIZE'
57+
COLUMNS = 'COLUMNS'
58+
ROWS = 'ROWS'
5659
EXTENT = 'EXTENT'
5760
OUTPUT = 'OUTPUT'
5861
TRIANGULATION = 'TRIANGULATION'
@@ -91,6 +94,20 @@ def initAlgorithm(self, config=None):
9194
default=0.1)
9295
self.addParameter(pixel_size_param)
9396

97+
cols_param = QgsProcessingParameterNumber(self.COLUMNS,
98+
self.tr('Number of columns'),
99+
optional=True,
100+
minValue=0, maxValue=10000000)
101+
cols_param.setFlags(cols_param.flags() | QgsProcessingParameterDefinition.FlagHidden)
102+
self.addParameter(cols_param)
103+
104+
rows_param = QgsProcessingParameterNumber(self.ROWS,
105+
self.tr('Number of rows'),
106+
optional=True,
107+
minValue=0, maxValue=10000000)
108+
rows_param.setFlags(rows_param.flags() | QgsProcessingParameterDefinition.FlagHidden)
109+
self.addParameter(rows_param)
110+
94111
self.addParameter(QgsProcessingParameterRasterDestination(self.OUTPUT,
95112
self.tr('Interpolated')))
96113

@@ -114,6 +131,13 @@ def processAlgorithm(self, parameters, context, feedback):
114131
pixel_size = self.parameterAsDouble(parameters, self.PIXEL_SIZE, context)
115132
output = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
116133

134+
columns = self.parameterAsInt(parameters, self.COLUMNS, context)
135+
rows = self.parameterAsInt(parameters, self.ROWS, context)
136+
if columns == 0:
137+
columns = max(round(bbox.width() / pixel_size) + 1, 1)
138+
if rows == 0:
139+
rows = max(round(bbox.height() / pixel_size) + 1, 1)
140+
117141
if interpolationData is None:
118142
raise QgsProcessingException(
119143
self.tr('You need to specify at least one input layer.'))
@@ -154,9 +178,6 @@ def processAlgorithm(self, parameters, context, feedback):
154178
if triangulation_sink is not None:
155179
interpolator.setTriangulationSink(triangulation_sink)
156180

157-
rows = max(round(bbox.height() / pixel_size) + 1, 1)
158-
columns = max(round(bbox.width() / pixel_size) + 1, 1)
159-
160181
writer = QgsGridFileWriter(interpolator,
161182
output,
162183
bbox,

0 commit comments

Comments
 (0)
Please sign in to comment.