|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | + |
| 3 | +""" |
| 4 | +*************************************************************************** |
| 5 | + r_series_interp.py |
| 6 | + ------------------ |
| 7 | + Date : February 2016 |
| 8 | + Copyright : (C) 2016 by Médéric Ribreux |
| 9 | + Email : medspx at medspx dot fr |
| 10 | +*************************************************************************** |
| 11 | +* * |
| 12 | +* This program is free software; you can redistribute it and/or modify * |
| 13 | +* it under the terms of the GNU General Public License as published by * |
| 14 | +* the Free Software Foundation; either version 2 of the License, or * |
| 15 | +* (at your option) any later version. * |
| 16 | +* * |
| 17 | +*************************************************************************** |
| 18 | +""" |
| 19 | + |
| 20 | +__author__ = 'Médéric Ribreux' |
| 21 | +__date__ = 'February 2016' |
| 22 | +__copyright__ = '(C) 2016, Médéric Ribreux' |
| 23 | + |
| 24 | +# This will get replaced with a git SHA1 when you do a git archive |
| 25 | + |
| 26 | +__revision__ = '$Format:%H$' |
| 27 | + |
| 28 | +import codecs |
| 29 | +from processing.tools.system import getTempFilename |
| 30 | +from os import path |
| 31 | + |
| 32 | + |
| 33 | +def checkParameterValuesBeforeExecuting(alg): |
| 34 | + """ Verify if we have the right parameters """ |
| 35 | + datapos = alg.getParameterValue(u'datapos') |
| 36 | + infile = alg.getParameterValue(u'infile') |
| 37 | + output = alg.getParameterValue(u'output') |
| 38 | + outfile = alg.getParameterValue(u'outfile') |
| 39 | + |
| 40 | + if datapos and infile: |
| 41 | + return alg.tr("You need to set either inline data positions or an input data positions file !") |
| 42 | + if output and outfile: |
| 43 | + return alg.tr("You need to set either sampling data positions or an output sampling data positions file !") |
| 44 | + if not (datapos or infile or output or outfile): |
| 45 | + return alg.tr("You need to set input and output data positions parameters !") |
| 46 | + return None |
| 47 | + |
| 48 | + |
| 49 | +def processCommand(alg): |
| 50 | + # We temporary remove the output directory |
| 51 | + outdir = alg.getOutputFromName('output_dir') |
| 52 | + alg.removeOutputFromName('output_dir') |
| 53 | + |
| 54 | + alg.processCommand() |
| 55 | + |
| 56 | + # We re-add the new output |
| 57 | + alg.addOutput(outdir) |
| 58 | + |
| 59 | + |
| 60 | +def processOutputs(alg): |
| 61 | + # We take all the outputs and we export them to the output directory |
| 62 | + outdir = alg.getOutputFromName('output_dir') |
| 63 | + output = alg.getParameterValue('output') |
| 64 | + outfile = alg.getParameterValue('outfile') |
| 65 | + outs = [] |
| 66 | + if output: |
| 67 | + outs = output.split(',') |
| 68 | + elif outfile: |
| 69 | + # Handle file manually to find the name of the layers |
| 70 | + with open(outfile) as f: |
| 71 | + for line in f: |
| 72 | + if '|' in line: |
| 73 | + outs.append(line.split('|')[0]) |
| 74 | + |
| 75 | + for out in outs: |
| 76 | + command = u"r.out.gdal --overwrite -t -c createopt=\"TFW=YES,COMPRESS=LZW\" input={} output=\"{}\"".format( |
| 77 | + out, path.join(outdir.value, '{}.tif'.format(out))) |
| 78 | + alg.commands.append(command) |
| 79 | + alg.outputCommands.append(command) |
0 commit comments