Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[processing] Fix exception when clicking help for GDAL algorithms
(cherry-picked from b328819)
  • Loading branch information
nyalldawson committed May 11, 2018
1 parent c9226ce commit 27aeb6a
Show file tree
Hide file tree
Showing 29 changed files with 140 additions and 24 deletions.
3 changes: 3 additions & 0 deletions python/plugins/processing/algs/gdal/AssignProjection.py
Expand Up @@ -73,6 +73,9 @@ def group(self):
def groupId(self):
return 'rasterprojections'

def commandName(self):
return 'gdal_edit'

def getConsoleCommands(self, parameters, context, feedback, executing=True):
inLayer = self.parameterAsRasterLayer(parameters, self.INPUT, context)
fileName = inLayer.source()
Expand Down
5 changes: 4 additions & 1 deletion python/plugins/processing/algs/gdal/ClipRasterByMask.py
Expand Up @@ -119,6 +119,9 @@ def group(self):
def groupId(self):
return 'rasterextraction'

def commandName(self):
return 'gdalwarp'

def getConsoleCommands(self, parameters, context, feedback, executing=True):
inLayer = self.parameterAsRasterLayer(parameters, self.INPUT, context)

Expand Down Expand Up @@ -159,4 +162,4 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
arguments.append(inLayer.source())
arguments.append(out)

return ['gdalwarp', GdalUtils.escapeAndJoin(arguments)]
return [self.commandName(), GdalUtils.escapeAndJoin(arguments)]
5 changes: 4 additions & 1 deletion python/plugins/processing/algs/gdal/ColorRelief.py
Expand Up @@ -95,6 +95,9 @@ def group(self):
def groupId(self):
return 'rasteranalysis'

def commandName(self):
return 'gdaldem'

def getConsoleCommands(self, parameters, context, feedback, executing=True):
arguments = ['color-relief']
inLayer = self.parameterAsRasterLayer(parameters, self.INPUT, context)
Expand All @@ -115,4 +118,4 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):

arguments.append(self.modes[self.parameterAsEnum(parameters, self.MATCH_MODE, context)][1])

return ['gdaldem', GdalUtils.escapeAndJoin(arguments)]
return [self.commandName(), GdalUtils.escapeAndJoin(arguments)]
10 changes: 6 additions & 4 deletions python/plugins/processing/algs/gdal/GdalAlgorithm.py
Expand Up @@ -32,7 +32,9 @@

from qgis.core import (QgsApplication,
QgsVectorFileWriter,
QgsProcessingAlgorithm)
QgsProcessingAlgorithm,
QgsProcessingContext,
QgsProcessingFeedback)

from processing.algs.gdal.GdalAlgorithmDialog import GdalAlgorithmDialog
from processing.algs.gdal.GdalUtils import GdalUtils
Expand Down Expand Up @@ -136,11 +138,11 @@ def helpUrl(self):

def commandName(self):
parameters = {}
for output in self.outputs:
output.setValue("dummy")
for param in self.parameterDefinitions():
parameters[param.name()] = "1"
name = self.getConsoleCommands(parameters)[0]
context = QgsProcessingContext()
feedback = QgsProcessingFeedback()
name = self.getConsoleCommands(parameters, context, feedback, executing=False)[0]
if name.endswith(".py"):
name = name[:-3]
return name
Expand Down
5 changes: 4 additions & 1 deletion python/plugins/processing/algs/gdal/aspect.py
Expand Up @@ -96,6 +96,9 @@ def group(self):
def groupId(self):
return 'rasteranalysis'

def commandName(self):
return 'gdaldem'

def getConsoleCommands(self, parameters, context, feedback, executing=True):
arguments = ['aspect']
inLayer = self.parameterAsRasterLayer(parameters, self.INPUT, context)
Expand Down Expand Up @@ -127,4 +130,4 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
if options:
arguments.extend(GdalUtils.parseCreationOptions(options))

return ['gdaldem', GdalUtils.escapeAndJoin(arguments)]
return [self.commandName(), GdalUtils.escapeAndJoin(arguments)]
5 changes: 4 additions & 1 deletion python/plugins/processing/algs/gdal/contour.py
Expand Up @@ -121,6 +121,9 @@ def group(self):
def groupId(self):
return 'rasterextraction'

def commandName(self):
return 'gdal_contour'

