QGIS/python/plugins/processing/algs/otb/OTBAlgorithmProvider.py

98 lines
4.0 KiB
Python
Raw Normal View History

2012-10-05 23:28:47 +02:00
# -*- coding: utf-8 -*-
"""
***************************************************************************
OTBAlgorithmProvider.py
---------------------
Date : August 2012
Copyright : (C) 2012 by Victor Olaya
2014-01-17 19:39:17 +01:00
(C) 2013 by CS Systemes d'information
2012-10-05 23:28:47 +02:00
Email : volayaf at gmail dot com
2014-01-17 19:39:17 +01:00
otb at c-s dot fr
Contributors : Victor Olaya
Julien Malik - Changing the way to load algorithms : loading from xml
Oscar Picas - Changing the way to load algorithms : loading from xml
2012-10-05 23:28:47 +02:00
***************************************************************************
* *
* 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__ = 'August 2012'
__copyright__ = '(C) 2012, Victor Olaya'
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'
2012-09-15 18:25:25 +03:00
import os
2014-01-17 19:39:17 +01:00
import PyQt4.QtGui
2013-08-12 20:44:27 +02:00
from processing.core.AlgorithmProvider import AlgorithmProvider
from processing.core.ProcessingConfig import ProcessingConfig, Setting
from OTBUtils import OTBUtils
from OTBAlgorithm import OTBAlgorithm
2014-01-17 19:39:17 +01:00
from processing.core.ProcessingLog import ProcessingLog
2012-09-15 18:25:25 +03:00
class OTBAlgorithmProvider(AlgorithmProvider):
def __init__(self):
AlgorithmProvider.__init__(self)
self.activate = True
2012-09-15 18:25:25 +03:00
self.createAlgsList()
2014-01-17 19:39:17 +01:00
2012-09-15 18:25:25 +03:00
def getDescription(self):
2014-01-17 19:39:17 +01:00
return "Orfeo Toolbox (Image analysis)"
2012-09-15 18:25:25 +03:00
def getName(self):
2014-01-17 19:39:17 +01:00
return "otb"
2012-09-15 18:25:25 +03:00
def getIcon(self):
return PyQt4.QtGui.QIcon(os.path.dirname(__file__) + "/../../images/otb.png")
2012-09-15 18:25:25 +03:00
def _loadAlgorithms(self):
self.algs = self.preloadedAlgs
def createAlgsList(self):
self.preloadedAlgs = []
folder = OTBUtils.otbDescriptionPath()
for descriptionFile in os.listdir(folder):
2014-01-17 19:39:17 +01:00
if descriptionFile.endswith("xml"):
2012-09-15 18:25:25 +03:00
try:
alg = OTBAlgorithm(os.path.join(folder, descriptionFile))
2014-04-06 12:27:51 +02:00
2014-01-17 19:39:17 +01:00
if alg.name.strip() != "":
2012-09-15 18:25:25 +03:00
self.preloadedAlgs.append(alg)
else:
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR,
self.tr("Could not open OTB algorithm: %s" % descriptionFile))
2014-01-17 19:39:17 +01:00
except Exception,e:
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR,
self.tr("Could not open OTB algorithm: %s" % descriptionFile))
2014-01-17 19:39:17 +01:00
2012-09-15 18:25:25 +03:00
def initializeSettings(self):
AlgorithmProvider.initializeSettings(self)
if OTBUtils.findOtbPath() is None:
ProcessingConfig.addSetting(Setting(self.getDescription(),
OTBUtils.OTB_FOLDER,
self.tr("OTB command line tools folder"), OTBUtils.otbPath()))
if OTBUtils.findOtbLibPath() is None:
ProcessingConfig.addSetting(Setting(self.getDescription(),
OTBUtils.OTB_LIB_FOLDER,
self.tr("OTB applications folder"), OTBUtils.otbLibPath()))
ProcessingConfig.addSetting(Setting(self.getDescription(),
OTBUtils.OTB_SRTM_FOLDER,
self.tr("SRTM tiles folder"), OTBUtils.otbSRTMPath()))
ProcessingConfig.addSetting(Setting(self.getDescription(),
OTBUtils.OTB_GEOID_FILE,
self.tr("Geoid file"), OTBUtils.otbGeoidPath()))
2012-09-15 18:25:25 +03:00
def unload(self):
AlgorithmProvider.unload(self)
2013-08-12 20:44:27 +02:00
ProcessingConfig.removeSetting(OTBUtils.OTB_FOLDER)
ProcessingConfig.removeSetting(OTBUtils.OTB_LIB_FOLDER)