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

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):
#parameter is added now and we must move to next line
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:
import traceback
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):
#it is considered valid if it has value other than float
if k == 'outputpixeltype' and self.pixelTypes[int(v)] == 'float':
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:
#- empty or no metadata
#- metadata without a 'group_key'
......@@ -239,7 +226,7 @@ class OTBAlgorithm(QgsProcessingAlgorithm):
def processAlgorithm(self, parameters, context, feedback):
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())
for k, v in parameters.items():
if k == 'outputpixeltype' or not v:
......
This diff is collapsed.
# -*- 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
import subprocess
from processing.core.ProcessingConfig import ProcessingConfig
from processing.core.ProcessingLog import ProcessingLog
from processing.tools.system import isMac, isWindows
from qgis.core import (Qgis, QgsMessageLog)
from qgis.core import (Qgis, QgsApplication, QgsMessageLog)
from qgis.PyQt.QtCore import QCoreApplication
from otb.OTBSettings import OTBSettings
ACTIVATE = "OTB_ACTIVATE"
FOLDER = "OTB_FOLDER"
APP_FOLDER = "OTB_APP_FOLDER"
VERSION = "OTB_VERSION"
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 cliPath():
cli_ext = '.bat' if os.name == 'nt' else ''
return os.path.normpath(os.path.join(QgsApplication.qgisSettingsDirPath(),
'processing', 'qgis_otb_cli' + cli_ext))
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():
if ProcessingConfig.getSetting(FOLDER):
return os.path.normpath(os.sep.join(re.split(r'\\|/', ProcessingConfig.getSetting(FOLDER))))
if ProcessingConfig.getSetting(OTBSettings.FOLDER):
return os.path.normpath(os.sep.join(re.split(r'\\|/', ProcessingConfig.getSetting(OTBSettings.FOLDER))))
else:
return None
def appFolder():
app_folder = ProcessingConfig.getSetting(APP_FOLDER)
app_folder = ProcessingConfig.getSetting(OTBSettings.APP_FOLDER)
if app_folder:
return os.pathsep.join(app_folder.split(';'))
else:
return None
def srtmFolder():
return ProcessingConfig.getSetting(SRTM_FOLDER) or ''
return ProcessingConfig.getSetting(OTBSettings.SRTM_FOLDER) or ''
def geoidFile():
return ProcessingConfig.getSetting(GEOID_FILE) or ''
return ProcessingConfig.getSetting(OTBSettings.GEOID_FILE) or ''
def executeOtb(commands, feedback, addToLog=True):
loglines = []
feedback.setProgress(0)
with subprocess.Popen(
commands,
shell=True,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment