QGIS/python/plugins/processing/algs/taudem/TauDEMAlgorithmProvider.py

121 lines
4.8 KiB
Python
Raw Normal View History

2012-10-20 17:15:42 +03:00
# -*- coding: utf-8 -*-
"""
***************************************************************************
TauDEMAlgorithmProvider.py
---------------------
Date : October 2012
Copyright : (C) 2012 by Alexander Bruy
Email : alexander dot bruy 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. *
* *
***************************************************************************
"""
2016-09-21 18:24:26 +02:00
from builtins import str
2012-10-20 17:15:42 +03:00
__author__ = 'Alexander Bruy'
__date__ = 'October 2012'
__copyright__ = '(C) 2012, Alexander Bruy'
2012-10-20 17:15:42 +03:00
# This will get replaced with a git SHA1 when you do a git archive
2012-10-20 17:15:42 +03:00
__revision__ = '$Format:%H$'
import os
2016-04-22 10:38:48 +02:00
from qgis.PyQt.QtGui import QIcon
2012-10-20 17:15:42 +03:00
2013-08-12 20:44:27 +02:00
from processing.core.AlgorithmProvider import AlgorithmProvider
from processing.core.ProcessingConfig import ProcessingConfig, Setting
2013-08-12 20:44:27 +02:00
from processing.core.ProcessingLog import ProcessingLog
from .TauDEMAlgorithm import TauDEMAlgorithm
from .TauDEMUtils import TauDEMUtils
from .peukerdouglas import PeukerDouglas
from .slopearea import SlopeArea
from .lengtharea import LengthArea
from .dropanalysis import DropAnalysis
from .dinfdistdown import DinfDistDown
from .dinfdistup import DinfDistUp
from .gridnet import GridNet
from .dinftranslimaccum import DinfTransLimAccum
from .dinftranslimaccum2 import DinfTransLimAccum2
pluginPath = os.path.normpath(os.path.join(
os.path.split(os.path.dirname(__file__))[0], os.pardir))
2012-10-20 17:15:42 +03:00
class TauDEMAlgorithmProvider(AlgorithmProvider):
def __init__(self):
AlgorithmProvider.__init__(self)
2012-11-13 15:32:59 +02:00
self.activate = False
2012-10-20 17:15:42 +03:00
def getDescription(self):
return self.tr('TauDEM (hydrologic analysis)')
2012-10-20 17:15:42 +03:00
def getName(self):
return 'taudem'
2012-10-20 17:15:42 +03:00
def getIcon(self):
return QIcon(os.path.join(pluginPath, 'images', 'taudem.svg'))
2012-10-20 17:15:42 +03:00
def initializeSettings(self):
AlgorithmProvider.initializeSettings(self)
ProcessingConfig.addSetting(Setting(self.getDescription(),
TauDEMUtils.TAUDEM_FOLDER,
self.tr('TauDEM command line tools folder'),
TauDEMUtils.taudemPath(), valuetype=Setting.FOLDER))
ProcessingConfig.addSetting(Setting(self.getDescription(),
TauDEMUtils.MPIEXEC_FOLDER,
self.tr('MPICH2/OpenMPI bin directory'),
TauDEMUtils.mpiexecPath(), valuetype=Setting.FOLDER))
ProcessingConfig.addSetting(Setting(self.getDescription(),
TauDEMUtils.MPI_PROCESSES,
self.tr('Number of MPI parallel processes to use'), 2))
2012-10-20 17:15:42 +03:00
def unload(self):
AlgorithmProvider.unload(self)
2013-08-12 20:44:27 +02:00
ProcessingConfig.removeSetting(TauDEMUtils.TAUDEM_FOLDER)
ProcessingConfig.removeSetting(TauDEMUtils.MPIEXEC_FOLDER)
ProcessingConfig.removeSetting(TauDEMUtils.MPI_PROCESSES)
2012-10-20 17:15:42 +03:00
def _loadAlgorithms(self):
self.algs = []
folder = TauDEMUtils.taudemDescriptionPath()
for descriptionFile in os.listdir(folder):
if descriptionFile.endswith('txt'):
descriptionFile = os.path.join(folder, descriptionFile)
self._algFromDescription(descriptionFile)
self.algs.append(PeukerDouglas())
self.algs.append(SlopeArea())
self.algs.append(LengthArea())
self.algs.append(DropAnalysis())
self.algs.append(DinfDistDown())
self.algs.append(DinfDistUp())
self.algs.append(GridNet())
self.algs.append(DinfTransLimAccum())
self.algs.append(DinfTransLimAccum2())
def _algFromDescription(self, descriptionFile, multifile=False):
try:
alg = TauDEMAlgorithm(descriptionFile)
if alg.name.strip() != '':
self.algs.append(alg)
else:
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR,
self.tr('Could not open TauDEM algorithm: {}'.format(descriptionFile)))
except Exception as e:
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR,
2016-09-21 18:24:26 +02:00
self.tr('Could not open TauDEM algorithm {}:\n{}'.format(descriptionFile, str(e))))