Skip to content

Commit 33d422b

Browse files
authoredNov 3, 2017
Merge pull request #5518 from nyalldawson/interp
Start on unit tests for interpolation classes
2 parents fb7f8f1 + 61fa8da commit 33d422b

17 files changed

+569
-343
lines changed
 

‎python/analysis/interpolation/qgsgridfilewriter.sip

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,23 @@ class QgsGridFileWriter
1717
#include "qgsgridfilewriter.h"
1818
%End
1919
public:
20-
QgsGridFileWriter( QgsInterpolator *i, const QString &outputPath, const QgsRectangle &extent, int nCols, int nRows, double cellSizeX, double cellSizeY );
2120

21+
QgsGridFileWriter( QgsInterpolator *interpolator, const QString &outputPath, const QgsRectangle &extent, int nCols, int nRows );
22+
%Docstring
23+
Constructor for QgsGridFileWriter, for the specified ``interpolator``.
24+
25+
The ``outputPath`` argument is used to set the output file path.
26+
27+
The ``extent`` and ``nCols``, ``nRows`` arguments dictate the extent and size of the output raster.
28+
%End
2229

2330
int writeFile( QgsFeedback *feedback = 0 );
2431
%Docstring
2532
Writes the grid file.
26-
\param feedback optional feedback object for progress reports and cancelation support
27-
:return: 0 in case of success*
33+
34+
An optional ``feedback`` object can be set for progress reports and cancelation support
35+
36+
:return: 0 in case of success
2837
:rtype: int
2938
%End
3039

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

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,6 @@ class IdwInterpolation(QgisAlgorithm):
8989
DISTANCE_COEFFICIENT = 'DISTANCE_COEFFICIENT'
9090
COLUMNS = 'COLUMNS'
9191
ROWS = 'ROWS'
92-
CELLSIZE_X = 'CELLSIZE_X'
93-
CELLSIZE_Y = 'CELLSIZE_Y'
9492
EXTENT = 'EXTENT'
9593
OUTPUT = 'OUTPUT'
9694

@@ -116,12 +114,6 @@ def initAlgorithm(self, config=None):
116114
self.addParameter(QgsProcessingParameterNumber(self.ROWS,
117115
self.tr('Number of rows'),
118116
minValue=0, maxValue=10000000, defaultValue=300))
119-
self.addParameter(QgsProcessingParameterNumber(self.CELLSIZE_X,
120-
self.tr('Cell Size X'), type=QgsProcessingParameterNumber.Double,
121-
minValue=0.0, maxValue=999999.000000, defaultValue=0.0))
122-
self.addParameter(QgsProcessingParameterNumber(self.CELLSIZE_Y,
123-
self.tr('Cell Size Y'), type=QgsProcessingParameterNumber.Double,
124-
minValue=0.0, maxValue=999999.000000, defaultValue=0.0))
125117
self.addParameter(QgsProcessingParameterExtent(self.EXTENT,
126118
self.tr('Extent'),
127119
optional=False))
@@ -139,8 +131,6 @@ def processAlgorithm(self, parameters, context, feedback):
139131
coefficient = self.parameterAsDouble(parameters, self.DISTANCE_COEFFICIENT, context)
140132
columns = self.parameterAsInt(parameters, self.COLUMNS, context)
141133
rows = self.parameterAsInt(parameters, self.ROWS, context)
142-
cellsizeX = self.parameterAsDouble(parameters, self.CELLSIZE_X, context)
143-
cellsizeY = self.parameterAsDouble(parameters, self.CELLSIZE_Y, context)
144134
bbox = self.parameterAsExtent(parameters, self.EXTENT, context)
145135
output = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
146136

@@ -176,9 +166,7 @@ def processAlgorithm(self, parameters, context, feedback):
176166
output,
177167
bbox,
178168
columns,
179-
rows,
180-
cellsizeX,
181-
cellsizeY)
169+
rows)
182170

183171
writer.writeFile(feedback)
184172
return {self.OUTPUT: output}

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

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,6 @@ class TinInterpolation(QgisAlgorithm):
9292
METHOD = 'METHOD'
9393
COLUMNS = 'COLUMNS'
9494
ROWS = 'ROWS'
95-
CELLSIZE_X = 'CELLSIZE_X'
96-
CELLSIZE_Y = 'CELLSIZE_Y'
9795
EXTENT = 'EXTENT'
9896
OUTPUT = 'OUTPUT'
9997
TRIANGULATION = 'TRIANGULATION'
@@ -124,12 +122,6 @@ def initAlgorithm(self, config=None):
124122
self.addParameter(QgsProcessingParameterNumber(self.ROWS,
125123
self.tr('Number of rows'),
126124
minValue=0, maxValue=10000000, defaultValue=300))
127-
self.addParameter(QgsProcessingParameterNumber(self.CELLSIZE_X,
128-
self.tr('Cell size X'), type=QgsProcessingParameterNumber.Double,
129-
minValue=0.0, maxValue=999999.000000, defaultValue=0.0))
130-
self.addParameter(QgsProcessingParameterNumber(self.CELLSIZE_Y,
131-
self.tr('Cell size Y'), type=QgsProcessingParameterNumber.Double,
132-
minValue=0.0, maxValue=999999.000000, defaultValue=0.0))
133125
self.addParameter(QgsProcessingParameterExtent(self.EXTENT,
134126
self.tr('Extent'),
135127
optional=False))
@@ -154,19 +146,13 @@ def processAlgorithm(self, parameters, context, feedback):
154146
method = self.parameterAsEnum(parameters, self.METHOD, context)
155147
columns = self.parameterAsInt(parameters, self.COLUMNS, context)
156148
rows = self.parameterAsInt(parameters, self.ROWS, context)
157-
cellsizeX = self.parameterAsDouble(parameters, self.CELLSIZE_X, context)
158-
cellsizeY = self.parameterAsDouble(parameters, self.CELLSIZE_Y, context)
159149
bbox = self.parameterAsExtent(parameters, self.EXTENT, context)
160150
output = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
161151

