|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | + |
| 3 | +""" |
| 4 | +*************************************************************************** |
| 5 | + r_what_color.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 color tables of the input rasters |
| 31 | + raster = alg.getParameterValue('input') |
| 32 | + if raster in alg.exportedLayers.keys(): |
| 33 | + return |
| 34 | + |
| 35 | + destFilename = alg.getTempFilename() |
| 36 | + alg.exportedLayers[raster] = destFilename |
| 37 | + command = 'r.in.gdal input={} output={} --overwrite -o'.format(raster, destFilename) |
| 38 | + alg.commands.append(command) |
| 39 | + |
| 40 | + alg.setSessionProjectionFromProject(alg.commands) |
| 41 | + |
| 42 | + region = unicode(alg.getParameterValue(alg.GRASS_REGION_EXTENT_PARAMETER)) |
| 43 | + regionCoords = region.split(',') |
| 44 | + command = 'g.region' |
| 45 | + command += ' -a' |
| 46 | + command += ' n=' + unicode(regionCoords[3]) |
| 47 | + command += ' s=' + unicode(regionCoords[2]) |
| 48 | + command += ' e=' + unicode(regionCoords[1]) |
| 49 | + command += ' w=' + unicode(regionCoords[0]) |
| 50 | + cellsize = alg.getParameterValue(alg.GRASS_REGION_CELLSIZE_PARAMETER) |
| 51 | + if cellsize: |
| 52 | + command += ' res=' + unicode(cellsize) |
| 53 | + else: |
| 54 | + command += ' res=' + unicode(alg.getDefaultCellsize()) |
| 55 | + alignToResolution = alg.getParameterValue(alg.GRASS_REGION_ALIGN_TO_RESOLUTION) |
| 56 | + if alignToResolution: |
| 57 | + command += ' -a' |
| 58 | + alg.commands.append(command) |
0 commit comments