Skip to content

Commit

Permalink
[processing][gdal] Ensure that GDAL algs output the CORRECT
Browse files Browse the repository at this point in the history
generated filename for outputs

Previously they were just echoing the input parameter value,
which isn't always a string and accordingly was broken for
temporary outputs. This caused models to break when the output
of a GDAL algorithm was used in a subsequent model step.
  • Loading branch information
nyalldawson committed Feb 5, 2019
1 parent f54f5a4 commit c93775f
Show file tree
Hide file tree
Showing 40 changed files with 41 additions and 0 deletions.
1 change: 1 addition & 0 deletions python/plugins/processing/algs/gdal/Buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
dissolve = self.parameterAsBool(parameters, self.DISSOLVE, context)
options = self.parameterAsString(parameters, self.OPTIONS, context)
outFile = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
self.setOutputValue(self.OUTPUT, outFile)

output, outputFormat = GdalUtils.ogrConnectionStringAndFormat(outFile, context)

Expand Down
1 change: 1 addition & 0 deletions python/plugins/processing/algs/gdal/ClipRasterByExtent.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
nodata = None
options = self.parameterAsString(parameters, self.OPTIONS, context)
out = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
self.setOutputValue(self.OUTPUT, out)

arguments = []
arguments.append('-projwin')
Expand Down
1 change: 1 addition & 0 deletions python/plugins/processing/algs/gdal/ClipRasterByMask.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
nodata = None
options = self.parameterAsString(parameters, self.OPTIONS, context)
out = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
self.setOutputValue(self.OUTPUT, out)

arguments = []

Expand Down
1 change: 1 addition & 0 deletions python/plugins/processing/algs/gdal/ClipVectorByExtent.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
extent = self.parameterAsExtent(parameters, self.EXTENT, context, source.sourceCrs())
options = self.parameterAsString(parameters, self.OPTIONS, context)
outFile = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
self.setOutputValue(self.OUTPUT, outFile)

output, outputFormat = GdalUtils.ogrConnectionStringAndFormat(outFile, context)

Expand Down
1 change: 1 addition & 0 deletions python/plugins/processing/algs/gdal/ClipVectorByMask.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
maskLayer, maskLayerName = self.getOgrCompatibleSource(self.MASK, parameters, context, feedback, executing)
options = self.parameterAsString(parameters, self.OPTIONS, context)
outFile = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
self.setOutputValue(self.OUTPUT, outFile)

output, outputFormat = GdalUtils.ogrConnectionStringAndFormat(outFile, context)

Expand Down
1 change: 1 addition & 0 deletions python/plugins/processing/algs/gdal/ColorRelief.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
arguments.append(self.parameterAsFile(parameters, self.COLOR_TABLE, context))

out = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
self.setOutputValue(self.OUTPUT, out)
arguments.append(out)

arguments.append('-of')
Expand Down
1 change: 1 addition & 0 deletions python/plugins/processing/algs/gdal/Dissolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):

options = self.parameterAsString(parameters, self.OPTIONS, context)
outFile = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
self.setOutputValue(self.OUTPUT, outFile)

output, outputFormat = GdalUtils.ogrConnectionStringAndFormat(outFile, context)

Expand Down
1 change: 1 addition & 0 deletions python/plugins/processing/algs/gdal/ExecuteSql.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
sql = self.parameterAsString(parameters, self.SQL, context)
options = self.parameterAsString(parameters, self.OPTIONS, context)
outFile = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
self.setOutputValue(self.OUTPUT, outFile)

output, outputFormat = GdalUtils.ogrConnectionStringAndFormat(outFile, context)

Expand Down
1 change: 1 addition & 0 deletions python/plugins/processing/algs/gdal/GridAverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
arguments.append(self.TYPES[self.parameterAsEnum(parameters, self.DATA_TYPE, context)])

out = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
self.setOutputValue(self.OUTPUT, out)
arguments.append('-of')
arguments.append(QgsRasterFileWriter.driverForExtension(os.path.splitext(out)[1]))

Expand Down
1 change: 1 addition & 0 deletions python/plugins/processing/algs/gdal/GridDataMetrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
arguments.append(self.TYPES[self.parameterAsEnum(parameters, self.DATA_TYPE, context)])

out = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
self.setOutputValue(self.OUTPUT, out)
arguments.append('-of')
arguments.append(QgsRasterFileWriter.driverForExtension(os.path.splitext(out)[1]))
options = self.parameterAsString(parameters, self.OPTIONS, context)
Expand Down
1 change: 1 addition & 0 deletions python/plugins/processing/algs/gdal/GridInverseDistance.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
arguments.append(self.TYPES[self.parameterAsEnum(parameters, self.DATA_TYPE, context)])

out = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
self.setOutputValue(self.OUTPUT, out)
arguments.append('-of')
arguments.append(QgsRasterFileWriter.driverForExtension(os.path.splitext(out)[1]))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
arguments.append(self.TYPES[self.parameterAsEnum(parameters, self.DATA_TYPE, context)])

out = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
self.setOutputValue(self.OUTPUT, out)
arguments.append('-of')
arguments.append(QgsRasterFileWriter.driverForExtension(os.path.splitext(out)[1]))

Expand Down
1 change: 1 addition & 0 deletions python/plugins/processing/algs/gdal/GridLinear.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
arguments.append(self.TYPES[self.parameterAsEnum(parameters, self.DATA_TYPE, context)])

out = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
self.setOutputValue(self.OUTPUT, out)
arguments.append('-of')
arguments.append(QgsRasterFileWriter.driverForExtension(os.path.splitext(out)[1]))

Expand Down
1 change: 1 addition & 0 deletions python/plugins/processing/algs/gdal/GridNearestNeighbor.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
arguments.append(self.TYPES[self.parameterAsEnum(parameters, self.DATA_TYPE, context)])

out = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
self.setOutputValue(self.OUTPUT, out)
arguments.append('-of')
arguments.append(QgsRasterFileWriter.driverForExtension(os.path.splitext(out)[1]))

Expand Down
1 change: 1 addition & 0 deletions python/plugins/processing/algs/gdal/OffsetCurve.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
distance = self.parameterAsDouble(parameters, self.DISTANCE, context)
options = self.parameterAsString(parameters, self.OPTIONS, context)
outFile = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
self.setOutputValue(self.OUTPUT, outFile)

output, outputFormat = GdalUtils.ogrConnectionStringAndFormat(outFile, context)

Expand Down
1 change: 1 addition & 0 deletions python/plugins/processing/algs/gdal/OneSideBuffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
dissolve = self.parameterAsBool(parameters, self.DISSOLVE, context)
options = self.parameterAsString(parameters, self.OPTIONS, context)
outFile = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
self.setOutputValue(self.OUTPUT, outFile)

output, outputFormat = GdalUtils.ogrConnectionStringAndFormat(outFile, context)

Expand Down
1 change: 1 addition & 0 deletions python/plugins/processing/algs/gdal/PointsAlongLines.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
distance = self.parameterAsDouble(parameters, self.DISTANCE, context)
geometry = self.parameterAsString(parameters, self.GEOMETRY, context)
outFile = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
self.setOutputValue(self.OUTPUT, outFile)
options = self.parameterAsString(parameters, self.OPTIONS, context)

output, outputFormat = GdalUtils.ogrConnectionStringAndFormat(outFile, context)
Expand Down
1 change: 1 addition & 0 deletions python/plugins/processing/algs/gdal/aspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):

out = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
arguments.append(out)
self.setOutputValue(self.OUTPUT, out)

arguments.append('-of')
arguments.append(QgsRasterFileWriter.driverForExtension(os.path.splitext(out)[1]))
Expand Down
1 change: 1 addition & 0 deletions python/plugins/processing/algs/gdal/buildvrt.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
arguments.append(list_file)

out = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
self.setOutputValue(self.OUTPUT, out)
arguments.append(out)

return [self.commandName(), GdalUtils.escapeAndJoin(arguments)]
1 change: 1 addition & 0 deletions python/plugins/processing/algs/gdal/contour.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
offset = self.parameterAsDouble(parameters, self.OFFSET, context)

outFile = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
self.setOutputValue(self.OUTPUT, outFile)
output, outFormat = GdalUtils.ogrConnectionStringAndFormat(outFile, context)

arguments = []
Expand Down
1 change: 1 addition & 0 deletions python/plugins/processing/algs/gdal/fillnodata.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
arguments.append('-mask {}'.format(mask.source()))

out = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
self.setOutputValue(self.OUTPUT, out)
arguments.append('-of')
arguments.append(QgsRasterFileWriter.driverForExtension(os.path.splitext(out)[1]))

Expand Down
1 change: 1 addition & 0 deletions python/plugins/processing/algs/gdal/gdalcalc.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ def commandName(self):

def getConsoleCommands(self, parameters, context, feedback, executing=True):
out = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
self.setOutputValue(self.OUTPUT, out)
formula = self.parameterAsString(parameters, self.FORMULA, context)
if self.NO_DATA in parameters and parameters[self.NO_DATA] is not None:
noData = self.parameterAsDouble(parameters, self.NO_DATA, context)
Expand Down
1 change: 1 addition & 0 deletions python/plugins/processing/algs/gdal/gdaltindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
target_crs = self.parameterAsCrs(parameters, self.TARGET_CRS, context)

