Skip to content
Permalink
Browse files

[processing][gdal] Better error messages when invalid parameters are …

…passed
  • Loading branch information
nyalldawson committed May 6, 2018
1 parent 787dd34 commit f4599f13f179ac2d36bcc44468d3d0b918c2bb77
Showing with 142 additions and 34 deletions.
  1. +5 −1 python/plugins/processing/algs/gdal/AssignProjection.py
  2. +4 −0 python/plugins/processing/algs/gdal/ClipRasterByExtent.py
  3. +3 −0 python/plugins/processing/algs/gdal/ClipRasterByMask.py
  4. +4 −0 python/plugins/processing/algs/gdal/ColorRelief.py
  5. +5 −1 python/plugins/processing/algs/gdal/OgrToPostGis.py
  6. +4 −1 python/plugins/processing/algs/gdal/aspect.py
  7. +4 −0 python/plugins/processing/algs/gdal/contour.py
  8. +6 −1 python/plugins/processing/algs/gdal/fillnodata.py
  9. +5 −1 python/plugins/processing/algs/gdal/gdal2tiles.py
  10. +6 −1 python/plugins/processing/algs/gdal/gdal2xyz.py
  11. +5 −1 python/plugins/processing/algs/gdal/gdaladdo.py
  12. +7 −2 python/plugins/processing/algs/gdal/gdalinfo.py
  13. +4 −0 python/plugins/processing/algs/gdal/hillshade.py
  14. +3 −0 python/plugins/processing/algs/gdal/nearblack.py
  15. +5 −1 python/plugins/processing/algs/gdal/ogrinfo.py
  16. +4 −0 python/plugins/processing/algs/gdal/pct2rgb.py
  17. +4 −0 python/plugins/processing/algs/gdal/polygonize.py
  18. +4 −0 python/plugins/processing/algs/gdal/proximity.py
  19. +6 −1 python/plugins/processing/algs/gdal/rgb2pct.py
  20. +4 −0 python/plugins/processing/algs/gdal/roughness.py
  21. +6 −1 python/plugins/processing/algs/gdal/sieve.py
  22. +4 −0 python/plugins/processing/algs/gdal/slope.py
  23. +5 −1 python/plugins/processing/algs/gdal/tpi.py
  24. +4 −0 python/plugins/processing/algs/gdal/translate.py
  25. +5 −1 python/plugins/processing/algs/gdal/tri.py
  26. +4 −0 python/plugins/processing/algs/gdal/warp.py
  27. +13 −1 python/plugins/processing/tests/GdalAlgorithmsTest.py
  28. +9 −19 python/plugins/processing/tools/postgis.py
@@ -29,7 +29,8 @@

from qgis.PyQt.QtGui import QIcon

