Skip to content

Commit

Permalink
[processing] If SAGA/OTB exist as bundled app, do not allow manual co…
Browse files Browse the repository at this point in the history
…nfiguration
  • Loading branch information
volaya committed Jun 16, 2014
1 parent 09cfc03 commit 3d15239
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 73 deletions.
8 changes: 6 additions & 2 deletions python/plugins/processing/algs/otb/OTBAlgorithmProvider.py
Expand Up @@ -74,8 +74,12 @@ def createAlgsList(self):

def initializeSettings(self):
AlgorithmProvider.initializeSettings(self)
ProcessingConfig.addSetting(Setting(self.getDescription(), OTBUtils.OTB_FOLDER, "OTB command line tools folder", OTBUtils.otbPath()))
ProcessingConfig.addSetting(Setting(self.getDescription(), OTBUtils.OTB_LIB_FOLDER, "OTB applications folder", OTBUtils.otbLibPath()))
if OTBUtils.findOtbPath() is None:
ProcessingConfig.addSetting(Setting(self.getDescription(), OTBUtils.OTB_FOLDER,
"OTB command line tools folder", OTBUtils.otbPath()))
if OTBUtils.findOtbLibPath() is None:
ProcessingConfig.addSetting(Setting(self.getDescription(), OTBUtils.OTB_LIB_FOLDER,
"OTB applications folder", OTBUtils.otbLibPath()))
ProcessingConfig.addSetting(Setting(self.getDescription(), OTBUtils.OTB_SRTM_FOLDER, "SRTM tiles folder", OTBUtils.otbSRTMPath()))
ProcessingConfig.addSetting(Setting(self.getDescription(), OTBUtils.OTB_GEOID_FILE, "Geoid file", OTBUtils.otbGeoidPath()))

Expand Down
91 changes: 48 additions & 43 deletions python/plugins/processing/algs/otb/OTBUtils.py
Expand Up @@ -29,7 +29,6 @@
__revision__ = '$Format:%H$'

import os
import glob
from qgis.core import QgsApplication
import subprocess
from processing.core.ProcessingConfig import ProcessingConfig
Expand All @@ -39,7 +38,6 @@
import xml.etree.ElementTree as ET
import traceback
import qgis.core
import PyQt4.QtGui


class OTBUtils:
Expand All @@ -50,58 +48,65 @@ class OTBUtils:
OTB_GEOID_FILE = "OTB_GEOID_FILE"

@staticmethod
def otbPath():
folder = ProcessingConfig.getSetting(OTBUtils.OTB_FOLDER)
if folder == None:
folder = ""
#try to configure the path automatically
if isMac():
testfolder = os.path.join(str(QgsApplication.prefixPath()), "bin")
if os.path.exists(os.path.join(testfolder, "otbcli")):
folder = testfolder
else:
testfolder = "/usr/local/bin"
if os.path.exists(os.path.join(testfolder, "otbcli")):
folder = testfolder
elif isWindows():
testfolder = os.path.dirname(str(QgsApplication.prefixPath()))
testfolder = os.path.dirname(testfolder)
testfolder = os.path.join(testfolder, "bin")
path = os.path.join(testfolder, "otbcli.bat")
if os.path.exists(path):
folder = testfolder
def findOtbPath():
folder = None
#try to configure the path automatically
if isMac():
testfolder = os.path.join(str(QgsApplication.prefixPath()), "bin")
if os.path.exists(os.path.join(testfolder, "otbcli")):
folder = testfolder
else:
testfolder = "/usr/bin"
testfolder = "/usr/local/bin"
if os.path.exists(os.path.join(testfolder, "otbcli")):
folder = testfolder
elif isWindows():
testfolder = os.path.join(os.path.dirname(QgsApplication.prefixPath()),
os.pardir, "bin")
if os.path.exists(os.path.join(testfolder, "otbcli.bat")):
folder = testfolder
else:
testfolder = "/usr/bin"
if os.path.exists(os.path.join(testfolder, "otbcli")):
folder = testfolder
return folder

