Commit 57fb661d authored by Rashad Kanavath's avatar Rashad Kanavath
Browse files

prepare for pull request to upstream

Add OTB_MAX_RAM_HINT and OTB_LOGGER_LEVEL issue #22. Other variables
seems not relevant to include in QGIS Processing provider settings

ram parameter is not added by default into all applications. It is now
controlled by config settings which btw ignore default value 128.

A "special" cli script is written to run otb application in all cases.
v0.1 uses custom script only for binary packages.

Config keys are moved a simply class OTBSettings which seems more
approriate for naming
parent b98fda42
...@@ -175,14 +175,6 @@ class OTBAlgorithm(QgsProcessingAlgorithm): ...@@ -175,14 +175,6 @@ class OTBAlgorithm(QgsProcessingAlgorithm):
#parameter is added now and we must move to next line #parameter is added now and we must move to next line
line = lines.readline().strip('\n').strip() line = lines.readline().strip('\n').strip()
#*QgsProcessingParameterNumber|ram||QgsProcessingParameterNumber.Integer|128|False
ramParameter = QgsProcessingParameterNumber('ram', 'Available RAM (Mb)', QgsProcessingParameterNumber.Integer, 128)
ramParameter.setFlags(QgsProcessingParameterDefinition.FlagAdvanced | QgsProcessingParameterDefinition.FlagOptional)
metadata = ramParameter.metadata()
metadata['ram_value_default'] = True
ramParameter.setMetadata(metadata)
self.addParameter(ramParameter)
except BaseException as e: except BaseException as e:
import traceback import traceback
errmsg = "Could not open OTB algorithm from file: \n" + self._descriptionfile + "\nline=" + line + "\nError:\n" + traceback.format_exc() errmsg = "Could not open OTB algorithm from file: \n" + self._descriptionfile + "\nline=" + line + "\nError:\n" + traceback.format_exc()
...@@ -202,11 +194,6 @@ class OTBAlgorithm(QgsProcessingAlgorithm): ...@@ -202,11 +194,6 @@ class OTBAlgorithm(QgsProcessingAlgorithm):
#it is considered valid if it has value other than float #it is considered valid if it has value other than float
if k == 'outputpixeltype' and self.pixelTypes[int(v)] == 'float': if k == 'outputpixeltype' and self.pixelTypes[int(v)] == 'float':
continue continue
#if a parameter has metadata key 'ram_value_default',
#It is considered valid if it hold a value other than 128 (default)
if 'ram_value_default' in param.metadata() and int(v) == 128.0:
continue
# Any other valid parameters have: # Any other valid parameters have:
#- empty or no metadata #- empty or no metadata
#- metadata without a 'group_key' #- metadata without a 'group_key'
...@@ -239,7 +226,7 @@ class OTBAlgorithm(QgsProcessingAlgorithm): ...@@ -239,7 +226,7 @@ class OTBAlgorithm(QgsProcessingAlgorithm):
def processAlgorithm(self, parameters, context, feedback): def processAlgorithm(self, parameters, context, feedback):
output_key = self.outputParameterName() output_key = self.outputParameterName()
otb_cli_file = OTBUtils.OTB_CLI_FILE otb_cli_file = OTBUtils.cliPath()
command = '"{}" {} {}'.format(otb_cli_file, self.name(), OTBUtils.appFolder()) command = '"{}" {} {}'.format(otb_cli_file, self.name(), OTBUtils.appFolder())
for k, v in parameters.items(): for k, v in parameters.items():
if k == 'outputpixeltype' or not v: if k == 'outputpixeltype' or not v:
......
...@@ -37,6 +37,7 @@ from qgis import utils ...@@ -37,6 +37,7 @@ from qgis import utils
from processing.core.ProcessingConfig import ProcessingConfig, Setting from processing.core.ProcessingConfig import ProcessingConfig, Setting
from otb import OTBUtils from otb import OTBUtils
from otb.OTBSettings import OTBSettings
from otb.OTBAlgorithm import OTBAlgorithm from otb.OTBAlgorithm import OTBAlgorithm
def otb_exe_file(f): def otb_exe_file(f):
...@@ -53,163 +54,56 @@ class OTBAlgorithmProvider(QgsProcessingProvider): ...@@ -53,163 +54,56 @@ class OTBAlgorithmProvider(QgsProcessingProvider):
self.version = '6.6.0' self.version = '6.6.0'
self.descriptionFile = '' self.descriptionFile = ''
def canBeActivated(self):
if not self.isActive():
return False
folder = OTBUtils.otbFolder()
if folder and os.path.exists(folder):
if os.path.isfile(self.algsFile(folder)):
return True
utils.iface.messageBar().pushWarning("OTB", "Cannot find '{}'. OTB provider will be disabled".format(self.algsFile(folder)))
self.setActive(False)
return False
def check_app_folder(self, v):
if not self.isActive():
return
if not v:
self.setActive(False)
raise ValueError(self.tr('Cannot activate OTB provider'))
folder = OTBUtils.otbFolder()
otb_app_dirs = self.otb_app_dir_list(v)
if len(otb_app_dirs) < 1:
self.setActive(False)
raise ValueError(self.tr("'{}' does not exist. OTB provider will be disabled".format(v)))
#isValid is True if there is atleast one valid otb application is given path
isValid = False
descr_folder = self.descrFolder(folder)
for app_dir in otb_app_dirs:
if not os.path.exists(app_dir):
continue
for otb_app in os.listdir(app_dir):
if not otb_app.startswith('otbapp_') or \
'TestApplication' in otb_app or \
'ApplicationExample' in otb_app:
continue
app_name = os.path.basename(otb_app).split('.')[0][7:]
dfile = os.path.join(descr_folder, app_name + '.txt')
isValid = True
if not os.path.exists(dfile):
cmdlist = [os.path.join(
folder, 'bin',
otb_exe_file('otbQgisDescriptor')),
app_name, app_dir, descr_folder + '/']
commands = ' '.join(cmdlist)
QgsMessageLog.logMessage(self.tr(commands), self.tr('Processing'), Qgis.Critical)
OTBUtils.executeOtb(commands, feedback=None)
if isValid:
utils.iface.messageBar().pushInfo("OTB", "OTB provider is activated from '{}'.".format(folder))
else:
self.setActive(False)
raise ValueError(self.tr("No OTB algorithms found in '{}'. OTB will be disabled".format(','.join(otb_app_dirs))))
def normalize_path(self, p):
# https://stackoverflow.com/a/20713238/1003090
return os.path.normpath(os.sep.join(re.split(r'\\|/', p)))
def check_otb_folder(self, v):
if not self.isActive():
return
if not v or not os.path.exists(v):
self.setActive(False)
raise ValueError(self.tr("'{}' does not exist. OTB provider will be disabled".format(v)))
path = self.normalize_path(v)
if not os.path.exists(os.path.join(path, 'bin', otb_exe_file('otbApplicationLauncherCommandLine'))):
self.setActive(False)
raise ValueError(self.tr("Cannot find '{}'. OTB will be disabled".format(os.path.join(v, 'bin', otb_exe_file('otbApplicationLauncherCommandLine')))))
def write_otbcli_wrapper_script(self):
otb_folder = self.normalize_path(OTBUtils.otbFolder())
otb_app_path_env = os.pathsep.join(self.otb_app_dir_list(OTBUtils.appFolder()))
gdal_data_dir = None
geotiff_csv_dir = None
try:
if os.name == 'nt':
app_vargs = " %*"
export_cmd = 'SET '
first_line = ':: Setup environment for OTB package. Generated by QGIS plugin'
otb_app_launcher = os.path.join(otb_folder, 'bin', 'otbApplicationLauncherCommandLine.exe')
gdal_data_dir = os.path.join(otb_folder, 'share', 'data')
geotiff_csv_dir = os.path.join(otb_folder, 'share', 'epsg_csv')
else:
app_vargs = " $@"
export_cmd = 'export '
first_line = '#!/bin/sh'
otb_app_launcher = os.path.join(otb_folder, 'bin', 'otbApplicationLauncherCommandLine')
lines = None
env_profile = os.path.join(otb_folder, 'otbenv.profile')
with open(env_profile) as f:
lines = f.readlines()
lines = [x.strip() for x in lines]
for line in lines:
if not line or line.startswith('#'):
continue
if 'GDAL_DATA=' in line:
gdal_data_dir = line.split("GDAL_DATA=")[1]
if 'GEOTIFF_CSV='in line:
geotiff_csv_dir = line.split("GEOTIFF_CSV=")[1]
with open(OTBUtils.OTB_CLI_FILE, 'w') as otb_cli_file:
otb_cli_file.write(first_line + os.linesep)
otb_cli_file.write(export_cmd + "LC_NUMERIC=C" + os.linesep)
otb_cli_file.write(export_cmd + "GDAL_DRIVER_PATH=disable" + os.linesep)
otb_cli_file.write(export_cmd + "\"GDAL_DATA=" + gdal_data_dir + "\"" + os.linesep)
otb_cli_file.write(export_cmd + "\"GEOTIFF_CSV=" + geotiff_csv_dir + "\"" + os.linesep)
otb_cli_file.write(export_cmd + "\"OTB_APPLICATION_PATH=" + otb_app_path_env + "\"" + os.linesep)
otb_cli_file.write("\"" + otb_app_launcher + "\"" + app_vargs + os.linesep)
if not os.name == 'nt':
os.chmod(OTBUtils.OTB_CLI_FILE, 0o744)
except BaseException as e:
import traceback
os.remove(OTBUtils.OTB_CLI_FILE)
errmsg = "Cannot write:" + OTBUtils.OTB_CLI_FILE + "\nError:\n" + traceback.format_exc()
QgsMessageLog.logMessage(self.tr(errmsg), self.tr('Processing'), Qgis.Critical)
raise e
def load(self): def load(self):
group = self.name() group = self.name()
ProcessingConfig.settingIcons[group] = self.icon() ProcessingConfig.settingIcons[group] = self.icon()
ProcessingConfig.addSetting(Setting(group, OTBUtils.ACTIVATE, self.tr('Activate'), True)) ProcessingConfig.addSetting(Setting(group, OTBSettings.ACTIVATE, self.tr('Activate'), True))
ProcessingConfig.addSetting(Setting(group, OTBUtils.FOLDER, ProcessingConfig.addSetting(Setting(group, OTBSettings.FOLDER,
self.tr("OTB folder"), self.tr("OTB folder"),
OTBUtils.otbFolder(), OTBUtils.otbFolder(),
valuetype=Setting.FOLDER, valuetype=Setting.FOLDER,
validator=self.check_otb_folder validator=self.validateOtbFolder
)) ))
ProcessingConfig.addSetting(Setting(group, OTBUtils.APP_FOLDER, ProcessingConfig.addSetting(Setting(group, OTBSettings.APP_FOLDER,
self.tr("OTB application folder"), self.tr("OTB application folder"),
OTBUtils.appFolder(), OTBUtils.appFolder(),
valuetype=Setting.MULTIPLE_FOLDERS, valuetype=Setting.MULTIPLE_FOLDERS,
validator=self.check_app_folder validator=self.validateAppFolders
)) ))
ProcessingConfig.addSetting(Setting(group, OTBUtils.SRTM_FOLDER, ProcessingConfig.addSetting(Setting(group, OTBSettings.SRTM_FOLDER,
self.tr("SRTM tiles folder"), self.tr("SRTM tiles folder"),
OTBUtils.srtmFolder(), OTBUtils.srtmFolder(),
valuetype=Setting.FOLDER valuetype=Setting.FOLDER
)) ))
ProcessingConfig.addSetting(Setting(group, OTBUtils.GEOID_FILE, ProcessingConfig.addSetting(Setting(group, OTBSettings.GEOID_FILE,
self.tr("Geoid file"), self.tr("Geoid file"),
OTBUtils.geoidFile(), OTBUtils.geoidFile(),
valuetype=Setting.FOLDER valuetype=Setting.FOLDER
)) ))
ProcessingConfig.addSetting(Setting(group, OTBSettings.MAX_RAM_HINT,
self.tr("Maximum RAM to use"),
OTBUtils.maxRAMHint(),
valuetype=Setting.STRING
))
ProcessingConfig.addSetting(Setting(group, OTBSettings.LOGGER_LEVEL,
self.tr("Logger level"),
OTBUtils.loggerLevel(),
valuetype=Setting.STRING,
validator=self.validateLoggerLevel
))
ProcessingConfig.readSettings() ProcessingConfig.readSettings()
self.refreshAlgorithms() self.refreshAlgorithms()
return True return True
def unload(self): def unload(self):
for setting in [OTBUtils.ACTIVATE, OTBUtils.FOLDER, OTBUtils.SRTM_FOLDER, OTBUtils.GEOID_FILE]: for setting in OTBSettings.keys():
ProcessingConfig.removeSetting(setting) ProcessingConfig.removeSetting(setting)
def isActive(self): def isActive(self):
return ProcessingConfig.getSetting(OTBUtils.ACTIVATE) return ProcessingConfig.getSetting(OTBSettings.ACTIVATE)
def setActive(self, active): def setActive(self, active):
ProcessingConfig.setSettingValue(OTBUtils.ACTIVATE, active) ProcessingConfig.setSettingValue(OTBSettings.ACTIVATE, active)
def createAlgsList(self): def createAlgsList(self):
algs = [] algs = []
...@@ -258,26 +152,140 @@ class OTBAlgorithmProvider(QgsProcessingProvider): ...@@ -258,26 +152,140 @@ class OTBAlgorithmProvider(QgsProcessingProvider):
self.addAlgorithm(a) self.addAlgorithm(a)
self.algs = [] self.algs = []
self.create_otbcli()
def create_otbcli(self):
otb_folder = self.normalize_path(OTBUtils.otbFolder())
otb_app_path_env = os.pathsep.join(self.appDirs(OTBUtils.appFolder()))
gdal_data_dir = None
geotiff_csv_dir = None
try:
if os.name == 'nt':
app_vargs = " %*"
export_cmd = 'SET '
first_line = ':: Setup environment for OTB package. Generated by QGIS plugin'
otb_app_launcher = os.path.join(otb_folder, 'bin', 'otbApplicationLauncherCommandLine.exe')
gdal_data_dir = os.path.join(otb_folder, 'share', 'data')
geotiff_csv_dir = os.path.join(otb_folder, 'share', 'epsg_csv')
else:
app_vargs = " $@"
export_cmd = 'export '
first_line = '#!/bin/sh'
otb_app_launcher = os.path.join(otb_folder, 'bin', 'otbApplicationLauncherCommandLine')
lines = None
env_profile = os.path.join(otb_folder, 'otbenv.profile')
with open(env_profile) as f:
lines = f.readlines()
lines = [x.strip() for x in lines]
for line in lines:
if not line or line.startswith('#'):
continue
if 'GDAL_DATA=' in line:
gdal_data_dir = line.split("GDAL_DATA=")[1]
if 'GEOTIFF_CSV='in line:
geotiff_csv_dir = line.split("GEOTIFF_CSV=")[1]
otbcli_path = OTBUtils.cliPath()
with open(otbcli_path, 'w') as otb_cli_file:
otb_cli_file.write(first_line + os.linesep)
otb_cli_file.write(export_cmd + "LC_NUMERIC=C" + os.linesep)
otb_cli_file.write(export_cmd + "GDAL_DRIVER_PATH=disable" + os.linesep)
if gdal_data_dir:
otb_cli_file.write(export_cmd + "GDAL_DATA=" + "\"" + gdal_data_dir + "\"" + os.linesep)
if geotiff_csv_dir:
otb_cli_file.write(export_cmd + "GEOTIFF_CSV=" + "\"" + geotiff_csv_dir + "\"" + os.linesep)
if OTBUtils.loggerLevel():
otb_cli_file.write(export_cmd + "OTB_LOGGER_LEVEL=" + "\"" + OTBUtils.loggerLevel() + "\"" + os.linesep)
max_ram_hint = OTBUtils.maxRAMHint()
if max_ram_hint and not int(max_ram_hint) == 128 :
otb_cli_file.write(export_cmd + "OTB_MAX_RAM_HINT=" + "\"" + max_ram_hint + "\"" + os.linesep)
otb_cli_file.write(export_cmd + "OTB_APPLICATION_PATH=" + "\"" + otb_app_path_env + "\"" + os.linesep)
otb_cli_file.write("\"" + otb_app_launcher + "\"" + app_vargs + os.linesep)
if not os.name == 'nt':
os.chmod(otbcli_path, 0o744)
except BaseException as e:
import traceback
os.remove(otbcli_path)
errmsg = "Cannot write:" + otbcli_path + "\nError:\n" + traceback.format_exc()
QgsMessageLog.logMessage(self.tr(errmsg), self.tr('Processing'), Qgis.Critical)
raise e
QgsMessageLog.logMessage(self.tr("Using otbcli: '{}'.".format(otbcli_path)), self.tr('Processing'), Qgis.Info)
def canBeActivated(self):
if not self.isActive():
return False
folder = OTBUtils.otbFolder()
if folder and os.path.exists(folder):
if os.path.isfile(self.algsFile(folder)):
return True
utils.iface.messageBar().pushWarning("OTB", "Cannot find '{}'. OTB provider will be disabled".format(self.algsFile(folder)))
self.setActive(False)
return False
def validateLoggerLevel(self, v):
allowed_values = ['DEBUG', 'INFO', 'WARNING', 'CRITICAL', 'FATAL']
if v in allowed_values:
return True
else:
raise ValueError(self.tr("'{}' is not valid. Possible values are '{}'".format(v, ', '.join(allowed_values))))
def validateAppFolders(self, v):
if not self.isActive():
return
if not v:
self.setActive(False)
raise ValueError(self.tr('Cannot activate OTB provider'))
folder = OTBUtils.otbFolder() folder = OTBUtils.otbFolder()
cli_ext = '' otb_app_dirs = self.appDirs(v)
env_profile = os.path.join(folder, 'otbenv.profile') if len(otb_app_dirs) < 1:
if os.name == 'nt': self.setActive(False)
cli_ext = '.bat' raise ValueError(self.tr("'{}' does not exist. OTB provider will be disabled".format(v)))
env_profile = os.path.join(folder, 'otbenv.bat')
#isValid is True if there is atleast one valid otb application is given path
if os.path.exists(env_profile) and os.path.isfile(env_profile): isValid = False
OTBUtils.OTB_CLI_FILE = os.path.normpath( descr_folder = self.descrFolder(folder)
os.path.join( for app_dir in otb_app_dirs:
QgsApplication.qgisSettingsDirPath(), if not os.path.exists(app_dir):
'processing', 'qgis_otb_cli' + cli_ext) continue
) for otb_app in os.listdir(app_dir):
#if not os.path.exists(OTBUtils.OTB_CLI_FILE): if not otb_app.startswith('otbapp_') or \
#rewrite always for now.. 'TestApplication' in otb_app or \
self.write_otbcli_wrapper_script() 'ApplicationExample' in otb_app:
continue
app_name = os.path.basename(otb_app).split('.')[0][7:]
dfile = os.path.join(descr_folder, app_name + '.txt')
isValid = True
if not os.path.exists(dfile):
cmdlist = [os.path.join(
folder, 'bin',
otb_exe_file('otbQgisDescriptor')),
app_name, app_dir, descr_folder + '/']
commands = ' '.join(cmdlist)
QgsMessageLog.logMessage(self.tr(commands), self.tr('Processing'), Qgis.Critical)
OTBUtils.executeOtb(commands, feedback=None)
if isValid:
utils.iface.messageBar().pushInfo("OTB", "OTB provider is activated from '{}'.".format(folder))
else: else:
OTBUtils.OTB_CLI_FILE = os.path.join(folder, 'bin', 'otbcli' + cli_ext) self.setActive(False)
raise ValueError(self.tr("No OTB algorithms found in '{}'. OTB will be disabled".format(','.join(otb_app_dirs))))
QgsMessageLog.logMessage(self.tr("Using otbcli: '{}'.".format(OTBUtils.OTB_CLI_FILE)), self.tr('Processing'), Qgis.Info) def normalize_path(self, p):
# https://stackoverflow.com/a/20713238/1003090
return os.path.normpath(os.sep.join(re.split(r'\\|/', p)))
def validateOtbFolder(self, v):
if not self.isActive():
return
if not v or not os.path.exists(v):
self.setActive(False)
raise ValueError(self.tr("'{}' does not exist. OTB provider will be disabled".format(v)))
path = self.normalize_path(v)
if not os.path.exists(os.path.join(path, 'bin', otb_exe_file('otbApplicationLauncherCommandLine'))):
self.setActive(False)
raise ValueError(self.tr("Cannot find '{}'. OTB will be disabled".format(os.path.join(v, 'bin', otb_exe_file('otbApplicationLauncherCommandLine')))))
def algsFile(self, d): def algsFile(self, d):
return os.path.join(self.descrFolder(d), 'algs.txt') return os.path.join(self.descrFolder(d), 'algs.txt')
...@@ -292,7 +300,7 @@ class OTBAlgorithmProvider(QgsProcessingProvider): ...@@ -292,7 +300,7 @@ class OTBAlgorithmProvider(QgsProcessingProvider):
def descrFile(self, d, f): def descrFile(self, d, f):
return os.path.join(self.descrFolder(d), f) return os.path.join(self.descrFolder(d), f)
def otb_app_dir_list(self, v): def appDirs(self, v):
#!hack needed for QGIS < 3.2!# #!hack needed for QGIS < 3.2!#
v = v.replace(';', os.pathsep) v = v.replace(';', os.pathsep)
#!hack needed for QGIS < 3.2!# #!hack needed for QGIS < 3.2!#
......
# -*- coding: utf-8 -*-
"""
***************************************************************************
* *
* 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. *
* *
***************************************************************************
"""
from builtins import str
__author__ = 'Rashad Kanavath'
__date__ = 'January 2019'
__copyright__ = '(C) CNES 2019'
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'
class OTBSettings(object):
"""
OTBSetting's key names
"""
# Checkbox to enable/disable otb provider (bool).
ACTIVATE = "OTB_ACTIVATE"
# Path to otb installation folder (string, directory).
FOLDER = "OTB_FOLDER"
# Path to otb application folder. multiple paths are supported (string, directory).
APP_FOLDER = "OTB_APP_FOLDER"
# A string to hold current version number. Useful for bug reporting.
VERSION = "OTB_VERSION"
# Default directory were DEM tiles are stored. It should only contain ```.hgt`` or or georeferenced ``.tif`` files. Empty if not set (no directory set).
SRTM_FOLDER = "OTB_SRTM_FOLDER"
# Default path to the geoid file that will be used to retrieve height of DEM above ellipsoid. Empty if not set (no geoid set).
GEOID_FILE = "OTB_GEOID_FILE"
# Default maximum memory that OTB should use for processing, in MB. If not set, default value is 128 MB.
# This is set through environment variable ``OTB_MAX_RAM_HINT``
MAX_RAM_HINT = 'OTB_MAX_RAM_HINT'
# ``OTB_LOGGER_LEVEL``: Default level of logging for OTB. Should be one of ``DEBUG``, ``INFO``, ``WARNING``, ``CRITICAL`` or ``FATAL``, by increasing order of priority. Only messages with a higher priority than the level of logging will be displayed. If not set, default level is ``INFO``.
LOGGER_LEVEL = 'OTB_LOGGER_LEVEL'
@staticmethod
def keys():
return [
OTBSettings.ACTIVATE,
OTBSettings.FOLDER,
OTBSettings.SRTM_FOLDER,
OTBSettings.GEOID_FILE,
OTBSettings.LOGGER_LEVEL,
OTBSettings.MAX_RAM_HINT
]
...@@ -34,47 +34,45 @@ import re ...@@ -34,47 +34,45 @@ import re
import subprocess import subprocess
from processing.core.ProcessingConfig import ProcessingConfig from processing.core.ProcessingConfig import ProcessingConfig
from processing.core.ProcessingLog import ProcessingLog from qgis.core import (Qgis, QgsApplication, QgsMessageLog)
from processing.tools.system import isMac, isWindows
from qgis.core import (Qgis, QgsMessageLog)
from qgis.PyQt.QtCore import QCoreApplication from qgis.PyQt.QtCore import QCoreApplication
from otb.OTBSettings import OTBSettings
ACTIVATE = "OTB_ACTIVATE" def cliPath():
FOLDER = "OTB_FOLDER" cli_ext = '.bat' if os.name == 'nt' else ''
APP_FOLDER = "OTB_APP_FOLDER" return os.path.normpath(os.path.join(QgsApplication.qgisSettingsDirPath(),
VERSION = "OTB_VERSION" 'processing', 'qgis_otb_cli' + cli_ext))
SRTM_FOLDER = "OTB_SRTM_FOLDER"
GEOID_FILE = "OTB_GEOID_FILE"
DOWNLOAD_URL = "https://orfeo-toolbox.org/packages/archives/OTB/"
DEFAULT_RAM_VALUE = 128
OTB_CLI_FILE = ''
import re
def version(): def version():
return ProcessingConfig.getSetting(VERSION) or '0.0.0' return ProcessingConfig.getSetting(OTBSettings.VERSION) or '0.0.0'
def loggerLevel():
return ProcessingConfig.getSetting(OTBSettings.LOGGER_LEVEL) or 'INFO'
def maxRAMHint():
return ProcessingConfig.getSetting(OTBSettings.MAX_RAM_HINT) or ''
def otbFolder(): def otbFolder():
if ProcessingConfig.getSetting(FOLDER): if ProcessingConfig.getSetting(OTBSettings.FOLDER):
return os.path.normpath(os.sep.join(re.split(r'\\|/', ProcessingConfig.getSetting(FOLDER)))) return os.path.normpath(os.sep.join(re.split(r'\\|/', ProcessingConfig.getSetting(OTBSettings.FOLDER))))
else: else:
return None return None
def appFolder(): def appFolder():
app_folder = ProcessingConfig.getSetting(APP_FOLDER) app_folder = ProcessingConfig.getSetting(OTBSettings.APP_FOLDER)
if app_folder: if app_folder:
return os.pathsep.join(app_folder.split(';')) return os.pathsep.join(app_folder.split(';'))
else: else:
return None return None
def srtmFolder(): def srtmFolder():
return ProcessingConfig.getSetting(SRTM_FOLDER) or '' return ProcessingConfig.getSetting(OTBSettings.SRTM_FOLDER) or ''
def geoidFile(): def geoidFile():
return ProcessingConfig.getSetting(GEOID_FILE) or '' return ProcessingConfig.getSetting(OTBSettings.GEOID_FILE) or ''
def executeOtb(commands, feedback, addToLog=True): def executeOtb(commands, feedback, addToLog=True):
loglines = [] loglines = []
feedback.setProgress(0)
with subprocess.Popen( with subprocess.Popen(
commands, commands,
shell=True, shell=True,
......