Skip to content
Permalink
Browse files

Fix indentation

  • Loading branch information
Médéric RIBREUX
Médéric RIBREUX committed Mar 7, 2016
1 parent 2275ce4 commit 5b11ba1a2bdceac178271132071254386c256e0b
@@ -28,19 +28,21 @@
import codecs
from processing.tools.system import getTempFilename


def checkParameterValuesBeforeExecuting(alg):
""" Verify if we have the right parameters """
rules = alg.getParameterValue(u'rules')
txtrules = alg.getParameterValue(u'txtrules')
raster = alg.getParameterValue(u'raster')

if rules and txtrules:
return alg.tr("You need to set either a rules file or write directly the rules !")
elif (rules and raster) or (txtrules and raster):
return alg.tr("You need to set either rules or a raster from which to copy categories !")

return None


def processInputs(alg):
# If there is another raster to copy categories from
# we need to import it with r.in.gdal rather than r.external
@@ -49,17 +51,17 @@ def processInputs(alg):
if copyRaster:
if copyRaster in alg.exportedLayers.keys():
return
for raster,method in (inputRaster, 'r.external'),(copyRaster, 'r.in.gdal'):

for raster, method in (inputRaster, 'r.external'), (copyRaster, 'r.in.gdal'):
alg.setSessionProjectionFromLayer(raster, alg.commands)

destFilename = alg.getTempFilename()
alg.exportedLayers[raster] = destFilename
command = '{} input={} output={} band=1 --overwrite -o'.format(method, raster, destFilename)
alg.commands.append(command)

alg.setSessionProjectionFromProject(alg.commands)

region = unicode(alg.getParameterValue(alg.GRASS_REGION_EXTENT_PARAMETER))
regionCoords = region.split(',')
command = 'g.region'
@@ -94,15 +96,15 @@ def processCommand(alg):
if txtRulesParam.value:
# Creates a temporary txt file
tempRulesName = getTempFilename('txt')

# Inject rules into temporary txt file
with codecs.open(tempRulesName, 'w', 'utf-8') as tempRules:
tempRules.write(txtRulesParam.value)

# Replace rules with temporary file
rules.value = tempRulesName
alg.parameters.remove(txtRulesParam)

alg.processCommand()

# We re-add the new output
@@ -57,9 +57,9 @@ def processOutputs(alg):
for method in methodList:
out = alg.getOutputValue(u'output')
for angle in angles:
inputRaster = "{}_{}{}".format(alg.exportedLayers[out], methodRef[method], angle)
outputFile = "{}/{}.{}".format(out, inputRaster, ext)
command = u"r.out.gdal --overwrite -c createopt=\"TFW=YES,COMPRESS=LZW\" input={} output=\"{}\"".format(
inputRaster, outputFile)
alg.commands.append(command)
alg.outputCommands.append(command)
inputRaster = "{}_{}{}".format(alg.exportedLayers[out], methodRef[method], angle)
outputFile = "{}/{}.{}".format(out, inputRaster, ext)
command = u"r.out.gdal --overwrite -c createopt=\"TFW=YES,COMPRESS=LZW\" input={} output=\"{}\"".format(
inputRaster, outputFile)
alg.commands.append(command)
alg.outputCommands.append(command)

0 comments on commit 5b11ba1

Please sign in to comment.
You can’t perform that action at this time.