def getConsoleCommands(self, parameters, context, feedback, executing=True):
inLayer = self.parameterAsRasterLayer(parameters, self.INPUT, context)
fieldName = self.parameterAsString(parameters, self.FIELD_NAME, context)
Expand Down Expand Up @@ -159,4 +162,4 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
arguments.append(inLayer.source())
arguments.append(output)

return ['gdal_contour', GdalUtils.escapeAndJoin(arguments)]
return [self.commandName(), GdalUtils.escapeAndJoin(arguments)]
3 changes: 3 additions & 0 deletions python/plugins/processing/algs/gdal/fillnodata.py
Expand Up @@ -89,6 +89,9 @@ def group(self):
def groupId(self):
return 'rasteranalysis'

def commandName(self):
return 'gdal_fillnodata'

def getConsoleCommands(self, parameters, context, feedback, executing=True):
arguments = []
arguments.append('-md')
Expand Down
3 changes: 3 additions & 0 deletions python/plugins/processing/algs/gdal/gdal2tiles.py
Expand Up @@ -154,6 +154,9 @@ def group(self):
def groupId(self):
return 'rastermiscellaneous'

def commandName(self):
return 'gdal2tiles'

def getConsoleCommands(self, parameters, context, feedback, executing=True):
arguments = []

Expand Down
4 changes: 3 additions & 1 deletion python/plugins/processing/algs/gdal/gdal2xyz.py
Expand Up @@ -71,8 +71,10 @@ def group(self):
def groupId(self):
return 'rasterconversion'

def commandName(self):
return 'gdal2xyz'

def getConsoleCommands(self, parameters, context, feedback, executing=True):
arguments = []
arguments = []
arguments.append('-band')
arguments.append(str(self.parameterAsInt(parameters, self.BAND, context)))
Expand Down
5 changes: 4 additions & 1 deletion python/plugins/processing/algs/gdal/gdaladdo.py
Expand Up @@ -105,6 +105,9 @@ def groupId(self):
def icon(self):
return QIcon(os.path.join(pluginPath, 'images', 'gdaltools', 'raster-overview.png'))

def commandName(self):
return 'gdaladdo'

def getConsoleCommands(self, parameters, context, feedback, executing=True):
inLayer = self.parameterAsRasterLayer(parameters, self.INPUT, context)
fileName = inLayer.source()
Expand All @@ -128,4 +131,4 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):

self.setOutputValue(self.OUTPUT, fileName)

return ['gdaladdo', GdalUtils.escapeAndJoin(arguments)]
return [self.commandName(), GdalUtils.escapeAndJoin(arguments)]
5 changes: 4 additions & 1 deletion python/plugins/processing/algs/gdal/gdalinfo.py
Expand Up @@ -84,6 +84,9 @@ def groupId(self):
def icon(self):
return QIcon(os.path.join(pluginPath, 'images', 'gdaltools', 'raster-info.png'))

def commandName(self):
return 'gdalinfo'

def getConsoleCommands(self, parameters, context, feedback, executing=True):
arguments = []
if self.parameterAsBool(parameters, self.MIN_MAX, context):
Expand All @@ -95,7 +98,7 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
if self.parameterAsBool(parameters, self.NO_METADATA, context):
arguments.append('-nomd')
arguments.append(self.parameterAsRasterLayer(parameters, self.INPUT, context).source())
return ['gdalinfo', GdalUtils.escapeAndJoin(arguments)]
return [self.commandName(), GdalUtils.escapeAndJoin(arguments)]

def processAlgorithm(self, parameters, context, feedback):
GdalUtils.runGdal(self.getConsoleCommands(parameters, context, feedback), feedback)
Expand Down
5 changes: 4 additions & 1 deletion python/plugins/processing/algs/gdal/gdaltindex.py
Expand Up @@ -117,6 +117,9 @@ def groupId(self):
def icon(self):
return QIcon(os.path.join(pluginPath, 'images', 'gdaltools', 'tiles.png'))

def commandName(self):
return 'gdaltindex'

def getConsoleCommands(self, parameters, context, feedback, executing=True):
input_layers = self.parameterAsLayerList(parameters, self.LAYERS, context)
crs_field = self.parameterAsString(parameters, self.CRS_FIELD_NAME, context)
Expand Down Expand Up @@ -158,4 +161,4 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
arguments.append(output)
arguments.append(' '.join(layers))

return ['gdaltindex', GdalUtils.escapeAndJoin(arguments)]
return [self.commandName(), GdalUtils.escapeAndJoin(arguments)]
5 changes: 4 additions & 1 deletion python/plugins/processing/algs/gdal/hillshade.py
Expand Up @@ -123,6 +123,9 @@ def group(self):
def groupId(self):
return 'rasteranalysis'

