mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-27 00:33:48 -05:00
[processing] Fix exception when clicking help for GDAL algorithms
This commit is contained in:
parent
280018dc5f
commit
b3288192ee
@ -73,6 +73,9 @@ class AssignProjection(GdalAlgorithm):
|
||||
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()
|
||||
|
@ -119,6 +119,9 @@ class ClipRasterByMask(GdalAlgorithm):
|
||||
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)
|
||||
|
||||
@ -159,4 +162,4 @@ class ClipRasterByMask(GdalAlgorithm):
|
||||
arguments.append(inLayer.source())
|
||||
arguments.append(out)
|
||||
|
||||
return ['gdalwarp', GdalUtils.escapeAndJoin(arguments)]
|
||||
return [self.commandName(), GdalUtils.escapeAndJoin(arguments)]
|
||||
|
@ -96,6 +96,9 @@ class ColorRelief(GdalAlgorithm):
|
||||
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)
|
||||
@ -116,4 +119,4 @@ class ColorRelief(GdalAlgorithm):
|
||||
|
||||
arguments.append(self.modes[self.parameterAsEnum(parameters, self.MATCH_MODE, context)][1])
|
||||
|
||||
return ['gdaldem', GdalUtils.escapeAndJoin(arguments)]
|
||||
return [self.commandName(), GdalUtils.escapeAndJoin(arguments)]
|
||||
|
@ -32,7 +32,9 @@ from qgis.PyQt.QtCore import QUrl, QCoreApplication
|
||||
|
||||
from qgis.core import (QgsApplication,
|
||||
QgsVectorFileWriter,
|
||||
QgsProcessingAlgorithm)
|
||||
QgsProcessingAlgorithm,
|
||||
QgsProcessingContext,
|
||||
QgsProcessingFeedback)
|
||||
|
||||
from processing.algs.gdal.GdalAlgorithmDialog import GdalAlgorithmDialog
|
||||
from processing.algs.gdal.GdalUtils import GdalUtils
|
||||
@ -136,11 +138,11 @@ class GdalAlgorithm(QgsProcessingAlgorithm):
|
||||
|
||||
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
|
||||
|
@ -96,6 +96,9 @@ class aspect(GdalAlgorithm):
|
||||
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)
|
||||
@ -127,4 +130,4 @@ class aspect(GdalAlgorithm):
|
||||
if options:
|
||||
arguments.extend(GdalUtils.parseCreationOptions(options))
|
||||
|
||||
return ['gdaldem', GdalUtils.escapeAndJoin(arguments)]
|
||||
return [self.commandName(), GdalUtils.escapeAndJoin(arguments)]
|
||||
|
@ -121,6 +121,9 @@ class contour(GdalAlgorithm):
|
||||
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)
|
||||
@ -159,4 +162,4 @@ class contour(GdalAlgorithm):
|
||||
arguments.append(inLayer.source())
|
||||
arguments.append(output)
|
||||
|
||||
return ['gdal_contour', GdalUtils.escapeAndJoin(arguments)]
|
||||
return [self.commandName(), GdalUtils.escapeAndJoin(arguments)]
|
||||
|
@ -89,6 +89,9 @@ class fillnodata(GdalAlgorithm):
|
||||
def groupId(self):
|
||||
return 'rasteranalysis'
|
||||
|
||||
def commandName(self):
|
||||
return 'gdal_fillnodata'
|
||||
|
||||
def getConsoleCommands(self, parameters, context, feedback, executing=True):
|
||||
arguments = []
|
||||
arguments.append('-md')
|
||||
|
@ -154,6 +154,9 @@ class gdal2tiles(GdalAlgorithm):
|
||||
def groupId(self):
|
||||
return 'rastermiscellaneous'
|
||||
|
||||
def commandName(self):
|
||||
return 'gdal2tiles'
|
||||
|
||||
def getConsoleCommands(self, parameters, context, feedback, executing=True):
|
||||
arguments = []
|
||||
|
||||
|
@ -71,8 +71,10 @@ class gdal2xyz(GdalAlgorithm):
|
||||
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)))
|
||||
|
@ -105,6 +105,9 @@ class gdaladdo(GdalAlgorithm):
|
||||
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()
|
||||
@ -128,4 +131,4 @@ class gdaladdo(GdalAlgorithm):
|
||||
|
||||
self.setOutputValue(self.OUTPUT, fileName)
|
||||
|
||||
return ['gdaladdo', GdalUtils.escapeAndJoin(arguments)]
|
||||
return [self.commandName(), GdalUtils.escapeAndJoin(arguments)]
|
||||
|
@ -84,6 +84,9 @@ class gdalinfo(GdalAlgorithm):
|
||||
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):
|
||||
@ -95,7 +98,7 @@ class gdalinfo(GdalAlgorithm):
|
||||
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)
|
||||
|
@ -117,6 +117,9 @@ class gdaltindex(GdalAlgorithm):
|
||||
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)
|
||||
@ -158,4 +161,4 @@ class gdaltindex(GdalAlgorithm):
|
||||
arguments.append(output)
|
||||
arguments.append(' '.join(layers))
|
||||
|
||||
return ['gdaltindex', GdalUtils.escapeAndJoin(arguments)]
|
||||
return [self.commandName(), GdalUtils.escapeAndJoin(arguments)]
|
||||
|
@ -123,6 +123,9 @@ class hillshade(GdalAlgorithm):
|
||||
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)
|
||||
@ -162,4 +165,4 @@ class hillshade(GdalAlgorithm):
|
||||
if options:
|
||||
arguments.extend(GdalUtils.parseCreationOptions(options))
|
||||
|
||||
return ['gdaldem', GdalUtils.escapeAndJoin(arguments)]
|
||||
return [self.commandName(), GdalUtils.escapeAndJoin(arguments)]
|
||||
|
@ -92,6 +92,9 @@ class nearblack(GdalAlgorithm):
|
||||
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)
|
||||
|
||||
@ -114,4 +117,4 @@ class nearblack(GdalAlgorithm):
|
||||
if options:
|
||||
arguments.extend(GdalUtils.parseCreationOptions(options))
|
||||
|
||||
return ['nearblack', GdalUtils.escapeAndJoin(arguments)]
|
||||
return [self.commandName(), GdalUtils.escapeAndJoin(arguments)]
|
||||
|
@ -69,9 +69,11 @@ class ogrinfo(GdalAlgorithm):
|
||||
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')
|
||||
|
@ -77,6 +77,9 @@ class pct2rgb(GdalAlgorithm):
|
||||
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)
|
||||
|
@ -85,6 +85,9 @@ class polygonize(GdalAlgorithm):
|
||||
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)
|
||||
|
@ -131,6 +131,9 @@ class proximity(GdalAlgorithm):
|
||||
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)
|
||||
|
@ -76,6 +76,9 @@ class rgb2pct(GdalAlgorithm):
|
||||
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')
|
||||
|
@ -85,6 +85,9 @@ class roughness(GdalAlgorithm):
|
||||
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)
|
||||
@ -107,4 +110,4 @@ class roughness(GdalAlgorithm):
|
||||
arguments.append('-co')
|
||||
arguments.append(options)
|
||||
|
||||
return ['gdaldem', GdalUtils.escapeAndJoin(arguments)]
|
||||
return [self.commandName(), GdalUtils.escapeAndJoin(arguments)]
|
||||
|
@ -87,6 +87,9 @@ class sieve(GdalAlgorithm):
|
||||
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')
|
||||
|
@ -100,6 +100,9 @@ class slope(GdalAlgorithm):
|
||||
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)
|
||||
@ -131,4 +134,4 @@ class slope(GdalAlgorithm):
|
||||
if options:
|
||||
arguments.extend(GdalUtils.parseCreationOptions(options))
|
||||
|
||||
return ['gdaldem', GdalUtils.escapeAndJoin(arguments)]
|
||||
return [self.commandName(), GdalUtils.escapeAndJoin(arguments)]
|
||||
|
@ -84,6 +84,9 @@ class tpi(GdalAlgorithm):
|
||||
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)
|
||||
@ -101,4 +104,4 @@ class tpi(GdalAlgorithm):
|
||||
if options:
|
||||
arguments.extend(GdalUtils.parseCreationOptions(options))
|
||||
|
||||
return ['gdaldem', GdalUtils.escapeAndJoin(arguments)]
|
||||
return [self.commandName(), GdalUtils.escapeAndJoin(arguments)]
|
||||
|
@ -110,6 +110,9 @@ class translate(GdalAlgorithm):
|
||||
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)
|
||||
@ -145,4 +148,4 @@ class translate(GdalAlgorithm):
|
||||
arguments.append(inLayer.source())
|
||||
arguments.append(out)
|
||||
|
||||
return ['gdal_translate', GdalUtils.escapeAndJoin(arguments)]
|
||||
return [self.commandName(), GdalUtils.escapeAndJoin(arguments)]
|
||||
|
@ -83,6 +83,9 @@ class tri(GdalAlgorithm):
|
||||
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)
|
||||
@ -100,4 +103,4 @@ class tri(GdalAlgorithm):
|
||||
if options:
|
||||
arguments.extend(GdalUtils.parseCreationOptions(options))
|
||||
|
||||
return ['gdaldem', GdalUtils.escapeAndJoin(arguments)]
|
||||
return [self.commandName(), GdalUtils.escapeAndJoin(arguments)]
|
||||
|
@ -158,6 +158,9 @@ class warp(GdalAlgorithm):
|
||||
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)
|
||||
@ -217,4 +220,4 @@ class warp(GdalAlgorithm):
|
||||
arguments.append(inLayer.source())
|
||||
arguments.append(out)
|
||||
|
||||
return ['gdalwarp', GdalUtils.escapeAndJoin(arguments)]
|
||||
return [self.commandName(), GdalUtils.escapeAndJoin(arguments)]
|
||||
|
@ -50,8 +50,10 @@ from qgis.core import (QgsVectorLayer,
|
||||
QgsProcessingContext,
|
||||
QgsProcessingUtils,
|
||||
QgsProcessingFeedback)
|
||||
|
||||
from qgis.testing import _UnexpectedSuccess
|
||||
from qgis.analysis import (QgsNativeAlgorithms)
|
||||
from qgis.testing import (_UnexpectedSuccess,
|
||||
start_app,
|
||||
unittest)
|
||||
from utilities import unitTestDataPath
|
||||
|
||||
import processing
|
||||
@ -316,5 +318,37 @@ class AlgorithmsTest(object):
|
||||
self.assertRegex(data, rule)
|
||||
|
||||
|
||||
class GenericAlgorithmsTest(unittest.TestCase):
|
||||
"""
|
||||
General (non-provider specific) algorithm tests
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
start_app()
|
||||
from processing.core.Processing import Processing
|
||||
Processing.initialize()
|
||||
QgsApplication.processingRegistry().addProvider(QgsNativeAlgorithms())
|
||||
cls.cleanup_paths = []
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
from processing.core.Processing import Processing
|
||||
Processing.deinitialize()
|
||||
for path in cls.cleanup_paths:
|
||||
shutil.rmtree(path)
|
||||
|
||||
def testAlgorithmCompliance(self):
|
||||
for p in QgsApplication.processingRegistry().providers():
|
||||
print('testing provider {}'.format(p.id()))
|
||||
for a in p.algorithms():
|
||||
print('testing algorithm {}'.format(a.id()))
|
||||
self.check_algorithm(a)
|
||||
|
||||
def check_algorithm(self, alg):
|
||||
# check that calling helpUrl() works without error
|
||||
alg.helpUrl()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
nose2.main()
|
||||
|
@ -9,6 +9,7 @@ IF(ENABLE_TESTS)
|
||||
ADD_PYTHON_TEST(ProcessingGuiTest GuiTest.py)
|
||||
ADD_PYTHON_TEST(ProcessingModelerTest ModelerTest.py)
|
||||
ADD_PYTHON_TEST(ProcessingToolsTest ToolsTest.py)
|
||||
ADD_PYTHON_TEST(ProcessingGenericAlgorithmsTest AlgorithmsTestBase.py)
|
||||
ADD_PYTHON_TEST(ProcessingQgisAlgorithmsTest QgisAlgorithmsTest.py)
|
||||
ADD_PYTHON_TEST(ProcessingGdalAlgorithmsTest GdalAlgorithmsTest.py)
|
||||
ADD_PYTHON_TEST(ProcessingGrass7AlgorithmsImageryTest Grass7AlgorithmsImageryTest.py)
|
||||
|
@ -69,6 +69,12 @@ class TestGdalAlgorithms(unittest.TestCase, AlgorithmsTestBase.AlgorithmsTest):
|
||||
def test_definition_file(self):
|
||||
return 'gdal_algorithm_tests.yaml'
|
||||
|
||||
def testCommandName(self):
|
||||
# Test that algorithms report a valid commandName
|
||||
p = QgsApplication.processingRegistry().providerById('gdal')
|
||||
for a in p.algorithms():
|
||||
self.assertTrue(a.commandName(), 'Algorithm {} has no commandName!'.format(a.id()))
|
||||
|
||||
def testGetOgrCompatibleSourceFromMemoryLayer(self):
|
||||
# create a memory layer and add to project and context
|
||||
layer = QgsVectorLayer("Point?field=fldtxt:string&field=fldint:integer",
|
||||
|
Loading…
x
Reference in New Issue
Block a user