162152
if interpolationData is None:
163153
raise QgsProcessingException(
164154
self.tr('You need to specify at least one input layer.'))
165155

166-
if cellsizeX == 0.0 or cellsizeY == 0.0:
167-
raise QgsProcessingException(
168-
self.tr('Cellsize should be greater than 0.'))
169-
170156
layerData = []
171157
layers = []
172158
crs = QgsCoordinateReferenceSystem()
@@ -207,9 +193,7 @@ def processAlgorithm(self, parameters, context, feedback):
207193
output,
208194
bbox,
209195
columns,
210-
rows,
211-
cellsizeX,
212-
cellsizeY)
196+
rows)
213197

214198
writer.writeFile(feedback)
215199
return {self.OUTPUT: output, self.TRIANGULATION: triangulation_dest_id}

‎python/plugins/processing/tests/testdata/qgis_algorithm_tests.yaml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1497,8 +1497,6 @@ tests:
14971497
- algorithm: qgis:idwinterpolation
14981498
name: IDW interpolation using attribute
14991499
params:
1500-
CELLSIZE_X: 0.02667
1501-
CELLSIZE_Y: 0.02667
15021500
COLUMNS: 300
15031501
DISTANCE_COEFFICIENT: 2.0
15041502
EXTENT: 0, 8, -5, 3
@@ -1508,14 +1506,14 @@ tests:
15081506
ROWS: 300
15091507
results:
15101508
OUTPUT:
1511-
hash: 56d2671d50444f8571affba3f9e585830b82af5e380394178f521065
1509+
hash:
1510+
- 56d2671d50444f8571affba3f9e585830b82af5e380394178f521065
1511+
- 2ae62aca803e6864ac75e47b4357292b0637d811cb510ed19471f422
15121512
type: rasterhash
15131513

15141514
- algorithm: qgis:idwinterpolation
15151515
name: IDW interpolation using Z value
15161516
params:
1517-
CELLSIZE_X: 0.02667
1518-
CELLSIZE_Y: 0.02667
15191517
COLUMNS: 300
15201518
DISTANCE_COEFFICIENT: 2.0
15211519
EXTENT: 0, 8, -5, 3
@@ -1525,14 +1523,14 @@ tests:
15251523
ROWS: 300
15261524
results:
15271525
OUTPUT:
1528-
hash: 56d2671d50444f8571affba3f9e585830b82af5e380394178f521065
1526+
hash:
1527+
- 56d2671d50444f8571affba3f9e585830b82af5e380394178f521065
1528+
- 2ae62aca803e6864ac75e47b4357292b0637d811cb510ed19471f422
15291529
type: rasterhash
15301530

15311531
- algorithm: qgis:tininterpolation
15321532
name: TIN interpolation using attribute
15331533
params:
1534-
CELLSIZE_X: 0.02667
1535-
CELLSIZE_Y: 0.02667
15361534
COLUMNS: 300
15371535
EXTENT: 0, 8, -5, 3
15381536
INTERPOLATION_DATA:
@@ -1542,7 +1540,9 @@ tests:
15421540
ROWS: 300
15431541
results:
15441542
OUTPUT:
1545-
hash: 87f40be6ec08f3fcbb5707762de71f6be35bb265c61f594335562a26
1543+
hash:
1544+
- 87f40be6ec08f3fcbb5707762de71f6be35bb265c61f594335562a26
1545+
- a31f0faf918ebe0902e5c9c5c8cf606d30f52eb4094bf24e4f8ac67a
15461546
type: rasterhash
15471547
#TRIANGULATION_FILE:
15481548
# name: expected/triangulation.gml
@@ -1551,8 +1551,6 @@ tests:
15511551
- algorithm: qgis:tininterpolation
15521552
name: TIN interpolation using Z value
15531553
params:
1554-
CELLSIZE_X: 0.02667
1555-
CELLSIZE_Y: 0.02667
15561554
COLUMNS: 300
15571555
EXTENT: 0, 8, -5, 3
15581556
INTERPOLATION_DATA:
@@ -1562,7 +1560,9 @@ tests:
15621560
ROWS: 300
15631561
results:
15641562
OUTPUT:
1565-
hash: 5e14dd0b879884b8b8da56c082947dad681feb4e9f1137f5cda126f8
1563+
hash:
1564+
- 5e14dd0b879884b8b8da56c082947dad681feb4e9f1137f5cda126f8
1565+
- b8389559d6a85e7a672d72254228473fae71af2d89e5a5dd73d1b0d7
15661566
type: rasterhash
15671567
#TRIANULATION_FILE:
15681568
# name: expected/triangulation.gml

‎src/analysis/interpolation/CloughTocherInterpolator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ void CloughTocherInterpolator::init( double x, double y )//version, which has th
227227

228228
if ( mTIN )
229229
{
230-
mTIN->getTriangle( x, y, &point1, &ptn1, &v1, &state1, &point2, &ptn2, &v2, &state2, &point3, &ptn3, &v3, &state3 );
230+
mTIN->getTriangle( x, y, point1, ptn1, &v1, &state1, point2, ptn2, &v2, &state2, point3, ptn3, &v3, &state3 );
231231

232232
if ( point1 == lpoint1 && point2 == lpoint2 && point3 == lpoint3 )//if we are in the same triangle as at the last run, we can leave 'init'
233233
{

0 commit comments

Comments
 (0)
Please sign in to comment.