Skip to content
Permalink
Browse files

[processing][gdal] Ensure that GDAL algs output the CORRECT

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 c93775f6b177ab2f64bd347c9a6f78896cee78dd
Showing with 41 additions and 0 deletions.
  1. +1 −0 python/plugins/processing/algs/gdal/Buffer.py
  2. +1 −0 python/plugins/processing/algs/gdal/ClipRasterByExtent.py
  3. +1 −0 python/plugins/processing/algs/gdal/ClipRasterByMask.py
  4. +1 −0 python/plugins/processing/algs/gdal/ClipVectorByExtent.py
  5. +1 −0 python/plugins/processing/algs/gdal/ClipVectorByMask.py
  6. +1 −0 python/plugins/processing/algs/gdal/ColorRelief.py
  7. +1 −0 python/plugins/processing/algs/gdal/Dissolve.py
  8. +1 −0 python/plugins/processing/algs/gdal/ExecuteSql.py
  9. +1 −0 python/plugins/processing/algs/gdal/GridAverage.py
  10. +1 −0 python/plugins/processing/algs/gdal/GridDataMetrics.py
  11. +1 −0 python/plugins/processing/algs/gdal/GridInverseDistance.py
  12. +1 −0 python/plugins/processing/algs/gdal/GridInverseDistanceNearestNeighbor.py
  13. +1 −0 python/plugins/processing/algs/gdal/GridLinear.py
  14. +1 −0 python/plugins/processing/algs/gdal/GridNearestNeighbor.py
  15. +1 −0 python/plugins/processing/algs/gdal/OffsetCurve.py
  16. +1 −0 python/plugins/processing/algs/gdal/OneSideBuffer.py
  17. +1 −0 python/plugins/processing/algs/gdal/PointsAlongLines.py
  18. +1 −0 python/plugins/processing/algs/gdal/aspect.py
  19. +1 −0 python/plugins/processing/algs/gdal/buildvrt.py
  20. +1 −0 python/plugins/processing/algs/gdal/contour.py
  21. +1 −0 python/plugins/processing/algs/gdal/fillnodata.py
  22. +1 −0 python/plugins/processing/algs/gdal/gdalcalc.py
  23. +1 −0 python/plugins/processing/algs/gdal/gdaltindex.py
  24. +1 −0 python/plugins/processing/algs/gdal/hillshade.py
  25. +1 −0 python/plugins/processing/algs/gdal/merge.py
  26. +1 −0 python/plugins/processing/algs/gdal/nearblack.py
  27. +1 −0 python/plugins/processing/algs/gdal/ogr2ogr.py
  28. +1 −0 python/plugins/processing/algs/gdal/pct2rgb.py
  29. +1 −0 python/plugins/processing/algs/gdal/polygonize.py
  30. +1 −0 python/plugins/processing/algs/gdal/proximity.py
  31. +1 −0 python/plugins/processing/algs/gdal/rasterize.py
  32. +1 −0 python/plugins/processing/algs/gdal/rearrange_bands.py
  33. +1 −0 python/plugins/processing/algs/gdal/rgb2pct.py
  34. +1 −0 python/plugins/processing/algs/gdal/roughness.py
  35. +1 −0 python/plugins/processing/algs/gdal/sieve.py
  36. +1 −0 python/plugins/processing/algs/gdal/slope.py
  37. +1 −0 python/plugins/processing/algs/gdal/tpi.py
  38. +1 −0 python/plugins/processing/algs/gdal/translate.py
  39. +1 −0 python/plugins/processing/algs/gdal/tri.py
  40. +2 −0 python/plugins/processing/algs/gdal/warp.py
@@ -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)

@@ -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')
@@ -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 = []

@@ -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)

@@ -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)

@@ -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')
@@ -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)

@@ -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)

@@ -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]))

@@ -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)
@@ -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]))

@@ -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]))

@@ -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]))

@@ -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]))

@@ -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)

@@ -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)

@@ -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)
@@ -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]))
@@ -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)]
@@ -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 = []
@@ -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]))

@@ -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)
@@ -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 = []
@@ -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')
@@ -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):
@@ -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')
@@ -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)

@@ -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')
@@ -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)

@@ -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')
@@ -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)
@@ -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 = []

@@ -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)
@@ -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')
@@ -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]))

@@ -114,6 +114,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')
@@ -97,6 +97,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('-b')
@@ -120,6 +120,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)
if self.NODATA in parameters and parameters[self.NODATA] is not None:
nodata = self.parameterAsDouble(parameters, self.NODATA, context)
else:
@@ -96,6 +96,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('-b')
@@ -180,6 +180,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)
sourceCrs = self.parameterAsCrs(parameters, self.SOURCE_CRS, context)
targetCrs = self.parameterAsCrs(parameters, self.TARGET_CRS, context)
if self.NODATA in parameters and parameters[self.NODATA] is not None:
@@ -230,6 +231,7 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
arguments.append('-ot ' + self.TYPES[data_type])

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

0 comments on commit c93775f

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