Skip to content

Commit d5b5c6c

Browse files
author
Médéric RIBREUX
committed
Add r.support (combined with r.timestamp) algorithm
1 parent 9198c16 commit d5b5c6c

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
r.support
2+
Allows creation and/or modification of raster map layer support files (metadata).
3+
Raster (r.*)
4+
ParameterRaster|map|Name of raster map|False
5+
ParameterString|title|Title for resultant raster map|None|False|True
6+
ParameterString|timestamp|r.timestamp date: Datetime, datetime1/datetime2, or 'none' to remove'|None|False|True
7+
ParameterString|history|Text to append to the next line of the map's metadata file|None|True|True
8+
ParameterString|units|Text to use for map data units|None|False|True
9+
ParameterString|vdatum|Text to use for map vertical datum|None|False|True
10+
ParameterString|source1|Text to use for data source, line 1|None|False|True
11+
ParameterString|source2|Text to use for data source, line 2|None|False|True
12+
ParameterString|description|Text to use for data description or keyword(s)|None|False|True
13+
*ParameterFile|loadhistory|Text file from which to load history|False
14+
OutputRaster|output|Metadata
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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

Comments
 (0)