def commandName(self):
return 'gdaldem'

def getConsoleCommands(self, parameters, context, feedback, executing=True):
arguments = ['hillshade']
inLayer = self.parameterAsRasterLayer(parameters, self.INPUT, context)
Expand Down Expand Up @@ -162,4 +165,4 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
if options:
arguments.extend(GdalUtils.parseCreationOptions(options))

return ['gdaldem', GdalUtils.escapeAndJoin(arguments)]
return [self.commandName(), GdalUtils.escapeAndJoin(arguments)]
5 changes: 4 additions & 1 deletion python/plugins/processing/algs/gdal/nearblack.py
Expand Up @@ -92,6 +92,9 @@ def groupId(self):
def icon(self):
return QIcon(os.path.join(pluginPath, 'images', 'gdaltools', 'nearblack.png'))

def commandName(self):
return 'nearblack'

def getConsoleCommands(self, parameters, context, feedback, executing=True):
inLayer = self.parameterAsRasterLayer(parameters, self.INPUT, context)

Expand All @@ -114,4 +117,4 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
if options:
arguments.extend(GdalUtils.parseCreationOptions(options))

return ['nearblack', GdalUtils.escapeAndJoin(arguments)]
return [self.commandName(), GdalUtils.escapeAndJoin(arguments)]
6 changes: 4 additions & 2 deletions python/plugins/processing/algs/gdal/ogrinfo.py
Expand Up @@ -69,9 +69,11 @@ def group(self):
def groupId(self):
return 'vectormiscellaneous'

def commandName(self):
return 'ogrinfo'

def getConsoleCommands(self, parameters, context, feedback, executing=True):
arguments = ['ogrinfo']
arguments.append('-al')
arguments = [self.commandName(), '-al']

if self.parameterAsBool(parameters, self.SUMMARY_ONLY, context):
arguments.append('-so')
Expand Down
3 changes: 3 additions & 0 deletions python/plugins/processing/algs/gdal/pct2rgb.py
Expand Up @@ -77,6 +77,9 @@ def groupId(self):
def icon(self):
return QIcon(os.path.join(pluginPath, 'images', 'gdaltools', '8-to-24-bits.png'))

def commandName(self):
return 'pct2rgb'

def getConsoleCommands(self, parameters, context, feedback, executing=True):
arguments = []
inLayer = self.parameterAsRasterLayer(parameters, self.INPUT, context)
Expand Down
3 changes: 3 additions & 0 deletions python/plugins/processing/algs/gdal/polygonize.py
Expand Up @@ -85,6 +85,9 @@ def groupId(self):
def icon(self):
return QIcon(os.path.join(pluginPath, 'images', 'gdaltools', 'polygonize.png'))

def commandName(self):
return 'gdal_polygonize'

def getConsoleCommands(self, parameters, context, feedback, executing=True):
arguments = []
inLayer = self.parameterAsRasterLayer(parameters, self.INPUT, context)
Expand Down
3 changes: 3 additions & 0 deletions python/plugins/processing/algs/gdal/proximity.py
Expand Up @@ -131,6 +131,9 @@ def group(self):
def groupId(self):
return 'rasteranalysis'

def commandName(self):
return 'gdal_proximity'

def getConsoleCommands(self, parameters, context, feedback, executing=True):
inLayer = self.parameterAsRasterLayer(parameters, self.INPUT, context)
distance = self.parameterAsDouble(parameters, self.MAX_DISTANCE, context)
Expand Down
3 changes: 3 additions & 0 deletions python/plugins/processing/algs/gdal/rgb2pct.py
Expand Up @@ -76,6 +76,9 @@ def groupId(self):
def icon(self):
return QIcon(os.path.join(pluginPath, 'images', 'gdaltools', '24-to-8-bits.png'))

def commandName(self):
return 'rgb2pct'

def getConsoleCommands(self, parameters, context, feedback, executing=True):
arguments = []
arguments.append('-n')
Expand Down
5 changes: 4 additions & 1 deletion python/plugins/processing/algs/gdal/roughness.py
Expand Up @@ -85,6 +85,9 @@ def group(self):
def groupId(self):
return 'rasteranalysis'

def commandName(self):
return 'gdaldem'

def getConsoleCommands(self, parameters, context, feedback, executing=True):
arguments = ['roughness']
inLayer = self.parameterAsRasterLayer(parameters, self.INPUT, context)
Expand All @@ -107,4 +110,4 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
arguments.append('-co')
arguments.append(options)

