2012-10-05 23:28:47 +02:00
# -*- coding: utf-8 -*-
"""
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
SagaAlgorithmProvider . py
- - - - - - - - - - - - - - - - - - - - -
Date : August 2012
Copyright : ( C ) 2012 by Victor Olaya
Email : volayaf at gmail dot com
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* 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 . *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
"""
__author__ = ' Victor Olaya '
__date__ = ' August 2012 '
__copyright__ = ' (C) 2012, Victor Olaya '
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = ' $Format: % H$ '
2012-09-15 18:25:25 +03:00
import os
from PyQt4 . QtCore import *
from PyQt4 . QtGui import *
2013-03-30 18:55:46 +01:00
from sextante . saga . SagaAlgorithm import SagaAlgorithm
from sextante . saga . SplitRGBBands import SplitRGBBands
from sextante . saga . SagaUtils import SagaUtils
2012-09-15 18:25:25 +03:00
from sextante . core . SextanteConfig import SextanteConfig , Setting
from sextante . core . AlgorithmProvider import AlgorithmProvider
from sextante . core . SextanteLog import SextanteLog
from sextante . core . SextanteUtils import SextanteUtils
class SagaAlgorithmProvider ( AlgorithmProvider ) :
def __init__ ( self ) :
AlgorithmProvider . __init__ ( self )
2013-04-21 15:12:53 +02:00
self . activate = True
2012-09-15 18:25:25 +03:00
self . createAlgsList ( ) #preloading algorithms to speed up
def initializeSettings ( self ) :
AlgorithmProvider . initializeSettings ( self )
if SextanteUtils . isWindows ( ) :
SextanteConfig . addSetting ( Setting ( self . getDescription ( ) , SagaUtils . SAGA_FOLDER , " SAGA folder " , SagaUtils . sagaPath ( ) ) )
SextanteConfig . addSetting ( Setting ( self . getDescription ( ) , SagaUtils . SAGA_AUTO_RESAMPLING , " Use min covering grid system for resampling " , True ) )
SextanteConfig . addSetting ( Setting ( self . getDescription ( ) , SagaUtils . SAGA_LOG_COMMANDS , " Log execution commands " , False ) )
SextanteConfig . addSetting ( Setting ( self . getDescription ( ) , SagaUtils . SAGA_LOG_CONSOLE , " Log console output " , False ) )
SextanteConfig . addSetting ( Setting ( self . getDescription ( ) , SagaUtils . SAGA_RESAMPLING_REGION_XMIN , " Resampling region min x " , 0 ) )
SextanteConfig . addSetting ( Setting ( self . getDescription ( ) , SagaUtils . SAGA_RESAMPLING_REGION_YMIN , " Resampling region min y " , 0 ) )
SextanteConfig . addSetting ( Setting ( self . getDescription ( ) , SagaUtils . SAGA_RESAMPLING_REGION_XMAX , " Resampling region max x " , 1000 ) )
SextanteConfig . addSetting ( Setting ( self . getDescription ( ) , SagaUtils . SAGA_RESAMPLING_REGION_YMAX , " Resampling region max y " , 1000 ) )
SextanteConfig . addSetting ( Setting ( self . getDescription ( ) , SagaUtils . SAGA_RESAMPLING_REGION_CELLSIZE , " Resampling region cellsize " , 1 ) )
def unload ( self ) :
AlgorithmProvider . unload ( self )
if SextanteUtils . isWindows ( ) :
SextanteConfig . removeSetting ( SagaUtils . SAGA_FOLDER )
SextanteConfig . removeSetting ( SagaUtils . SAGA_AUTO_RESAMPLING )
SextanteConfig . removeSetting ( SagaUtils . SAGA_RESAMPLING_REGION_XMIN )
SextanteConfig . removeSetting ( SagaUtils . SAGA_RESAMPLING_REGION_YMIN )
SextanteConfig . removeSetting ( SagaUtils . SAGA_RESAMPLING_REGION_XMAX )
SextanteConfig . removeSetting ( SagaUtils . SAGA_RESAMPLING_REGION_YMAX )
SextanteConfig . removeSetting ( SagaUtils . SAGA_RESAMPLING_REGION_CELLSIZE )
SextanteConfig . removeSetting ( SagaUtils . SAGA_LOG_CONSOLE )
SextanteConfig . removeSetting ( SagaUtils . SAGA_LOG_COMMANDS )
def createAlgsList ( self ) :
self . preloadedAlgs = [ ]
folder = SagaUtils . sagaDescriptionPath ( )
for descriptionFile in os . listdir ( folder ) :
if descriptionFile . endswith ( " txt " ) :
try :
alg = SagaAlgorithm ( os . path . join ( folder , descriptionFile ) )
if alg . name . strip ( ) != " " :
self . preloadedAlgs . append ( alg )
else :
SextanteLog . addToLog ( SextanteLog . LOG_ERROR , " Could not open SAGA algorithm: " + descriptionFile )
except Exception , e :
2013-03-28 21:24:35 +01:00
SextanteLog . addToLog ( SextanteLog . LOG_ERROR , " Could not open SAGA algorithm: " + descriptionFile + " \n " + str ( e ) )
2012-10-27 23:06:38 +02:00
self . preloadedAlgs . append ( SplitRGBBands ( ) )
2012-12-10 00:12:07 +01:00
2012-09-15 18:25:25 +03:00
def _loadAlgorithms ( self ) :
self . algs = self . preloadedAlgs
def getDescription ( self ) :
return " SAGA "
def getName ( self ) :
return " saga "
2013-03-31 21:18:27 +02:00
2013-03-30 18:55:46 +01:00
def getPostProcessingErrorMessage ( self , wrongLayers ) :
2013-03-31 21:18:27 +02:00
html = AlgorithmProvider . getPostProcessingErrorMessage ( self , wrongLayers )
2013-03-30 18:55:46 +01:00
msg = SagaUtils . checkSagaIsInstalled ( True )
2013-03-31 21:18:27 +02:00
html + = ( " <p>This algorithm requires SAGA to be run. A test to check if SAGA is correctly installed "
2013-03-30 18:55:46 +01:00
" and configured in your system has been performed, with the following result:</p><ul><i> " )
if msg is None :
2013-04-01 00:29:07 +02:00
html + = " SAGA seems to be correctly installed and configured</li></ul> "
2013-03-30 18:55:46 +01:00
else :
html + = msg + " </i></li></ul> "
html + = ' <p><a href= " http://docs.qgis.org/html/en/docs/user_manual/sextante/3rdParty.html " >Click here</a> to know more about how to install and configure SAGA to be used with SEXTANTE</p> '
2013-03-31 21:18:27 +02:00
2013-03-30 18:55:46 +01:00
return html
2013-03-31 21:18:27 +02:00
2012-11-10 00:31:01 +01:00
def getSupportedOutputVectorLayerExtensions ( self ) :
return [ " shp " ]
2012-12-10 00:12:07 +01:00
def getSupportedOutputRasterLayerExtensions ( self ) :
2012-11-10 00:31:01 +01:00
return [ " tif " ]
2013-02-07 01:09:39 +01:00
2013-02-06 21:00:26 +01:00
def getSupportedOutputTableLayerExtensions ( self ) :
return [ " dbf " ]
2012-09-15 18:25:25 +03:00
def getIcon ( self ) :
return QIcon ( os . path . dirname ( __file__ ) + " /../images/saga.png " )