def load(self): group = self.name() ProcessingConfig.settingIcons[group] = self.icon() ProcessingConfig.addSetting( Setting(group, OtbSettings.ACTIVATE, self.tr('Activate'), True)) ProcessingConfig.addSetting( Setting(group, OtbSettings.FOLDER, self.tr("OTB folder"), OtbUtils.otbFolder(), valuetype=Setting.FOLDER, validator=self.validateOtbFolder)) ProcessingConfig.addSetting( Setting(group, OtbSettings.APP_FOLDER, self.tr("OTB application folder"), OtbUtils.appFolder(), valuetype=Setting.MULTIPLE_FOLDERS, validator=self.validateAppFolders)) ProcessingConfig.addSetting( Setting(group, OtbSettings.SRTM_FOLDER, self.tr("SRTM tiles folder"), OtbUtils.srtmFolder(), valuetype=Setting.FOLDER)) ProcessingConfig.addSetting( Setting(group, OtbSettings.GEOID_FILE, self.tr("Geoid file"), OtbUtils.geoidFile(), 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() self.refreshAlgorithms() return True
def load(self): group = self.name() ProcessingConfig.settingIcons[group] = self.icon() ProcessingConfig.addSetting(Setting(group, OtbSettings.ACTIVATE, self.tr('Activate'), True)) ProcessingConfig.addSetting(Setting(group, OtbSettings.FOLDER, self.tr("OTB folder"), OtbUtils.otbFolder(), valuetype=Setting.FOLDER, validator=self.validateOtbFolder )) ProcessingConfig.addSetting(Setting(group, OtbSettings.APP_FOLDER, self.tr("OTB application folder"), OtbUtils.appFolder(), valuetype=Setting.MULTIPLE_FOLDERS, validator=self.validateAppFolders )) ProcessingConfig.addSetting(Setting(group, OtbSettings.SRTM_FOLDER, self.tr("SRTM tiles folder"), OtbUtils.srtmFolder(), valuetype=Setting.FOLDER )) ProcessingConfig.addSetting(Setting(group, OtbSettings.GEOID_FILE, self.tr("Geoid file"), OtbUtils.geoidFile(), 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() self.refreshAlgorithms() return True
def loadAlgorithms(self): if not self.canBeActivated(): return version_file = os.path.join(OtbUtils.otbFolder(), 'share', 'doc', 'otb', 'VERSION') if not os.path.isfile(version_file): version_file = os.path.join(OtbUtils.otbFolder(), 'VERSION') if os.path.isfile(version_file): with open(version_file) as vf: vlines = vf.readlines() vlines = [l.strip() for l in vlines] vline = vlines[0] if 'OTB Version:' in vline: self.version = vline.split(':')[1].strip() QgsMessageLog.logMessage(self.tr("Loading OTB '{}'.".format(self.version)), self.tr('Processing'), Qgis.Info) self.algs = self.createAlgsList() for a in self.algs: self.addAlgorithm(a) self.algs = [] 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 otbcli_path = OtbUtils.cliPath() 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') if os.path.exists(env_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(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 loadAlgorithms(self): if not self.canBeActivated(): return version_file = os.path.join(OtbUtils.otbFolder(), 'share', 'doc', 'otb', 'VERSION') if not os.path.isfile(version_file): version_file = os.path.join(OtbUtils.otbFolder(), 'VERSION') if os.path.isfile(version_file): with open(version_file) as vf: vlines = vf.readlines() vlines = [l.strip() for l in vlines] vline = vlines[0] if 'OTB Version:' in vline: self.version = vline.split(':')[1].strip() QgsMessageLog.logMessage( self.tr("Loading OTB '{}'.".format(self.version)), self.tr('Processing'), Qgis.Info) self.algs = self.createAlgsList() for a in self.algs: self.addAlgorithm(a) self.algs = [] 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 otbcli_path = OtbUtils.cliPath() 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') if os.path.exists(env_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(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)