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
|
2014-04-17 01:41:25 +02:00
|
|
|
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)
|
2013-04-21 15:12:53 +02:00
|
|
|
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):
|
2014-04-17 01:41:25 +02:00
|
|
|
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:
|
2015-01-16 15:56:05 +02:00
|
|
|
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR,
|
|
|
|
self.tr("Could not open OTB algorithm: %s" % descriptionFile))
|
fix python pep8 warnings and fix some revealed errors
pep8 --ignore=E111,E128,E201,E202,E203,E211,E221,E222,E225,E226,E227,E231,E241,E261,E265,E272,E302,E303,E501,E701 \
--exclude="ui_*.py,debian/*,python/ext-libs/*" \
.
2015-02-01 14:15:42 +01:00
|
|
|
except Exception, e:
|
2015-01-16 15:56:05 +02:00
|
|
|
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)
|
2014-06-12 10:55:54 +02:00
|
|
|
if OTBUtils.findOtbPath() is None:
|
2015-01-16 15:56:05 +02:00
|
|
|
ProcessingConfig.addSetting(Setting(self.getDescription(),
|
|
|
|
OTBUtils.OTB_FOLDER,
|
|
|
|
self.tr("OTB command line tools folder"), OTBUtils.otbPath()))
|
2014-06-18 23:59:46 +02:00
|
|
|
if OTBUtils.findOtbLibPath() is None:
|
2015-01-16 15:56:05 +02:00
|
|
|
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)
|