Skip to content
Permalink
Browse files

Merge pull request #5518 from nyalldawson/interp

Start on unit tests for interpolation classes
  • Loading branch information
nyalldawson committed Nov 3, 2017
2 parents fb7f8f1 + 61fa8da commit 33d422b4de8f893c8fe7b52d88c25aa5f51f72d3
@@ -17,14 +17,23 @@ class QgsGridFileWriter
#include "qgsgridfilewriter.h"
%End
public:
QgsGridFileWriter( QgsInterpolator *i, const QString &outputPath, const QgsRectangle &extent, int nCols, int nRows, double cellSizeX, double cellSizeY );

QgsGridFileWriter( QgsInterpolator *interpolator, const QString &outputPath, const QgsRectangle &extent, int nCols, int nRows );
%Docstring
Constructor for QgsGridFileWriter, for the specified ``interpolator``.

The ``outputPath`` argument is used to set the output file path.

The ``extent`` and ``nCols``, ``nRows`` arguments dictate the extent and size of the output raster.
%End

int writeFile( QgsFeedback *feedback = 0 );
%Docstring
Writes the grid file.
\param feedback optional feedback object for progress reports and cancelation support
:return: 0 in case of success*

An optional ``feedback`` object can be set for progress reports and cancelation support

:return: 0 in case of success
:rtype: int
%End

@@ -89,8 +89,6 @@ class IdwInterpolation(QgisAlgorithm):
DISTANCE_COEFFICIENT = 'DISTANCE_COEFFICIENT'
COLUMNS = 'COLUMNS'
ROWS = 'ROWS'
CELLSIZE_X = 'CELLSIZE_X'
CELLSIZE_Y = 'CELLSIZE_Y'
EXTENT = 'EXTENT'
OUTPUT = 'OUTPUT'

@@ -116,12 +114,6 @@ def initAlgorithm(self, config=None):
self.addParameter(QgsProcessingParameterNumber(self.ROWS,
self.tr('Number of rows'),
minValue=0, maxValue=10000000, defaultValue=300))
self.addParameter(QgsProcessingParameterNumber(self.CELLSIZE_X,
self.tr('Cell Size X'), type=QgsProcessingParameterNumber.Double,
minValue=0.0, maxValue=999999.000000, defaultValue=0.0))
self.addParameter(QgsProcessingParameterNumber(self.CELLSIZE_Y,
self.tr('Cell Size Y'), type=QgsProcessingParameterNumber.Double,
minValue=0.0, maxValue=999999.000000, defaultValue=0.0))
self.addParameter(QgsProcessingParameterExtent(self.EXTENT,
self.tr('Extent'),
optional=False))
@@ -139,8 +131,6 @@ def processAlgorithm(self, parameters, context, feedback):
coefficient = self.parameterAsDouble(parameters, self.DISTANCE_COEFFICIENT, context)
columns = self.parameterAsInt(parameters, self.COLUMNS, context)
rows = self.parameterAsInt(parameters, self.ROWS, context)
cellsizeX = self.parameterAsDouble(parameters, self.CELLSIZE_X, context)
cellsizeY = self.parameterAsDouble(parameters, self.CELLSIZE_Y, context)
bbox = self.parameterAsExtent(parameters, self.EXTENT, context)
output = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)

@@ -176,9 +166,7 @@ def processAlgorithm(self, parameters, context, feedback):
output,
bbox,
columns,
rows,
cellsizeX,
cellsizeY)
rows)

writer.writeFile(feedback)
return {self.OUTPUT: output}
@@ -92,8 +92,6 @@ class TinInterpolation(QgisAlgorithm):
METHOD = 'METHOD'
COLUMNS = 'COLUMNS'
ROWS = 'ROWS'
CELLSIZE_X = 'CELLSIZE_X'
CELLSIZE_Y = 'CELLSIZE_Y'
EXTENT = 'EXTENT'
OUTPUT = 'OUTPUT'
TRIANGULATION = 'TRIANGULATION'
@@ -124,12 +122,6 @@ def initAlgorithm(self, config=None):
self.addParameter(QgsProcessingParameterNumber(self.ROWS,
self.tr('Number of rows'),
minValue=0, maxValue=10000000, defaultValue=300))
self.addParameter(QgsProcessingParameterNumber(self.CELLSIZE_X,
self.tr('Cell size X'), type=QgsProcessingParameterNumber.Double,
minValue=0.0, maxValue=999999.000000, defaultValue=0.0))
self.addParameter(QgsProcessingParameterNumber(self.CELLSIZE_Y,
self.tr('Cell size Y'), type=QgsProcessingParameterNumber.Double,
minValue=0.0, maxValue=999999.000000, defaultValue=0.0))
self.addParameter(QgsProcessingParameterExtent(self.EXTENT,
self.tr('Extent'),
optional=False))
@@ -154,19 +146,13 @@ def processAlgorithm(self, parameters, context, feedback):
method = self.parameterAsEnum(parameters, self.METHOD, context)
columns = self.parameterAsInt(parameters, self.COLUMNS, context)
rows = self.parameterAsInt(parameters, self.ROWS, context)
cellsizeX = self.parameterAsDouble(parameters, self.CELLSIZE_X, context)
cellsizeY = self.parameterAsDouble(parameters, self.CELLSIZE_Y, context)
bbox = self.parameterAsExtent(parameters, self.EXTENT, context)
output = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)

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