from qgis.core import (QgsProcessingParameterRasterLayer,
from qgis.core import (QgsProcessingException,
QgsProcessingParameterRasterLayer,
QgsProcessingParameterCrs,
QgsProcessingOutputRasterLayer)
from processing.algs.gdal.GdalAlgorithm import GdalAlgorithm
@@ -78,6 +79,9 @@ def commandName(self):

def getConsoleCommands(self, parameters, context, feedback, executing=True):
inLayer = self.parameterAsRasterLayer(parameters, self.INPUT, context)
if inLayer is None:
raise QgsProcessingException(self.invalidRasterError(parameters, self.INPUT))

fileName = inLayer.source()

crs = self.parameterAsCrs(parameters, self.CRS, context).authid()
@@ -30,6 +30,7 @@
from qgis.PyQt.QtGui import QIcon

from qgis.core import (QgsRasterFileWriter,
QgsProcessingException,
QgsProcessingParameterDefinition,
QgsProcessingParameterRasterLayer,
QgsProcessingParameterEnum,
@@ -110,6 +111,9 @@ def commandName(self):

def getConsoleCommands(self, parameters, context, feedback, executing=True):
inLayer = self.parameterAsRasterLayer(parameters, self.INPUT, context)
if inLayer is None:
raise QgsProcessingException('Invalid input layer {}'.format(parameters[self.INPUT] if self.INPUT in parameters else 'INPUT'))

bbox = self.parameterAsExtent(parameters, self.EXTENT, context, inLayer.crs())
if self.NODATA in parameters and parameters[self.NODATA] is not None:
nodata = self.parameterAsDouble(parameters, self.NODATA, context)
@@ -31,6 +31,7 @@

from qgis.core import (QgsRasterFileWriter,
QgsProcessing,
QgsProcessingException,
QgsProcessingParameterDefinition,
QgsProcessingParameterFeatureSource,
QgsProcessingParameterRasterLayer,
@@ -124,6 +125,8 @@ def commandName(self):

def getConsoleCommands(self, parameters, context, feedback, executing=True):
inLayer = self.parameterAsRasterLayer(parameters, self.INPUT, context)
if inLayer is None:
raise QgsProcessingException(self.invalidRasterError(parameters, self.INPUT))

maskLayer, maskLayerName = self.getOgrCompatibleSource(self.MASK, parameters, context, feedback, executing)

@@ -27,6 +27,7 @@

import os
from qgis.core import (QgsRasterFileWriter,
QgsProcessingException,
QgsProcessingParameterDefinition,
QgsProcessingParameterRasterLayer,
QgsProcessingParameterBand,
@@ -102,6 +103,9 @@ def commandName(self):
def getConsoleCommands(self, parameters, context, feedback, executing=True):
arguments = ['color-relief']
inLayer = self.parameterAsRasterLayer(parameters, self.INPUT, context)
if inLayer is None:
raise QgsProcessingException(self.invalidRasterError(parameters, self.INPUT))

arguments.append(inLayer.source())
arguments.append(self.parameterAsFile(parameters, self.COLOR_TABLE, context))

@@ -25,7 +25,8 @@

__revision__ = '$Format:%H$'

from qgis.core import (QgsProcessingParameterFeatureSource,
from qgis.core import (QgsProcessingException,
QgsProcessingParameterFeatureSource,
QgsProcessingParameterString,
QgsProcessingParameterEnum,
QgsProcessingParameterCrs,
@@ -189,6 +190,9 @@ def getConnectionString(self, parameters, context):

def getConsoleCommands(self, parameters, context, feedback, executing=True):
ogrLayer, layername = self.getOgrCompatibleSource(self.INPUT, parameters, context, feedback, executing)
if not layername:
raise QgsProcessingException(self.invalidSourceError(parameters, self.INPUT))

shapeEncoding = self.parameterAsString(parameters, self.SHAPE_ENCODING, context)
ssrs = self.parameterAsCrs(parameters, self.S_SRS, context).authid()
tsrs = self.parameterAsCrs(parameters, self.T_SRS, context).authid()
@@ -27,7 +27,8 @@

import os

from qgis.core import (QgsRasterFileWriter,
from qgis.core import (QgsProcessingException,
QgsRasterFileWriter,
QgsProcessingParameterDefinition,
QgsProcessingParameterRasterLayer,
QgsProcessingParameterBand,
@@ -102,6 +103,8 @@ def commandName(self):
def getConsoleCommands(self, parameters, context, feedback, executing=True):
arguments = ['aspect']
inLayer = self.parameterAsRasterLayer(parameters, self.INPUT, context)
if inLayer is None:
raise QgsProcessingException(self.invalidRasterError(parameters, self.INPUT))
arguments.append(inLayer.source())

out = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
@@ -30,6 +30,7 @@
from qgis.PyQt.QtGui import QIcon

from qgis.core import (QgsProcessing,
QgsProcessingException,
QgsProcessingParameterDefinition,
QgsProcessingParameterRasterLayer,
QgsProcessingParameterBand,
@@ -126,6 +127,9 @@ def commandName(self):

def getConsoleCommands(self, parameters, context, feedback, executing=True):
inLayer = self.parameterAsRasterLayer(parameters, self.INPUT, context)
if inLayer is None:
raise QgsProcessingException(self.invalidRasterError(parameters, self.INPUT))

fieldName = self.parameterAsString(parameters, self.FIELD_NAME, context)
if self.NODATA in parameters and parameters[self.NODATA] is not None:
nodata = self.parameterAsDouble(parameters, self.NODATA, context)
@@ -28,6 +28,7 @@
import os

from qgis.core import (QgsRasterFileWriter,
QgsProcessingException,
QgsProcessingParameterRasterLayer,
QgsProcessingParameterBand,
QgsProcessingParameterNumber,
@@ -116,7 +117,11 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
arguments.append('-of')
arguments.append(QgsRasterFileWriter.driverForExtension(os.path.splitext(out)[1]))

arguments.append(self.parameterAsRasterLayer(parameters, self.INPUT, context).source())
raster = self.parameterAsRasterLayer(parameters, self.INPUT, context)
if raster is None:
raise QgsProcessingException(self.invalidRasterError(parameters, self.INPUT))

arguments.append(raster.source())
arguments.append(out)

commands = []
@@ -26,7 +26,8 @@
__revision__ = '$Format:%H$'


from qgis.core import (QgsProcessingParameterDefinition,
from qgis.core import (QgsProcessingException,
QgsProcessingParameterDefinition,
QgsProcessingParameterRasterLayer,
QgsProcessingParameterCrs,
QgsProcessingParameterEnum,
@@ -219,6 +220,9 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
arguments.append('-n')

inLayer = self.parameterAsRasterLayer(parameters, self.INPUT, context)
if inLayer is None:
raise QgsProcessingException(self.invalidRasterError(parameters, self.INPUT))

arguments.append(inLayer.source())
arguments.append(self.parameterAsString(parameters, self.OUTPUT, context))

@@ -26,6 +26,7 @@
__revision__ = '$Format:%H$'

from qgis.core import (QgsProcessing,
QgsProcessingException,
QgsProcessingParameterRasterLayer,
QgsProcessingParameterBand,
QgsProcessingParameterBoolean,
@@ -82,7 +83,11 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
if self.parameterAsBool(parameters, self.CSV, context):
arguments.append('-csv')

arguments.append(self.parameterAsRasterLayer(parameters, self.INPUT, context).source())
raster = self.parameterAsRasterLayer(parameters, self.INPUT, context)
if raster is None:
raise QgsProcessingException(self.invalidRasterError(parameters, self.INPUT))

arguments.append(raster.source())
arguments.append(self.parameterAsFileOutput(parameters, self.OUTPUT, context))

commands = []
@@ -29,7 +29,8 @@

from qgis.PyQt.QtGui import QIcon

from qgis.core import (QgsProcessingParameterRasterLayer,
from qgis.core import (QgsProcessingException,
QgsProcessingParameterRasterLayer,
QgsProcessingParameterEnum,
QgsProcessingParameterString,
QgsProcessingParameterBoolean,
@@ -110,6 +111,9 @@ def commandName(self):

def getConsoleCommands(self, parameters, context, feedback, executing=True):
inLayer = self.parameterAsRasterLayer(parameters, self.INPUT, context)
if inLayer is None:
raise QgsProcessingException(self.invalidRasterError(parameters, self.INPUT))

fileName = inLayer.source()

arguments = []
@@ -28,7 +28,8 @@
import os

from qgis.PyQt.QtGui import QIcon
from qgis.core import (QgsProcessingParameterRasterLayer,
from qgis.core import (QgsProcessingException,
QgsProcessingParameterRasterLayer,
QgsProcessingParameterBoolean,
QgsProcessingParameterFileDestination)
from processing.algs.gdal.GdalAlgorithm import GdalAlgorithm
@@ -97,7 +98,11 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
arguments.append('-nogcp')
if self.parameterAsBool(parameters, self.NO_METADATA, context):
arguments.append('-nomd')
arguments.append(self.parameterAsRasterLayer(parameters, self.INPUT, context).source())
raster = self.parameterAsRasterLayer(parameters, self.INPUT, context)
if raster is None:
raise QgsProcessingException(self.invalidRasterError(parameters, self.INPUT))

arguments.append(raster.source())
return [self.commandName(), GdalUtils.escapeAndJoin(arguments)]

def processAlgorithm(self, parameters, context, feedback):
@@ -29,6 +29,7 @@
import os

from qgis.core import (QgsRasterFileWriter,
QgsProcessingException,
QgsProcessingParameterDefinition,
QgsProcessingParameterRasterLayer,
QgsProcessingParameterBand,
@@ -129,6 +130,9 @@ def commandName(self):
def getConsoleCommands(self, parameters, context, feedback, executing=True):
arguments = ['hillshade']
inLayer = self.parameterAsRasterLayer(parameters, self.INPUT, context)
if inLayer is None:
raise QgsProcessingException(self.invalidRasterError(parameters, self.INPUT))

arguments.append(inLayer.source())

out = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
@@ -30,6 +30,7 @@
from qgis.PyQt.QtGui import QIcon

from qgis.core import (QgsRasterFileWriter,
QgsProcessingException,
QgsProcessingParameterDefinition,
QgsProcessingParameterRasterLayer,
QgsProcessingParameterBoolean,
@@ -97,6 +98,8 @@ def commandName(self):

def getConsoleCommands(self, parameters, context, feedback, executing=True):
inLayer = self.parameterAsRasterLayer(parameters, self.INPUT, context)
if inLayer is None:
raise QgsProcessingException(self.invalidRasterError(parameters, self.INPUT))

arguments = []
arguments.append(inLayer.source())
@@ -26,7 +26,8 @@
__revision__ = '$Format:%H$'


from qgis.core import (QgsProcessingParameterVectorLayer,
from qgis.core import (QgsProcessingException,
QgsProcessingParameterVectorLayer,
QgsProcessingParameterBoolean,
QgsProcessingParameterFileDestination)
from processing.algs.gdal.GdalAlgorithm import GdalAlgorithm
@@ -81,6 +82,9 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
arguments.append('-nomd')

inLayer = self.parameterAsVectorLayer(parameters, self.INPUT, context)
if inLayer is None:
raise QgsProcessingException(self.invalidSourceError(parameters, self.INPUT))

connectionString = GdalUtils.ogrConnectionString(inLayer.source(), context)
arguments.append(connectionString)
return arguments
@@ -30,6 +30,7 @@
from qgis.PyQt.QtGui import QIcon

from qgis.core import (QgsRasterFileWriter,
QgsProcessingException,
QgsProcessingParameterRasterLayer,
QgsProcessingParameterBand,
QgsProcessingParameterBoolean,
@@ -83,6 +84,9 @@ def commandName(self):
def getConsoleCommands(self, parameters, context, feedback, executing=True):
arguments = []
inLayer = self.parameterAsRasterLayer(parameters, self.INPUT, context)
if inLayer is None:
raise QgsProcessingException(self.invalidRasterError(parameters, self.INPUT))

arguments.append(inLayer.source())

out = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
@@ -31,6 +31,7 @@
from qgis.PyQt.QtCore import QFileInfo

from qgis.core import (QgsProcessing,
QgsProcessingException,
QgsProcessingParameterRasterLayer,
QgsProcessingParameterBand,
QgsProcessingParameterString,
@@ -91,6 +92,9 @@ def commandName(self):
def getConsoleCommands(self, parameters, context, feedback, executing=True):
arguments = []
inLayer = self.parameterAsRasterLayer(parameters, self.INPUT, context)
if inLayer is None:
raise QgsProcessingException(self.invalidRasterError(parameters, self.INPUT))

arguments.append(inLayer.source())

outFile = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
@@ -30,6 +30,7 @@
from qgis.PyQt.QtGui import QIcon

from qgis.core import (QgsRasterFileWriter,
QgsProcessingException,
QgsProcessingParameterDefinition,
QgsProcessingParameterRasterLayer,
QgsProcessingParameterBand,
@@ -136,6 +137,9 @@ def commandName(self):

def getConsoleCommands(self, parameters, context, feedback, executing=True):
inLayer = self.parameterAsRasterLayer(parameters, self.INPUT, context)
if inLayer is None:
raise QgsProcessingException(self.invalidRasterError(parameters, self.INPUT))

distance = self.parameterAsDouble(parameters, self.MAX_DISTANCE, context)
replaceValue = self.parameterAsDouble(parameters, self.REPLACE, context)
if self.NODATA in parameters and parameters[self.NODATA] is not None:
@@ -31,6 +31,7 @@
from qgis.PyQt.QtGui import QIcon

from qgis.core import (QgsRasterFileWriter,
QgsProcessingException,
QgsProcessingParameterRasterLayer,
QgsProcessingParameterNumber,
QgsProcessingParameterRasterDestination)
@@ -87,7 +88,11 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
out = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
arguments.append('-of')
arguments.append(QgsRasterFileWriter.driverForExtension(os.path.splitext(out)[1]))
arguments.append(self.parameterAsRasterLayer(parameters, self.INPUT, context).source())
raster = self.parameterAsRasterLayer(parameters, self.INPUT, context)
if raster is None:
raise QgsProcessingException(self.invalidRasterError(parameters, self.INPUT))

arguments.append(raster.source())
arguments.append(out)

if isWindows():
@@ -28,6 +28,7 @@
import os

from qgis.core import (QgsRasterFileWriter,
QgsProcessingException,
QgsProcessingParameterDefinition,
QgsProcessingParameterRasterLayer,
QgsProcessingParameterBand,
@@ -91,6 +92,9 @@ def commandName(self):
def getConsoleCommands(self, parameters, context, feedback, executing=True):
arguments = ['roughness']
inLayer = self.parameterAsRasterLayer(parameters, self.INPUT, context)
if inLayer is None:
raise QgsProcessingException(self.invalidRasterError(parameters, self.INPUT))

arguments.append(inLayer.source())

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

0 comments on commit f4599f1

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