Skip to content

Commit 2cb249c

Browse files
author
Médéric RIBREUX
committed
Add r.series.interp algorithm
1 parent af48246 commit 2cb249c

File tree

2 files changed

+90
-0
lines changed

2 files changed

+90
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
r.series.interp
2+
Interpolates raster maps located (temporal or spatial) in between input raster maps at specific sampling positions.
3+
Raster (r.*)
4+
ParameterMultipleInput|input|Input raster layer(s)|3.0|False
5+
ParameterString|datapos|Data point position for each input map|None|True|True
6+
ParameterFile|infile|Input file with one input raster map name and data point position per line, field separator between name and sample point is '|'|True
7+
ParameterString|output|Name for output raster map (comma separated list if multiple|None|False|True
8+
ParameterString|samplingpos|Sampling point position for each output map (comma separated list)|None|True|True
9+
ParameterFile|outfile|Input file with one output raster map name and sample point position per line, field separator between name and sample point is '|'|True
10+
ParameterSelection|method|Interpolation method, currently only linear interpolation is supported|linear|0
11+
OutputDirectory|output_dir|Interpolated rasters
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# -*- coding: utf-8 -*-
2+
3+
"""
4+
***************************************************************************
5+
r_series_interp.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 codecs
29+
from processing.tools.system import getTempFilename
30+
from os import path
31+
32+
33+
def checkParameterValuesBeforeExecuting(alg):
34+
""" Verify if we have the right parameters """
35+
datapos = alg.getParameterValue(u'datapos')
36+
infile = alg.getParameterValue(u'infile')
37+
output = alg.getParameterValue(u'output')
38+
outfile = alg.getParameterValue(u'outfile')
39+
40+
if datapos and infile:
41+
return alg.tr("You need to set either inline data positions or an input data positions file !")
42+
if output and outfile:
43+
return alg.tr("You need to set either sampling data positions or an output sampling data positions file !")
44+
if not (datapos or infile or output or outfile):
45+
return alg.tr("You need to set input and output data positions parameters !")
46+
return None
47+
48+
49+
def processCommand(alg):
50+
# We temporary remove the output directory
51+
outdir = alg.getOutputFromName('output_dir')
52+
alg.removeOutputFromName('output_dir')
53+
54+
alg.processCommand()
55+
56+
# We re-add the new output
57+
alg.addOutput(outdir)
58+
59+
60+
def processOutputs(alg):
61+
# We take all the outputs and we export them to the output directory
62+
outdir = alg.getOutputFromName('output_dir')
63+
output = alg.getParameterValue('output')
64+
outfile = alg.getParameterValue('outfile')
65+
outs = []
66+
if output:
67+
outs = output.split(',')
68+
elif outfile:
69+
# Handle file manually to find the name of the layers
70+
with open(outfile) as f:
71+
for line in f:
72+
if '|' in line:
73+
outs.append(line.split('|')[0])
74+
75+
for out in outs:
76+
command = u"r.out.gdal --overwrite -t -c createopt=\"TFW=YES,COMPRESS=LZW\" input={} output=\"{}\"".format(
77+
out, path.join(outdir.value, '{}.tif'.format(out)))
78+
alg.commands.append(command)
79+
alg.outputCommands.append(command)

0 commit comments

Comments
 (0)