if cellsizeX == 0.0 or cellsizeY == 0.0:
raise QgsProcessingException(
self.tr('Cellsize should be greater than 0.'))

layerData = []
layers = []
crs = QgsCoordinateReferenceSystem()
@@ -207,9 +193,7 @@ def processAlgorithm(self, parameters, context, feedback):
output,
bbox,
columns,
rows,
cellsizeX,
cellsizeY)
rows)

writer.writeFile(feedback)
return {self.OUTPUT: output, self.TRIANGULATION: triangulation_dest_id}
@@ -1497,8 +1497,6 @@ tests:
- algorithm: qgis:idwinterpolation
name: IDW interpolation using attribute
params:
CELLSIZE_X: 0.02667
CELLSIZE_Y: 0.02667
COLUMNS: 300
DISTANCE_COEFFICIENT: 2.0
EXTENT: 0, 8, -5, 3
@@ -1508,14 +1506,14 @@ tests:
ROWS: 300
results:
OUTPUT:
hash: 56d2671d50444f8571affba3f9e585830b82af5e380394178f521065
hash:
- 56d2671d50444f8571affba3f9e585830b82af5e380394178f521065
- 2ae62aca803e6864ac75e47b4357292b0637d811cb510ed19471f422
type: rasterhash

- algorithm: qgis:idwinterpolation
name: IDW interpolation using Z value
params:
CELLSIZE_X: 0.02667
CELLSIZE_Y: 0.02667
COLUMNS: 300
DISTANCE_COEFFICIENT: 2.0
EXTENT: 0, 8, -5, 3
@@ -1525,14 +1523,14 @@ tests:
ROWS: 300
results:
OUTPUT:
hash: 56d2671d50444f8571affba3f9e585830b82af5e380394178f521065
hash:
- 56d2671d50444f8571affba3f9e585830b82af5e380394178f521065
- 2ae62aca803e6864ac75e47b4357292b0637d811cb510ed19471f422
type: rasterhash

- algorithm: qgis:tininterpolation
name: TIN interpolation using attribute
params:
CELLSIZE_X: 0.02667
CELLSIZE_Y: 0.02667
COLUMNS: 300
EXTENT: 0, 8, -5, 3
INTERPOLATION_DATA:
@@ -1542,7 +1540,9 @@ tests:
ROWS: 300
results:
OUTPUT:
hash: 87f40be6ec08f3fcbb5707762de71f6be35bb265c61f594335562a26
hash:
- 87f40be6ec08f3fcbb5707762de71f6be35bb265c61f594335562a26
- a31f0faf918ebe0902e5c9c5c8cf606d30f52eb4094bf24e4f8ac67a
type: rasterhash
#TRIANGULATION_FILE:
# name: expected/triangulation.gml
@@ -1551,8 +1551,6 @@ tests:
- algorithm: qgis:tininterpolation
name: TIN interpolation using Z value
params:
CELLSIZE_X: 0.02667
CELLSIZE_Y: 0.02667
COLUMNS: 300
EXTENT: 0, 8, -5, 3
INTERPOLATION_DATA:
@@ -1562,7 +1560,9 @@ tests:
ROWS: 300
results:
OUTPUT:
hash: 5e14dd0b879884b8b8da56c082947dad681feb4e9f1137f5cda126f8
hash:
- 5e14dd0b879884b8b8da56c082947dad681feb4e9f1137f5cda126f8
- b8389559d6a85e7a672d72254228473fae71af2d89e5a5dd73d1b0d7
type: rasterhash
#TRIANULATION_FILE:
# name: expected/triangulation.gml
@@ -227,7 +227,7 @@ void CloughTocherInterpolator::init( double x, double y )//version, which has th

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

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

0 comments on commit 33d422b

Please sign in to comment.
You can’t perform that action at this time.