|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | + |
| 3 | +""" |
| 4 | +*************************************************************************** |
| 5 | + r_stats_quantile_rast.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 | +from processing.core.parameters import getParameterFromString |
| 29 | +import os |
| 30 | + |
| 31 | + |
| 32 | +def processCommand(alg): |
| 33 | + # We create the output sequence according to percentiles number |
| 34 | + base = alg.getParameterValue('base') |
| 35 | + quantiles = alg.getParameterValue('quantiles') - 1 |
| 36 | + outputs = [] |
| 37 | + for i in range(0, int(quantiles)): |
| 38 | + outputs.append('output_{}'.format(i)) |
| 39 | + |
| 40 | + output = getParameterFromString('ParameterString|output|Output Rasters|None|False|True') |
| 41 | + output.value = ','.join(outputs) |
| 42 | + alg.addParameter(output) |
| 43 | + |
| 44 | + output_dir = alg.getOutputFromName('output_dir') |
| 45 | + alg.removeOutputFromName('output_dir') |
| 46 | + |
| 47 | + # Launch the algorithm |
| 48 | + alg.processCommand() |
| 49 | + |
| 50 | + # We re-add the previous output |
| 51 | + alg.addOutput(output_dir) |
| 52 | + |
| 53 | + |
| 54 | +def processOutputs(alg): |
| 55 | + # We need to export each of the output |
| 56 | + output_dir = alg.getOutputValue('output_dir') |
| 57 | + outputParam = alg.getParameterFromName('output') |
| 58 | + outputs = outputParam.value.split(',') |
| 59 | + alg.parameters.remove(outputParam) |
| 60 | + for output in outputs: |
| 61 | + command = u"r.out.gdal -c createopt=\"TFW=YES,COMPRESS=LZW\" input={} output=\"{}\" --overwrite".format( |
| 62 | + output, |
| 63 | + os.path.join(output_dir, output + '.tif') |
| 64 | + ) |
| 65 | + alg.commands.append(command) |
| 66 | + alg.outputCommands.append(command) |
0 commit comments