本文整理汇总了Python中processing.script.ScriptAlgorithm.ScriptAlgorithm.initAlgorithm方法的典型用法代码示例。如果您正苦于以下问题:Python ScriptAlgorithm.initAlgorithm方法的具体用法?Python ScriptAlgorithm.initAlgorithm怎么用?Python ScriptAlgorithm.initAlgorithm使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类processing.script.ScriptAlgorithm.ScriptAlgorithm
的用法示例。
在下文中一共展示了ScriptAlgorithm.initAlgorithm方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: check_algorithm
# 需要导入模块: from processing.script.ScriptAlgorithm import ScriptAlgorithm [as 别名]
# 或者: from processing.script.ScriptAlgorithm.ScriptAlgorithm import initAlgorithm [as 别名]
def check_algorithm(self, name, defs):
"""
Will run an algorithm definition and check if it generates the expected result
:param name: The identifier name used in the test output heading
:param defs: A python dict containing a test algorithm definition
"""
self.vector_layer_params = {}
QgsProject.instance().removeAllMapLayers()
params = self.load_params(defs['params'])
if defs['algorithm'].startswith('script:'):
filePath = os.path.join(processingTestDataPath(), 'scripts', '{}.py'.format(defs['algorithm'][len('script:'):]))
alg = ScriptAlgorithm(filePath)
alg.initAlgorithm()
else:
print('Running alg: "{}"'.format(defs['algorithm']))
alg = QgsApplication.processingRegistry().createAlgorithmById(defs['algorithm'])
parameters = {}
if isinstance(params, list):
for param in zip(alg.parameterDefinitions(), params):
parameters[param[0].name()] = param[1]
else:
for k, p in list(params.items()):
parameters[k] = p
for r, p in list(defs['results'].items()):
if not 'in_place_result' in p or not p['in_place_result']:
parameters[r] = self.load_result_param(p)
expectFailure = False
if 'expectedFailure' in defs:
exec(('\n'.join(defs['expectedFailure'][:-1])), globals(), locals())
expectFailure = eval(defs['expectedFailure'][-1])
# ignore user setting for invalid geometry handling
context = QgsProcessingContext()
context.setProject(QgsProject.instance())
if 'skipInvalid' in defs and defs['skipInvalid']:
context.setInvalidGeometryCheck(QgsFeatureRequest.GeometrySkipInvalid)
feedback = QgsProcessingFeedback()
if expectFailure:
try:
results, ok = alg.run(parameters, context, feedback)
self.check_results(results, context, defs['params'], defs['results'])
if ok:
raise _UnexpectedSuccess
except Exception:
pass
else:
results, ok = alg.run(parameters, context, feedback)
self.assertTrue(ok, 'params: {}, results: {}'.format(parameters, results))
self.check_results(results, context, defs['params'], defs['results'])