2012-10-05 23:28:47 +02:00
# -*- coding: utf-8 -*-
"""
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
SagaAlgorithm . 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 . *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
"""
2014-04-19 00:48:56 +02:00
from processing . gui . Help2Html import getHtmlFromRstFile
2013-10-01 20:52:22 +03:00
2012-10-05 23:28:47 +02:00
__author__ = ' Victor Olaya '
__date__ = ' August 2012 '
__copyright__ = ' (C) 2012, Victor Olaya '
2013-10-01 20:52:22 +03:00
2012-10-05 23:28:47 +02:00
# This will get replaced with a git SHA1 when you do a git archive
2013-10-01 20:52:22 +03:00
2012-10-05 23:28:47 +02:00
__revision__ = ' $Format: % H$ '
2013-07-23 14:28:24 +02:00
import importlib
2012-09-15 18:25:25 +03:00
from qgis . core import *
from PyQt4 . QtCore import *
from PyQt4 . QtGui import *
2013-10-01 20:52:22 +03:00
2013-08-12 20:44:27 +02:00
from processing . core . GeoAlgorithm import GeoAlgorithm
2013-10-01 20:52:22 +03:00
from processing . core . ProcessingConfig import ProcessingConfig
from processing . core . ProcessingLog import ProcessingLog
from processing . core . GeoAlgorithmExecutionException import \
GeoAlgorithmExecutionException
2014-07-14 14:19:09 +02:00
from processing . core . parameters import *
from processing . core . outputs import *
2014-04-17 01:41:25 +02:00
from SagaUtils import SagaUtils
from SagaGroupNameDecorator import SagaGroupNameDecorator
2013-09-12 13:19:00 +02:00
from processing . tools import dataobjects
2013-10-01 20:52:22 +03:00
from processing . tools . system import *
2012-09-15 18:25:25 +03:00
2013-09-14 17:41:08 +02:00
sessionExportedLayers = { }
2013-10-01 20:52:22 +03:00
2012-09-15 18:25:25 +03:00
class SagaAlgorithm ( GeoAlgorithm ) :
2013-10-01 20:52:22 +03:00
OUTPUT_EXTENT = ' OUTPUT_EXTENT '
2012-09-15 18:25:25 +03:00
2014-05-21 21:25:18 +02:00
def __init__ ( self , descriptionfile ) :
2012-09-15 18:25:25 +03:00
GeoAlgorithm . __init__ ( self )
2014-05-20 01:10:23 +02:00
self . hardcodedStrings = [ ]
self . allowUnmatchingGridExtents = False
2012-09-15 18:25:25 +03:00
self . descriptionFile = descriptionfile
self . defineCharacteristicsFromFile ( )
def getCopy ( self ) :
newone = SagaAlgorithm ( self . descriptionFile )
newone . provider = self . provider
return newone
def getIcon ( self ) :
2014-04-17 01:41:25 +02:00
return QIcon ( os . path . dirname ( __file__ ) + ' /../../images/saga.png ' )
2012-09-15 18:25:25 +03:00
2014-05-21 21:25:18 +02:00
def defineCharacteristicsFromFile ( self ) :
2012-09-15 18:25:25 +03:00
lines = open ( self . descriptionFile )
2013-10-01 20:52:22 +03:00
line = lines . readline ( ) . strip ( ' \n ' ) . strip ( )
2012-09-15 18:25:25 +03:00
self . name = line
2013-10-01 20:52:22 +03:00
if ' | ' in self . name :
tokens = self . name . split ( ' | ' )
2012-10-12 19:14:39 +02:00
self . name = tokens [ 0 ]
self . cmdname = tokens [ 1 ]
else :
self . cmdname = self . name
2013-04-12 17:18:51 +02:00
self . name = self . name [ 0 ] . upper ( ) + self . name [ 1 : ] . lower ( )
2013-10-01 20:52:22 +03:00
line = lines . readline ( ) . strip ( ' \n ' ) . strip ( )
2012-09-15 18:25:25 +03:00
self . undecoratedGroup = line
2013-10-01 20:52:22 +03:00
self . group = SagaGroupNameDecorator . getDecoratedName (
self . undecoratedGroup )
2014-07-18 09:57:37 +02:00
line = lines . readline ( ) . strip ( ' \n ' ) . strip ( )
2013-10-01 20:52:22 +03:00
while line != ' ' :
if line . startswith ( ' Hardcoded ' ) :
self . hardcodedStrings . append ( line [ len ( ' Harcoded| ' ) + 1 : ] )
elif line . startswith ( ' Parameter ' ) :
2014-07-14 14:19:09 +02:00
self . addParameter ( getParameterFromString ( line ) )
2014-05-18 12:01:36 +02:00
elif line . startswith ( ' AllowUnmatching ' ) :
self . allowUnmatchingGridExtents = True
2013-10-01 20:52:22 +03:00
elif line . startswith ( ' Extent ' ) :
# An extent parameter that wraps 4 SAGA numerical parameters
self . extentParamNames = line [ 6 : ] . strip ( ) . split ( ' ' )
self . addParameter ( ParameterExtent ( self . OUTPUT_EXTENT ,
' Output extent ' , ' 0,1,0,1 ' ) )
2012-09-15 18:25:25 +03:00
else :
2014-07-14 14:19:09 +02:00
self . addOutput ( getOutputFromString ( line ) )
2013-10-01 20:52:22 +03:00
line = lines . readline ( ) . strip ( ' \n ' ) . strip ( )
2012-09-15 18:25:25 +03:00
lines . close ( )
def processAlgorithm ( self , progress ) :
2013-09-12 13:19:00 +02:00
if isWindows ( ) :
2012-09-15 18:25:25 +03:00
path = SagaUtils . sagaPath ( )
2013-10-01 20:52:22 +03:00
if path == ' ' :
raise GeoAlgorithmExecutionException (
' SAGA folder is not configured. \n Please configure \
it before running SAGA algorithms . ' )
2012-09-15 18:25:25 +03:00
commands = list ( )
self . exportedLayers = { }
2013-08-25 10:45:52 +02:00
2013-07-23 13:05:24 +02:00
self . preProcessInputs ( )
2012-09-15 18:25:25 +03:00
2013-10-01 20:52:22 +03:00
# 1: Export rasters to sgrd and vectors to shp
# Tables must be in dbf format. We check that.
2012-09-15 18:25:25 +03:00
for param in self . parameters :
if isinstance ( param , ParameterRaster ) :
2013-10-01 20:52:22 +03:00
if param . value is None :
2012-09-15 18:25:25 +03:00
continue
value = param . value
2013-10-01 20:52:22 +03:00
if not value . endswith ( ' sgrd ' ) :
2013-09-14 17:41:08 +02:00
exportCommand = self . exportRasterLayer ( value )
if exportCommand is not None :
commands . append ( exportCommand )
2012-09-15 18:25:25 +03:00
if isinstance ( param , ParameterVector ) :
2013-10-01 20:52:22 +03:00
if param . value is None :
2012-09-15 18:25:25 +03:00
continue
2013-09-12 13:19:00 +02:00
layer = dataobjects . getObjectFromUri ( param . value , False )
2012-09-15 18:25:25 +03:00
if layer :
2013-09-12 13:19:00 +02:00
filename = dataobjects . exportVectorLayer ( layer )
2013-10-01 20:52:22 +03:00
self . exportedLayers [ param . value ] = filename
elif not param . value . endswith ( ' shp ' ) :
raise GeoAlgorithmExecutionException (
' Unsupported file format ' )
2012-09-15 18:25:25 +03:00
if isinstance ( param , ParameterTable ) :
2013-10-01 20:52:22 +03:00
if param . value is None :
2012-09-15 18:25:25 +03:00
continue
2013-09-12 13:19:00 +02:00
table = dataobjects . getObjectFromUri ( param . value , False )
2013-02-16 00:20:38 +01:00
if table :
2013-09-12 13:19:00 +02:00
filename = dataobjects . exportTable ( table )
2013-10-01 20:52:22 +03:00
self . exportedLayers [ param . value ] = filename
elif not param . value . endswith ( ' shp ' ) :
raise GeoAlgorithmExecutionException (
' Unsupported file format ' )
2012-09-15 18:25:25 +03:00
if isinstance ( param , ParameterMultipleInput ) :
2013-10-01 20:52:22 +03:00
if param . value is None :
2012-09-15 18:25:25 +03:00
continue
2013-10-01 20:52:22 +03:00
layers = param . value . split ( ' ; ' )
if layers is None or len ( layers ) == 0 :
2012-09-15 18:25:25 +03:00
continue
if param . datatype == ParameterMultipleInput . TYPE_RASTER :
for layerfile in layers :
2013-10-01 20:52:22 +03:00
if not layerfile . endswith ( ' sgrd ' ) :
2013-09-15 18:45:11 +02:00
exportCommand = self . exportRasterLayer ( layerfile )
if exportCommand is not None :
2013-09-20 12:44:16 +02:00
commands . append ( exportCommand )
2012-09-15 18:25:25 +03:00
elif param . datatype == ParameterMultipleInput . TYPE_VECTOR_ANY :
for layerfile in layers :
2013-09-12 13:19:00 +02:00
layer = dataobjects . getObjectFromUri ( layerfile , False )
2012-09-15 18:25:25 +03:00
if layer :
2013-09-12 13:19:00 +02:00
filename = dataobjects . exportVectorLayer ( layer )
2013-10-01 20:52:22 +03:00
self . exportedLayers [ layerfile ] = filename
elif not layerfile . endswith ( ' shp ' ) :
raise GeoAlgorithmExecutionException (
' Unsupported file format ' )
2012-09-15 18:25:25 +03:00
2013-10-01 20:52:22 +03:00
# 2: Set parameters and outputs
2014-06-12 10:55:54 +02:00
saga208 = SagaUtils . isSaga208 ( )
2013-09-12 13:19:00 +02:00
if isWindows ( ) or isMac ( ) or not saga208 :
2013-10-01 20:52:22 +03:00
command = self . undecoratedGroup + ' " ' + self . cmdname + ' " '
2013-07-15 22:16:43 +02:00
else :
2013-10-01 20:52:22 +03:00
command = ' lib ' + self . undecoratedGroup + ' " ' + self . cmdname + ' " '
2013-07-12 16:27:06 +02:00
2013-03-28 21:24:35 +01:00
if self . hardcodedStrings :
for s in self . hardcodedStrings :
2013-10-01 20:52:22 +03:00
command + = ' ' + s
2013-03-31 21:18:27 +02:00
2012-09-15 18:25:25 +03:00
for param in self . parameters :
if param . value is None :
continue
2013-10-01 20:52:22 +03:00
if isinstance ( param , ( ParameterRaster , ParameterVector ,
ParameterTable ) ) :
2012-09-15 18:25:25 +03:00
value = param . value
if value in self . exportedLayers . keys ( ) :
2013-10-01 20:52:22 +03:00
command + = ' - ' + param . name + ' " ' \
+ self . exportedLayers [ value ] + ' " '
2012-09-15 18:25:25 +03:00
else :
2013-10-01 20:52:22 +03:00
command + = ' - ' + param . name + ' " ' + value + ' " '
2012-09-15 18:25:25 +03:00
elif isinstance ( param , ParameterMultipleInput ) :
s = param . value
for layer in self . exportedLayers . keys ( ) :
s = s . replace ( layer , self . exportedLayers [ layer ] )
2013-10-01 20:52:22 +03:00
command + = ' - ' + param . name + ' " ' + s + ' " '
2012-09-15 18:25:25 +03:00
elif isinstance ( param , ParameterBoolean ) :
if param . value :
2013-10-01 20:52:22 +03:00
command + = ' - ' + param . name
2012-09-15 18:25:25 +03:00
elif isinstance ( param , ParameterFixedTable ) :
2013-10-01 20:52:22 +03:00
tempTableFile = getTempFilename ( ' txt ' )
f = open ( tempTableFile , ' w ' )
f . write ( ' \t ' . join ( [ col for col in param . cols ] ) + ' \n ' )
values = param . value . split ( ' , ' )
2012-09-15 18:25:25 +03:00
for i in range ( 0 , len ( values ) , 3 ) :
2013-10-01 20:52:22 +03:00
s = values [ i ] + ' \t ' + values [ i + 1 ] + ' \t ' + values [ i
+ 2 ] + ' \n '
2012-09-15 18:25:25 +03:00
f . write ( s )
f . close ( )
2013-10-01 20:52:22 +03:00
command + = ' - ' + param . name + ' " ' + tempTableFile + ' " '
2012-09-15 18:25:25 +03:00
elif isinstance ( param , ParameterExtent ) :
2013-10-01 20:52:22 +03:00
# 'We have to substract/add half cell size, since SAGA is
# center based, not corner based
2012-10-20 21:38:46 +02:00
halfcell = self . getOutputCellsize ( ) / 2
2012-10-27 10:59:23 +02:00
offset = [ halfcell , - halfcell , halfcell , - halfcell ]
2013-10-01 20:52:22 +03:00
values = param . value . split ( ' , ' )
2012-09-15 18:25:25 +03:00
for i in range ( 4 ) :
2013-10-01 20:52:22 +03:00
command + = ' - ' + self . extentParamNames [ i ] + ' ' \
+ str ( float ( values [ i ] ) + offset [ i ] )
2012-09-15 18:25:25 +03:00
elif isinstance ( param , ( ParameterNumber , ParameterSelection ) ) :
2013-10-01 20:52:22 +03:00
command + = ' - ' + param . name + ' ' + str ( param . value )
2012-09-15 18:25:25 +03:00
else :
2013-10-01 20:52:22 +03:00
command + = ' - ' + param . name + ' " ' + str ( param . value ) + ' " '
2012-09-15 18:25:25 +03:00
for out in self . outputs :
if isinstance ( out , OutputRaster ) :
2013-03-23 21:44:20 +01:00
filename = out . getCompatibleFileName ( self )
2013-10-01 20:52:22 +03:00
filename + = ' .sgrd '
command + = ' - ' + out . name + ' " ' + filename + ' " '
2012-09-15 18:25:25 +03:00
if isinstance ( out , OutputVector ) :
2013-03-23 21:44:20 +01:00
filename = out . getCompatibleFileName ( self )
2013-10-01 20:52:22 +03:00
command + = ' - ' + out . name + ' " ' + filename + ' " '
2012-09-15 18:25:25 +03:00
if isinstance ( out , OutputTable ) :
2013-03-23 21:44:20 +01:00
filename = out . getCompatibleFileName ( self )
2013-10-01 20:52:22 +03:00
command + = ' - ' + out . name + ' " ' + filename + ' " '
2012-09-15 18:25:25 +03:00
commands . append ( command )
2013-10-01 20:52:22 +03:00
# 3: Export resulting raster layers
optim = ProcessingConfig . getSetting (
SagaUtils . SAGA_IMPORT_EXPORT_OPTIMIZATION )
2012-09-15 18:25:25 +03:00
for out in self . outputs :
if isinstance ( out , OutputRaster ) :
2013-01-21 23:05:17 +01:00
filename = out . getCompatibleFileName ( self )
2013-10-01 20:52:22 +03:00
filename2 = filename + ' .sgrd '
formatIndex = ( 4 if not saga208 and isWindows ( ) else 1 )
2013-09-15 13:53:33 +02:00
sessionExportedLayers [ filename ] = filename2
dontExport = True
2013-09-17 12:33:57 +02:00
2013-10-01 20:52:22 +03:00
# Do not export is the output is not a final output
# of the model
2014-10-31 11:04:15 +00:00
#if self.model is not None and optim:
# for subalg in self.model.algOutputs:
# if out.name in subalg:
# if subalg[out.name] is not None:
# dontExport = False
# break
# if dontExport:
# continue
2013-09-17 12:33:57 +02:00
2013-10-15 20:40:48 +01:00
if self . cmdname == ' RGB Composite ' :
2013-10-20 19:01:56 +02:00
if isWindows ( ) or isMac ( ) or not saga208 :
commands . append ( ' io_grid_image 0 -IS_RGB -GRID: " ' + filename2
2013-10-15 20:40:48 +01:00
+ ' " -FILE: " ' + filename
+ ' " ' )
2013-10-20 19:01:56 +02:00
else :
commands . append ( ' libio_grid_image 0 -IS_RGB -GRID: " ' + filename2
2013-10-15 20:40:48 +01:00
+ ' " -FILE: " ' + filename
+ ' " ' )
2013-07-15 22:16:43 +02:00
else :
2013-10-20 19:01:56 +02:00
if isWindows ( ) or isMac ( ) or not saga208 :
commands . append ( ' io_gdal 1 -GRIDS " ' + filename2
2013-10-15 20:40:48 +01:00
+ ' " -FORMAT ' + str ( formatIndex )
+ ' -TYPE 0 -FILE " ' + filename + ' " ' )
2013-10-20 19:01:56 +02:00
else :
commands . append ( ' libio_gdal 1 -GRIDS " ' + filename2
2013-10-15 20:40:48 +01:00
+ ' " -FORMAT 1 -TYPE 0 -FILE " ' + filename
+ ' " ' )
2013-08-25 10:45:52 +02:00
2013-10-01 20:52:22 +03:00
# 4: Run SAGA
2013-07-23 13:05:24 +02:00
commands = self . editCommands ( commands )
2012-09-15 18:25:25 +03:00
SagaUtils . createSagaBatchJobFileFromSagaCommands ( commands )
loglines = [ ]
2013-10-01 20:52:22 +03:00
loglines . append ( ' SAGA execution commands ' )
2012-09-15 18:25:25 +03:00
for line in commands :
progress . setCommand ( line )
loglines . append ( line )
2013-08-12 20:44:27 +02:00
if ProcessingConfig . getSetting ( SagaUtils . SAGA_LOG_COMMANDS ) :
ProcessingLog . addToLog ( ProcessingLog . LOG_INFO , loglines )
2013-10-01 20:52:22 +03:00
SagaUtils . executeSaga ( progress )
2012-12-10 00:12:07 +01:00
2013-07-23 13:05:24 +02:00
def preProcessInputs ( self ) :
2013-10-01 20:52:22 +03:00
name = self . commandLineName ( ) . replace ( ' . ' , ' _ ' ) [ len ( ' saga: ' ) : ]
2013-07-23 13:05:24 +02:00
try :
2014-04-17 01:41:25 +02:00
module = importlib . import_module ( ' processing.algs.saga.ext. ' + name )
2013-07-23 13:05:24 +02:00
except ImportError :
return
if hasattr ( module , ' preProcessInputs ' ) :
2013-10-01 20:52:22 +03:00
func = getattr ( module , ' preProcessInputs ' )
2013-07-23 13:05:24 +02:00
func ( self )
2013-08-25 10:45:52 +02:00
2013-07-23 13:05:24 +02:00
def editCommands ( self , commands ) :
name = self . commandLineName ( ) [ len ( ' saga: ' ) : ]
try :
2014-04-17 01:41:25 +02:00
module = importlib . import_module ( ' processing.algs.saga.ext. ' + name )
2013-07-23 13:05:24 +02:00
except ImportError :
return commands
if hasattr ( module , ' editCommands ' ) :
2013-10-01 20:52:22 +03:00
func = getattr ( module , ' editCommands ' )
2013-07-23 13:05:24 +02:00
return func ( commands )
else :
return commands
2012-10-20 21:38:46 +02:00
def getOutputCellsize ( self ) :
2013-10-01 20:52:22 +03:00
""" Tries to guess the cellsize of the output, searching for
a parameter with an appropriate name for it .
"""
cellsize = 0
2012-10-20 21:38:46 +02:00
for param in self . parameters :
2013-10-01 20:52:22 +03:00
if param . value is not None and param . name == ' USER_SIZE ' :
2012-10-20 21:38:46 +02:00
cellsize = float ( param . value )
2013-10-01 20:52:22 +03:00
break
2012-10-20 21:38:46 +02:00
return cellsize
2014-05-21 21:25:18 +02:00
2012-09-15 18:25:25 +03:00
2013-09-03 21:59:14 +02:00
def exportRasterLayer ( self , source ) :
2014-05-20 01:10:23 +02:00
global sessionExportedLayers
2013-09-14 17:41:08 +02:00
if source in sessionExportedLayers :
self . exportedLayers [ source ] = sessionExportedLayers [ source ]
return None
2013-09-12 13:19:00 +02:00
layer = dataobjects . getObjectFromUri ( source , False )
2013-09-02 00:54:25 +02:00
if layer :
filename = str ( layer . name ( ) )
else :
2013-09-13 12:05:01 +02:00
filename = os . path . basename ( source )
2013-10-01 20:52:22 +03:00
validChars = \
' abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789: '
2013-09-14 14:25:58 +02:00
filename = ' ' . join ( c for c in filename if c in validChars )
2013-09-02 00:54:25 +02:00
if len ( filename ) == 0 :
2013-10-01 20:52:22 +03:00
filename = ' layer '
destFilename = getTempFilenameInTempFolder ( filename + ' .sgrd ' )
self . exportedLayers [ source ] = destFilename
2013-09-14 17:41:08 +02:00
sessionExportedLayers [ source ] = destFilename
2014-06-12 10:55:54 +02:00
saga208 = SagaUtils . isSaga208 ( )
2013-10-16 15:08:17 +01:00
if saga208 :
2013-10-20 19:01:56 +02:00
if isWindows ( ) or isMac ( ) :
return ' io_gdal 0 -GRIDS " ' + destFilename + ' " -FILES " ' + source \
2013-10-16 15:08:17 +01:00
+ ' " '
2013-10-20 19:01:56 +02:00
else :
return ' libio_gdal 0 -GRIDS " ' + destFilename + ' " -FILES " ' \
2013-10-16 15:08:17 +01:00
+ source + ' " '
2012-09-15 18:25:25 +03:00
else :
2013-10-15 20:40:48 +01:00
return ' io_gdal 0 -TRANSFORM -INTERPOL 0 -GRIDS " ' + destFilename + ' " -FILES " ' + source \
2013-10-01 20:52:22 +03:00
+ ' " '
2013-09-03 21:59:14 +02:00
2013-03-31 21:18:27 +02:00
def checkBeforeOpeningParametersDialog ( self ) :
2013-04-12 17:18:51 +02:00
msg = SagaUtils . checkSagaIsInstalled ( )
2013-04-15 07:16:20 +02:00
if msg is not None :
2014-07-14 14:19:09 +02:00
print msg
2013-10-01 20:52:22 +03:00
html = ' <p>This algorithm requires SAGA to be run.Unfortunately, \
it seems that SAGA is not installed in your system , or it \
is not correctly configured to be used from QGIS < / p > '
2014-05-18 12:01:36 +02:00
html + = ' <p><a href= " http://docs.qgis.org/2.0/en/docs/user_manual/processing/3rdParty.html " > \
Click here < / a > to know more about how to install and configure SAGA to be used with QGIS < / p > '
2013-04-12 17:18:51 +02:00
return html
2013-03-26 14:15:12 +01:00
2013-03-12 00:00:36 +01:00
def checkParameterValuesBeforeExecuting ( self ) :
2013-10-01 20:52:22 +03:00
"""
2014-05-18 12:01:36 +02:00
We check that there are no multiband layers , which are not
supported by SAGA , and that raster layers have the same grid extent
2014-05-21 21:25:18 +02:00
"""
2014-05-18 12:01:36 +02:00
extent = None
2013-03-12 00:00:36 +01:00
for param in self . parameters :
2014-07-19 09:11:25 +02:00
files = [ ]
2014-05-21 21:25:18 +02:00
if isinstance ( param , ParameterRaster ) :
2014-07-18 09:57:37 +02:00
files = [ param . value ]
elif isinstance ( param , ParameterMultipleInput ) and param . datatype == ParameterMultipleInput . TYPE_RASTER :
2014-07-19 09:11:25 +02:00
if param . value is not None :
files = param . value . split ( " ; " )
2014-07-18 09:57:37 +02:00
for f in files :
layer = dataobjects . getObjectFromUri ( f )
2014-05-18 12:01:36 +02:00
if layer is None :
continue
if layer . bandCount ( ) > 1 :
2013-10-01 20:52:22 +03:00
return ' Input layer ' + str ( layer . name ( ) ) \
+ ' has more than one band. \n ' \
+ ' Multiband layers are not supported by SAGA '
2014-07-18 09:57:37 +02:00
if not self . allowUnmatchingGridExtents :
if extent is None :
extent = ( layer . extent ( ) , layer . height ( ) , layer . width ( ) )
else :
extent2 = ( layer . extent ( ) , layer . height ( ) , layer . width ( ) )
if extent != extent2 :
return " Input layers do not have the same grid extent. "
2014-05-21 21:25:18 +02:00
2012-09-15 18:25:25 +03:00
2014-04-19 00:48:56 +02:00
def help ( self ) :
name = self . cmdname . lower ( )
validChars = ' abcdefghijklmnopqrstuvwxyz '
2014-04-19 22:04:24 +02:00
name = ' ' . join ( c for c in name if c in validChars )
2014-04-19 00:48:56 +02:00
html = getHtmlFromRstFile ( os . path . join ( os . path . dirname ( __file__ ) , ' help ' ,
name + ' .rst ' ) )
2014-06-13 14:07:45 +02:00
if html is None :
return True , None
2014-04-19 00:48:56 +02:00
imgpath = os . path . join ( os . path . dirname ( __file__ ) , os . pardir , os . pardir , ' images ' , ' saga100x100.jpg ' )
html = ( ' <img src= " %s " /> ' % imgpath ) + html
return True , html
2013-02-28 22:08:32 +01:00
2013-07-18 17:16:16 +02:00
def getPostProcessingErrorMessage ( self , wrongLayers ) :
html = GeoAlgorithm . getPostProcessingErrorMessage ( self , wrongLayers )
msg = SagaUtils . checkSagaIsInstalled ( True )
2013-10-01 20:52:22 +03:00
html + = ' <p>This algorithm requires SAGA to be run. A test to check \
if SAGA is correctly installed and configured in your system \
has been performed , with the following result : < / p > < ul > < i > '
2013-07-18 17:16:16 +02:00
if msg is None :
2013-10-01 20:52:22 +03:00
html + = ' SAGA seems to be correctly installed and \
configured < / li > < / ul > '
2013-07-18 17:16:16 +02:00
else :
2013-10-01 20:52:22 +03:00
html + = msg + ' </i></li></ul> '
2014-04-19 17:37:15 +02:00
html + = ' <p><a href= " http://docs.qgis.org/2.0/en/docs/user_manual/processing/3rdParty.html " >Click here</a> to know more about how to install and configure SAGA to be used with QGIS</p> '
2013-02-28 22:08:32 +01:00
2013-07-18 17:16:16 +02:00
return html