|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | + |
| 3 | +""" |
| 4 | +*************************************************************************** |
| 5 | + r_support.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 os |
| 29 | + |
| 30 | + |
| 31 | +def processCommand(alg): |
| 32 | + # We temporary remove the output |
| 33 | + out = alg.getOutputFromName('output') |
| 34 | + mapParam = alg.getParameterValue('map') |
| 35 | + alg.exportedLayers[out.value] = alg.exportedLayers[mapParam] |
| 36 | + alg.removeOutputFromName('output') |
| 37 | + timestamp = alg.getParameterValue('timestamp') |
| 38 | + if timestamp: |
| 39 | + command = "r.timestamp map={} date='{}'".format(alg.exportedLayers[mapParam], |
| 40 | + timestamp) |
| 41 | + alg.commands.append(command) |
| 42 | + alg.parameters.remove(alg.getParameterFromName('timestamp')) |
| 43 | + alg.processCommand() |
| 44 | + |
| 45 | + # We re-add the new output |
| 46 | + alg.addOutput(out) |
| 47 | + |
| 48 | + |
| 49 | +def processOutputs(alg): |
| 50 | + tags = {'title': 'TIFFTAG_DOCUMENTNAME', 'description': 'TIFFTAG_IMAGEDESCRIPTION', |
| 51 | + 'creator': 'TIFFTAG_ARTIST', 'timestamp': 'TIFFTAG_DATETIME', |
| 52 | + 'source1': 'TIFFTAG_COPYRIGHT', 'units': 'TIFFTAG_RESOLUTIONUNIT', |
| 53 | + 'source2': 'GRASS_SOURCE2', 'comments': 'GRASS_HISTORY', 'vdatum': 'GRASS_VDATUM'} |
| 54 | + awk = "awk -F '=' '" |
| 55 | + for support, tag in tags.items(): |
| 56 | + awk = '{0} /{1}=".+"/{{ print \"{2}=\"substr($0,{3},length($0) - {3})"," }}'.format( |
| 57 | + awk, support, tag, len(support) + 3) |
| 58 | + |
| 59 | + # Output results ('from' table and output table) |
| 60 | + out = alg.getOutputValue('output') |
| 61 | + command = u"SDF=$(r.info -e map={} | {}')".format(alg.exportedLayers[out], awk) |
| 62 | + alg.commands.append(command) |
| 63 | + command = u"r.out.gdal --overwrite -c createopt=\"TFW=YES,COMPRESS=LZW\" input={} output=\"{}\" metaopt=\"${{SDF%%,}}\"".format( |
| 64 | + alg.exportedLayers[out], out) |
| 65 | + alg.commands.append(command) |
| 66 | + alg.outputCommands.append(command) |
0 commit comments