Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add r.support (combined with r.timestamp) algorithm
  • Loading branch information
Médéric RIBREUX committed Feb 14, 2016
1 parent 2726093 commit 61fc094
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
14 changes: 14 additions & 0 deletions python/plugins/processing/algs/grass7/description/r.support.txt
@@ -0,0 +1,14 @@
r.support
Allows creation and/or modification of raster map layer support files (metadata).
Raster (r.*)
ParameterRaster|map|Name of raster map|False
ParameterString|title|Title for resultant raster map|None|False|True
ParameterString|timestamp|r.timestamp date: Datetime, datetime1/datetime2, or 'none' to remove'|None|False|True
ParameterString|history|Text to append to the next line of the map's metadata file|None|True|True
ParameterString|units|Text to use for map data units|None|False|True
ParameterString|vdatum|Text to use for map vertical datum|None|False|True
ParameterString|source1|Text to use for data source, line 1|None|False|True
ParameterString|source2|Text to use for data source, line 2|None|False|True
ParameterString|description|Text to use for data description or keyword(s)|None|False|True
*ParameterFile|loadhistory|Text file from which to load history|False
OutputRaster|output|Metadata
66 changes: 66 additions & 0 deletions python/plugins/processing/algs/grass7/ext/r_support.py
@@ -0,0 +1,66 @@
# -*- coding: utf-8 -*-

"""
***************************************************************************
r_support.py
------------
Date : February 2016
Copyright : (C) 2016 by Médéric Ribreux
Email : medspx at medspx dot fr
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************
"""

__author__ = 'Médéric Ribreux'
__date__ = 'February 2016'
__copyright__ = '(C) 2016, Médéric Ribreux'

# This will get replaced with a git SHA1 when you do a git archive

__revision__ = '$Format:%H$'

import os


def processCommand(alg):
# We temporary remove the output
out = alg.getOutputFromName('output')
mapParam = alg.getParameterValue('map')
alg.exportedLayers[out.value] = alg.exportedLayers[mapParam]
alg.removeOutputFromName('output')
timestamp = alg.getParameterValue('timestamp')
if timestamp:
command = "r.timestamp map={} date='{}'".format(alg.exportedLayers[mapParam],
timestamp)
alg.commands.append(command)
alg.parameters.remove(alg.getParameterFromName('timestamp'))
alg.processCommand()

# We re-add the new output
alg.addOutput(out)


def processOutputs(alg):
tags = {'title': 'TIFFTAG_DOCUMENTNAME', 'description': 'TIFFTAG_IMAGEDESCRIPTION',
'creator': 'TIFFTAG_ARTIST', 'timestamp': 'TIFFTAG_DATETIME',
'source1': 'TIFFTAG_COPYRIGHT', 'units': 'TIFFTAG_RESOLUTIONUNIT',
'source2': 'GRASS_SOURCE2', 'comments': 'GRASS_HISTORY', 'vdatum': 'GRASS_VDATUM'}
awk = "awk -F '=' '"
for support, tag in tags.items():
awk = '{0} /{1}=".+"/{{ print \"{2}=\"substr($0,{3},length($0) - {3})"," }}'.format(
awk, support, tag, len(support) + 3)

# Output results ('from' table and output table)
out = alg.getOutputValue('output')
command = u"SDF=$(r.info -e map={} | {}')".format(alg.exportedLayers[out], awk)
alg.commands.append(command)
command = u"r.out.gdal --overwrite -c createopt=\"TFW=YES,COMPRESS=LZW\" input={} output=\"{}\" metaopt=\"${{SDF%%,}}\"".format(
alg.exportedLayers[out], out)
alg.commands.append(command)
alg.outputCommands.append(command)

0 comments on commit 61fc094

Please sign in to comment.