2016-04-06 10:50:54 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
"""
|
|
|
|
***************************************************************************
|
2016-04-07 13:21:23 +02:00
|
|
|
PreconfiguredAlgorithm.py
|
2016-04-06 10:50:54 +02:00
|
|
|
---------------------
|
|
|
|
Date : April 2016
|
|
|
|
Copyright : (C) 2016 by Victor Olaya
|
|
|
|
Email : volayaf at gmail dot com
|
|
|
|
***************************************************************************
|
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
|
|
* (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
***************************************************************************
|
|
|
|
"""
|
|
|
|
|
|
|
|
__author__ = 'Victor Olaya'
|
|
|
|
__date__ = 'April 2016'
|
|
|
|
__copyright__ = '(C) 2016, Victor Olaya'
|
|
|
|
|
|
|
|
# This will get replaced with a git SHA1 when you do a git archive
|
|
|
|
|
|
|
|
__revision__ = '$Format:%H$'
|
|
|
|
|
|
|
|
|
|
|
|
import os
|
2017-04-04 11:04:36 +10:00
|
|
|
from qgis.core import (QgsProcessingAlgorithm,
|
|
|
|
QgsApplication)
|
2016-04-06 10:50:54 +02:00
|
|
|
from processing.core.GeoAlgorithm import GeoAlgorithm
|
|
|
|
import json
|
|
|
|
|
2016-04-07 14:10:25 +02:00
|
|
|
|
2016-04-06 10:50:54 +02:00
|
|
|
class PreconfiguredAlgorithm(GeoAlgorithm):
|
|
|
|
|
|
|
|
def __init__(self, descriptionFile):
|
|
|
|
self.descriptionFile = descriptionFile
|
|
|
|
with open(self.descriptionFile) as f:
|
|
|
|
self.description = json.load(f)
|
|
|
|
GeoAlgorithm.__init__(self)
|
2017-05-15 13:40:38 +10:00
|
|
|
|
|
|
|
self._name = self.description["name"]
|
|
|
|
self._group = self.description["group"]
|
2017-03-29 12:04:09 +10:00
|
|
|
|
|
|
|
def group(self):
|
|
|
|
return self._group
|
2016-04-06 10:50:54 +02:00
|
|
|
|
2017-04-03 21:20:56 +10:00
|
|
|
def displayName(self):
|
|
|
|
return self._name
|
|
|
|
|
|
|
|
def name(self):
|
|
|
|
return os.path.splitext(os.path.basename(self.descriptionFile))[0].lower()
|
|
|
|
|
2017-03-29 15:00:20 +10:00
|
|
|
def flags(self):
|
|
|
|
return QgsProcessingAlgorithm.FlagHideFromModeler
|
|
|
|
|
2017-04-25 14:55:38 +10:00
|
|
|
def execute(self, context=None, feedback=None, model=None):
|
2017-05-19 10:24:59 +10:00
|
|
|
self.alg = QgsApplication.processingRegistry().algorithmById(self.description["algname"])
|
2016-09-27 19:51:06 +02:00
|
|
|
for name, value in list(self.description["parameters"].items()):
|
2016-04-06 10:50:54 +02:00
|
|
|
self.alg.setParameterValue(name, value)
|
2016-09-27 19:51:06 +02:00
|
|
|
for name, value in list(self.description["outputs"].items()):
|
2016-04-06 10:50:54 +02:00
|
|
|
self.alg.setOutputValue(name, value)
|
2017-01-06 20:04:00 +10:00
|
|
|
self.alg.execute(feedback)
|
2016-04-07 13:21:23 +02:00
|
|
|
self.outputs = self.alg.outputs
|