@staticmethod
def otbLibPath():
folder = ProcessingConfig.getSetting(OTBUtils.OTB_LIB_FOLDER)
if folder == None:
folder =""
#try to configure the path automatically
if isMac():
testfolder = os.path.join(str(QgsApplication.prefixPath()), "lib/otb/applications")
if os.path.exists(testfolder):
folder = testfolder
else:
testfolder = "/usr/local/lib/otb/applications"
if os.path.exists(testfolder):
folder = testfolder
elif isWindows():
testfolder = os.path.dirname(str(QgsApplication.prefixPath()))
testfolder = os.path.join(testfolder, "orfeotoolbox")
testfolder = os.path.join(testfolder, "applications")
if os.path.exists(testfolder):
folder = testfolder
def otbPath():
folder = OTBUtils.findOtbPath()
if folder is None:
folder = ProcessingConfig.getSetting(OTBUtils.OTB_FOLDER)
return folder

@staticmethod
def findOtbLibPath():
folder = None
#try to configure the path automatically
if isMac():
testfolder = os.path.join(str(QgsApplication.prefixPath()), "lib/otb/applications")
if os.path.exists(testfolder):
folder = testfolder
else:
testfolder = "/usr/lib/otb/applications"
testfolder = "/usr/local/lib/otb/applications"
if os.path.exists(testfolder):
folder = testfolder
elif isWindows():
testfolder = os.path.join(os.path.dirname(QgsApplication.prefixPath()), "orfeotoolbox", "applications")
if os.path.exists(testfolder):
folder = testfolder
else:
testfolder = "/usr/lib/otb/applications"
if os.path.exists(testfolder):
folder = testfolder
return folder

@staticmethod
def otbLibPath():
folder = OTBUtils.findOtbLibPath()
if folder is None:
folder = ProcessingConfig.getSetting(OTBUtils.OTB_LIB_FOLDER)
return folder


@staticmethod
def otbSRTMPath():
folder = ProcessingConfig.getSetting(OTBUtils.OTB_SRTM_FOLDER)
Expand Down
4 changes: 2 additions & 2 deletions python/plugins/processing/algs/saga/SagaAlgorithm.py
Expand Up @@ -177,7 +177,7 @@ def processAlgorithm(self, progress):
'Unsupported file format')

# 2: Set parameters and outputs
saga208 = ProcessingConfig.getSetting(SagaUtils.SAGA_208)
saga208 = SagaUtils.isSaga208()
if isWindows() or isMac() or not saga208:
command = self.undecoratedGroup + ' "' + self.cmdname + '"'
else:
Expand Down Expand Up @@ -351,7 +351,7 @@ def exportRasterLayer(self, source):
destFilename = getTempFilenameInTempFolder(filename + '.sgrd')
self.exportedLayers[source] = destFilename
sessionExportedLayers[source] = destFilename
saga208 = ProcessingConfig.getSetting(SagaUtils.SAGA_208)
saga208 = SagaUtils.isSaga208()
if saga208:
if isWindows() or isMac():
return 'io_gdal 0 -GRIDS "' + destFilename + '" -FILES "' + source \
Expand Down
18 changes: 9 additions & 9 deletions python/plugins/processing/algs/saga/SagaAlgorithmProvider.py
Expand Up @@ -46,13 +46,13 @@ def __init__(self):