outFile = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
self.setOutputValue(self.OUTPUT, outFile)
output, outFormat = GdalUtils.ogrConnectionStringAndFormat(outFile, context)

layers = []
Expand Down
1 change: 1 addition & 0 deletions python/plugins/processing/algs/gdal/hillshade.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
arguments.append(inLayer.source())

out = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
self.setOutputValue(self.OUTPUT, out)
arguments.append(out)

arguments.append('-of')
Expand Down
1 change: 1 addition & 0 deletions python/plugins/processing/algs/gdal/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ def commandName(self):

def getConsoleCommands(self, parameters, context, feedback, executing=True):
out = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
self.setOutputValue(self.OUTPUT, out)

arguments = []
if self.parameterAsBool(parameters, self.PCT, context):
Expand Down
1 change: 1 addition & 0 deletions python/plugins/processing/algs/gdal/nearblack.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
arguments.append(inLayer.source())

out = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
self.setOutputValue(self.OUTPUT, out)
arguments.append('-of')
arguments.append(QgsRasterFileWriter.driverForExtension(os.path.splitext(out)[1]))
arguments.append('-o')
Expand Down
1 change: 1 addition & 0 deletions python/plugins/processing/algs/gdal/ogr2ogr.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
ogrLayer, layerName = self.getOgrCompatibleSource(self.INPUT, parameters, context, feedback, executing)
options = self.parameterAsString(parameters, self.OPTIONS, context)
outFile = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
self.setOutputValue(self.OUTPUT, outFile)

output, outputFormat = GdalUtils.ogrConnectionStringAndFormat(outFile, context)

Expand Down
1 change: 1 addition & 0 deletions python/plugins/processing/algs/gdal/pct2rgb.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
arguments.append(inLayer.source())

out = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
self.setOutputValue(self.OUTPUT, out)
arguments.append(out)

arguments.append('-of')
Expand Down
1 change: 1 addition & 0 deletions python/plugins/processing/algs/gdal/polygonize.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
arguments.append(inLayer.source())

outFile = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
self.setOutputValue(self.OUTPUT, outFile)
output, outFormat = GdalUtils.ogrConnectionStringAndFormat(outFile, context)
arguments.append(output)

Expand Down
1 change: 1 addition & 0 deletions python/plugins/processing/algs/gdal/proximity.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
nodata = None
options = self.parameterAsString(parameters, self.OPTIONS, context)
out = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
self.setOutputValue(self.OUTPUT, out)

arguments = []
arguments.append('-srcband')
Expand Down
1 change: 1 addition & 0 deletions python/plugins/processing/algs/gdal/rasterize.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
arguments.append(self.TYPES[self.parameterAsEnum(parameters, self.DATA_TYPE, context)])

out = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
self.setOutputValue(self.OUTPUT, out)
arguments.append('-of')
arguments.append(QgsRasterFileWriter.driverForExtension(os.path.splitext(out)[1]))
options = self.parameterAsString(parameters, self.OPTIONS, context)
Expand Down
1 change: 1 addition & 0 deletions python/plugins/processing/algs/gdal/rearrange_bands.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
raise QgsProcessingException(self.invalidRasterError(parameters, self.INPUT))

out = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
self.setOutputValue(self.OUTPUT, out)

arguments = []

Expand Down
1 change: 1 addition & 0 deletions python/plugins/processing/algs/gdal/rgb2pct.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
arguments.append(str(self.parameterAsInt(parameters, self.NCOLORS, context)))

out = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
self.setOutputValue(self.OUTPUT, out)
arguments.append('-of')
arguments.append(QgsRasterFileWriter.driverForExtension(os.path.splitext(out)[1]))
raster = self.parameterAsRasterLayer(parameters, self.INPUT, context)
Expand Down
1 change: 1 addition & 0 deletions python/plugins/processing/algs/gdal/roughness.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
arguments.append(inLayer.source())

out = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
self.setOutputValue(self.OUTPUT, out)
arguments.append(out)

arguments.append('-of')
Expand Down
1 change: 1 addition & 0 deletions python/plugins/processing/algs/gdal/sieve.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
arguments.append('-mask {}'.format(mask.source()))

out = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
self.setOutputValue(self.OUTPUT, out)
arguments.append('-of')
arguments.append(QgsRasterFileWriter.driverForExtension(os.path.splitext(out)[1]))

Expand Down
1 change: 1 addition & 0 deletions python/plugins/processing/algs/gdal/slope.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
arguments.append(inLayer.source())

out = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
self.