|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | + |
| 3 | +""" |
| 4 | +*************************************************************************** |
| 5 | + r_colors_stddev.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 | + |
| 29 | +def processInputs(alg): |
| 30 | + # We need to import all the bands and to preserve color table |
| 31 | + raster = alg.getParameterValue('map') |
| 32 | + if raster in alg.exportedLayers.keys(): |
| 33 | + return |
| 34 | + |
| 35 | + alg.setSessionProjectionFromLayer(raster, alg.commands) |
| 36 | + destFilename = alg.getTempFilename() |
| 37 | + alg.exportedLayers[raster] = destFilename |
| 38 | + command = 'r.in.gdal input={} output={} --overwrite -o'.format(raster, destFilename) |
| 39 | + alg.commands.append(command) |
| 40 | + |
| 41 | + alg.setSessionProjectionFromProject(alg.commands) |
| 42 | + |
| 43 | + region = unicode(alg.getParameterValue(alg.GRASS_REGION_EXTENT_PARAMETER)) |
| 44 | + regionCoords = region.split(',') |
| 45 | + command = 'g.region' |
| 46 | + command += ' -a' |
| 47 | + command += ' n=' + unicode(regionCoords[3]) |
| 48 | + command += ' s=' + unicode(regionCoords[2]) |
| 49 | + command += ' e=' + unicode(regionCoords[1]) |
| 50 | + command += ' w=' + unicode(regionCoords[0]) |
| 51 | + cellsize = alg.getParameterValue(alg.GRASS_REGION_CELLSIZE_PARAMETER) |
| 52 | + if cellsize: |
| 53 | + command += ' res=' + unicode(cellsize) |
| 54 | + else: |
| 55 | + command += ' res=' + unicode(alg.getDefaultCellsize()) |
| 56 | + alignToResolution = alg.getParameterValue(alg.GRASS_REGION_ALIGN_TO_RESOLUTION) |
| 57 | + if alignToResolution: |
| 58 | + command += ' -a' |
| 59 | + alg.commands.append(command) |
| 60 | + |
| 61 | + |
| 62 | +def processCommand(alg): |
| 63 | + # We need to remove output |
| 64 | + output = alg.getOutputFromName('output') |
| 65 | + alg.exportedLayers[output.value] = output.name + alg.uniqueSufix |
| 66 | + alg.removeOutputFromName('output') |
| 67 | + alg.processCommand() |
| 68 | + alg.addOutput(output) |
| 69 | + |
| 70 | + |
| 71 | +def processOutputs(alg): |
| 72 | + # We need to export the raster with all its bands and its color table |
| 73 | + output = alg.getOutputValue('output') |
| 74 | + raster = alg.getParameterFromName('map') |
| 75 | + |
| 76 | + # Get the list of rasters matching the basename |
| 77 | + command = "r.out.gdal -t input={} output=\"{}\" createopt=\"TFW=YES,COMPRESS=LZW\"".format( |
| 78 | + alg.exportedLayers[raster.value], output) |
| 79 | + alg.commands.append(command) |
| 80 | + alg.outputCommands.append(command) |
0 commit comments