Skip to content
Permalink
Browse files
[sextante]Changed how SAGA installation is checked
  • Loading branch information
volaya committed Feb 24, 2013
1 parent 10999cf commit e394fc1
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 21 deletions.
@@ -366,25 +366,12 @@ def exportRasterLayer(self, layer):


def checkBeforeOpeningParametersDialog(self):
if SextanteUtils.isWindows():
path = SagaUtils.sagaPath()
if path == "":
return "SAGA folder is not configured.\nPlease configure it before running SAGA algorithms."
else:
SAGA_INSTALLED = "SAGA_INSTALLED"
settings = QSettings()
if settings.contains(SAGA_INSTALLED):
return
command = ["saga_cmd"]
proc = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stdin=subprocess.PIPE,stderr=subprocess.STDOUT, universal_newlines=True).stdout
for line in iter(proc.readline, ""):
if "________" in line:
settings.setValue(SAGA_INSTALLED, True)
return
return "It seems that SAGA is not correctly installed in your system.\nPlease install it before running SAGA algorithms."
return SagaUtils.checkSagaIsInstalled()


def helpFile(self):
return os.path.join(os.path.dirname(__file__), "help", self.name.replace(" ", "") + ".html")
return os.path.join(os.path.dirname(__file__), "help", self.name.replace(" ", "") + ".html")


def commandLineName(self):
name = self.provider.getName().lower() + ":" + self.cmdname.lower()
@@ -16,6 +16,9 @@
* *
***************************************************************************
"""
from sextante.core.SextanteVectorWriter import SextanteVectorWriter
from sextante.core.QGisLayers import QGisLayers
import sextante

__author__ = 'Victor Olaya'
__date__ = 'August 2012'
@@ -29,6 +32,8 @@
from sextante.core.SextanteConfig import SextanteConfig
from sextante.core.SextanteLog import SextanteLog
import stat
from qgis.core import *
from PyQt4.QtCore import *

class SagaUtils:

@@ -107,7 +112,47 @@ def executeSaga(progress):
if SextanteConfig.getSetting(SagaUtils.SAGA_LOG_CONSOLE):
SextanteLog.addToLog(SextanteLog.LOG_INFO, loglines)






@classmethod
def checkSagaIsInstalled(cls):
if SextanteUtils.isWindows():
path = SagaUtils.sagaPath()
if path == "":
return "SAGA folder is not configured.\nPlease configure it before running SAGA algorithms."
cmdpath = os.path.join(path, "saga_cmd.exe")
if not os.path.exists(cmdpath):
return ("The specified SAGA folder does not contain a valid SAGA executable.\n"
+ "Please, go to the SEXTANTE settings dialog, and check that the SAGA\n"
+ "folder is correctly configured")

SAGA_INSTALLED = "/SextanteQGIS/SagaInstalled"
settings = QSettings()
if settings.contains(SAGA_INSTALLED):
return

try:
qgis = QGisLayers.iface
crs = qgis.mapCanvas().mapRenderer().destinationCrs()
fields = []
fields.append(QgsField("NUM_FIELD", QVariant.Int))
filename = SextanteUtils.getTempFilename("shp")
writer = SextanteVectorWriter(filename, None, fields, QGis.WKBPoint, crs)
for x in range(5):
for y in range(5):
attrs = []
attrs.append(QVariant(x))
outFeat = QgsFeature()
pt = QgsPoint(x, y)
outFeat.setGeometry(QgsGeometry.fromPoint(pt))
outFeat.setAttributes(attrs)
writer.addFeature(outFeat)
del writer.writer
del writer
result = sextante.runalg("saga:thiessenpolygons", filename, None)
if not os.path.exists(result['POLYGONS']):
return "It seems that SAGA is not correctly installed in your system.\nPlease install it before running SAGA algorithms."
except:
return "It seems that SAGA is not correctly installed in your system.\nPlease install it before running SAGA algorithms."

settings.setValue("/SextanteQGIS/SagaInstalled", True)

0 comments on commit e394fc1

Please sign in to comment.