def initializeSettings(self):
AlgorithmProvider.initializeSettings(self)
if isWindows():
if SagaUtils.findSagaFolder() is None:
ProcessingConfig.addSetting(Setting(self.getDescription(),
SagaUtils.SAGA_FOLDER, 'SAGA folder',
SagaUtils.sagaPath()))
ProcessingConfig.addSetting(Setting(self.getDescription(),
SagaUtils.SAGA_208,
'Use SAGA 2.0.8 syntax', True))
SagaUtils.SAGA_208,
'Use SAGA 2.0.8 syntax', not isMac()))
if isWindows() or isMac():
ProcessingConfig.addSetting(Setting(self.getDescription(),
SagaUtils.SAGA_FOLDER, 'SAGA folder', ''))
ProcessingConfig.addSetting(Setting(self.getDescription(),
SagaUtils.SAGA_IMPORT_EXPORT_OPTIMIZATION,
'Enable SAGA Import/Export optimizations',
Expand All @@ -72,13 +72,13 @@ def unload(self):
ProcessingConfig.removeSetting(SagaUtils.SAGA_LOG_CONSOLE)
ProcessingConfig.removeSetting(SagaUtils.SAGA_LOG_COMMANDS)


def _loadAlgorithms(self):
self.algs = []
saga208 = ProcessingConfig.getSetting(SagaUtils.SAGA_208)
self.algs = []
folder = SagaUtils.sagaDescriptionPath()
for descriptionFile in os.listdir(folder):
if descriptionFile.endswith('txt'):
if not saga208:
if not SagaUtils.isSaga208():
if descriptionFile.startswith('2.0.8'):
continue
else:
Expand Down
43 changes: 26 additions & 17 deletions python/plugins/processing/algs/saga/SagaUtils.py
Expand Up @@ -59,27 +59,36 @@ def sagaBatchJobFilename():
return batchfile

@staticmethod
def sagaPath():
folder = ProcessingConfig.getSetting(SagaUtils.SAGA_FOLDER)
if folder is None:
folder = ''
# Try to auto-configure the folder
if isMac():
testfolder = os.path.join(str(QgsApplication.prefixPath()),
'bin')
def findSagaFolder():
folder = None
if isMac():
testfolder = os.path.join(QgsApplication.prefixPath(), 'bin')
if os.path.exists(os.path.join(testfolder, 'saga_cmd')):
folder = testfolder
else:
testfolder = '/usr/local/bin'
if os.path.exists(os.path.join(testfolder, 'saga_cmd')):
folder = testfolder
else:
testfolder = '/usr/local/bin'
if os.path.exists(os.path.join(testfolder, 'saga_cmd')):
folder = testfolder
elif isWindows():
testfolder = os.path.dirname(str(QgsApplication.prefixPath()))
testfolder = os.path.join(testfolder, 'saga')
if os.path.exists(os.path.join(testfolder, 'saga_cmd.exe')):
folder = testfolder
elif isWindows():
testfolder = os.path.join(os.path.dirname(QgsApplication.prefixPath()), 'saga')
if os.path.exists(os.path.join(testfolder, 'saga_cmd.exe')):
folder = testfolder
return folder

@staticmethod
def sagaPath():
folder = SagaUtils.findSagaFolder()
if folder is None:
folder = ProcessingConfig.getSetting(SagaUtils.SAGA_FOLDER)
return folder or ''

@staticmethod
def isSaga208():
if SagaUtils.findSagaFolder() is not None:
return not isMac();
else:
return ProcessingConfig.getSetting(SagaUtils.SAGA_208)

@staticmethod
def sagaDescriptionPath():
return os.path.join(os.path.dirname(__file__), 'description')
Expand Down

5 comments on commit 3d15239

@gioman
Copy link
Contributor

@gioman gioman commented on 3d15239 Jun 16, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Victor, I didn't tested yet his patch, does this means that on Windows we cannot choose anymore (manually) to use SAGA 2.0.0 or 2.10? thanks!

@gioman
Copy link
Contributor

@gioman gioman commented on 3d15239 Jun 30, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Victor, removing the possibility to choose what SAGA installation to use (on Windows) was on purpose?

@volaya
Copy link
Contributor Author

@volaya volaya commented on 3d15239 Jul 1, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the idea is that, if you are using a QGIS that comes with a packaged SAGA, it should use that one, just like it uses a given version of GDAL or any other library. If you are an advanced user, you can tweak it and replace that folder or edit the QSettings directly, but in the Processing options you will not see an option for that. There is no need for any configuration, since it comes preconfigured.

If there is no packaged SAGA, then you must configure it.

What do you think of this?

@gioman
Copy link
Contributor

@gioman gioman commented on 3d15239 Jul 1, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Victor,

I think is ok, simplify things is good and power users can use the workaround to change SAGA to be used. The problem is that on Linux there is the option to use/not use SAGA 2..0.8 (so use SAGA 2.10) while on Windows there isn't. So at this moment in Windows a power user can only use the bundled SAGA (2.0.8) that has a few modules bugged a few of them that have been already fixed/added as specific 2.10 modules. Cheers!

@PedroVenancio
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Victor,

If what Giovanni refers is true, it seems a throwback, not being able to use a newer version of SAGA.
You can not leave this option as it is on Linux?

Thanks Victor!

Please sign in to comment.