return ['gdaldem', GdalUtils.escapeAndJoin(arguments)]
return [self.commandName(), GdalUtils.escapeAndJoin(arguments)]
3 changes: 3 additions & 0 deletions python/plugins/processing/algs/gdal/sieve.py
Expand Up @@ -87,6 +87,9 @@ def groupId(self):
def icon(self):
return QIcon(os.path.join(pluginPath, 'images', 'gdaltools', 'sieve.png'))

def commandName(self):
return 'gdal_sieve'

def getConsoleCommands(self, parameters, context, feedback, executing=True):
arguments = []
arguments.append('-st')
Expand Down
5 changes: 4 additions & 1 deletion python/plugins/processing/algs/gdal/slope.py
Expand Up @@ -100,6 +100,9 @@ def group(self):
def groupId(self):
return 'rasteranalysis'

def commandName(self):
return 'gdaldem'

def getConsoleCommands(self, parameters, context, feedback, executing=True):
arguments = ['slope']
inLayer = self.parameterAsRasterLayer(parameters, self.INPUT, context)
Expand Down Expand Up @@ -131,4 +134,4 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
if options:
arguments.extend(GdalUtils.parseCreationOptions(options))

return ['gdaldem', GdalUtils.escapeAndJoin(arguments)]
return [self.commandName(), GdalUtils.escapeAndJoin(arguments)]
5 changes: 4 additions & 1 deletion python/plugins/processing/algs/gdal/tpi.py
Expand Up @@ -84,6 +84,9 @@ def group(self):
def groupId(self):
return 'rasteranalysis'

def commandName(self):
return 'gdaldem'

def getConsoleCommands(self, parameters, context, feedback, executing=True):
arguments = ['TPI']
inLayer = self.parameterAsRasterLayer(parameters, self.INPUT, context)
Expand All @@ -101,4 +104,4 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
if options:
arguments.extend(GdalUtils.parseCreationOptions(options))

return ['gdaldem', GdalUtils.escapeAndJoin(arguments)]
return [self.commandName(), GdalUtils.escapeAndJoin(arguments)]
5 changes: 4 additions & 1 deletion python/plugins/processing/algs/gdal/translate.py
Expand Up @@ -110,6 +110,9 @@ def groupId(self):
def icon(self):
return QIcon(os.path.join(pluginPath, 'images', 'gdaltools', 'translate.png'))

def commandName(self):
return 'gdal_translate'

def getConsoleCommands(self, parameters, context, feedback, executing=True):
inLayer = self.parameterAsRasterLayer(parameters, self.INPUT, context)
out = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
Expand Down Expand Up @@ -145,4 +148,4 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
arguments.append(inLayer.source())
arguments.append(out)

return ['gdal_translate', GdalUtils.escapeAndJoin(arguments)]
return [self.commandName(), GdalUtils.escapeAndJoin(arguments)]
5 changes: 4 additions & 1 deletion python/plugins/processing/algs/gdal/tri.py
Expand Up @@ -83,6 +83,9 @@ def group(self):
def groupId(self):
return 'rasteranalysis'

def commandName(self):
return 'gdaldem'

def getConsoleCommands(self, parameters, context, feedback, executing=True):
arguments = ['TRI']
inLayer = self.parameterAsRasterLayer(parameters, self.INPUT, context)
Expand All @@ -100,4 +103,4 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
if options:
arguments.extend(GdalUtils.parseCreationOptions(options))

return ['gdaldem', GdalUtils.escapeAndJoin(arguments)]
return [self.commandName(), GdalUtils.escapeAndJoin(arguments)]
5 changes: 4 additions & 1 deletion python/plugins/processing/algs/gdal/warp.py
Expand Up @@ -158,6 +158,9 @@ def icon(self):
def tags(self):
return self.tr('transform,reproject,crs,srs').split(',')

def commandName(self):
return 'gdalwarp'

def getConsoleCommands(self, parameters, context, feedback, executing=True):
inLayer = self.parameterAsRasterLayer(parameters, self.INPUT, context)
out = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
Expand Down Expand Up @@ -217,4 +220,4 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
arguments.append(inLayer.source())
arguments.append(out)

return ['gdalwarp', GdalUtils.escapeAndJoin(arguments)]
return [self.commandName(), GdalUtils.escapeAndJoin(arguments)]

0 comments on commit 27aeb6a

Please sign in to comment.