Skip to content

Commit 3a9846b

Browse files
author
Médéric RIBREUX
committed
Add r.stats.quantile algorithm
1 parent 960f3a9 commit 3a9846b

File tree

3 files changed

+89
-0
lines changed

3 files changed

+89
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
r.stats.quantile
2+
r.stats.quantile.out - Compute category quantiles using two passes and output statistics
3+
Raster (r.*)
4+
ParameterRaster|base|Name of base raster map|False
5+
ParameterRaster|cover|Name of cover raster map|False
6+
ParameterString|quantiles|Number of quantiles|None|False|True
7+
ParameterString|percentiles|List of percentiles|None|False|True
8+
ParameterNumber|bins|Number of bins to use|0|None|1000|True
9+
*ParameterBoolean|-r|Create reclass map with statistics as category labels|False
10+
Hardcoded|-p
11+
OutputFile|output|Statistics File
12+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
r.stats.quantile
2+
r.stats.quantile.rast - Compute category quantiles using two passes and output rasters.
3+
Raster (r.*)
4+
ParameterRaster|base|Name of base raster map|False
5+
ParameterRaster|cover|Name of cover raster map|False
6+
ParameterNumber|quantiles|Number of quantiles|2|None|2|True
7+
ParameterString|percentiles|List of percentiles|None|False|True
8+
ParameterNumber|bins|Number of bins to use|0|None|1000|True
9+
*ParameterBoolean|-r|Create reclass map with statistics as category labels|False
10+
OutputDirectory|output_dir|Output Directory
11+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# -*- coding: utf-8 -*-
2+
3+
"""
4+
***************************************************************************
5+
r_stats_quantile_rast.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+
from processing.core.parameters import getParameterFromString
29+
import os
30+
31+
32+
def processCommand(alg):
33+
# We create the output sequence according to percentiles number
34+
base = alg.getParameterValue('base')
35+
quantiles = alg.getParameterValue('quantiles') - 1
36+
outputs = []
37+
for i in range(0, int(quantiles)):
38+
outputs.append('output_{}'.format(i))
39+
40+
output = getParameterFromString('ParameterString|output|Output Rasters|None|False|True')
41+
output.value = ','.join(outputs)
42+
alg.addParameter(output)
43+
44+
output_dir = alg.getOutputFromName('output_dir')
45+
alg.removeOutputFromName('output_dir')
46+
47+
# Launch the algorithm
48+
alg.processCommand()
49+
50+
# We re-add the previous output
51+
alg.addOutput(output_dir)
52+
53+
54+
def processOutputs(alg):
55+
# We need to export each of the output
56+
output_dir = alg.getOutputValue('output_dir')
57+
outputParam = alg.getParameterFromName('output')
58+
outputs = outputParam.value.split(',')
59+
alg.parameters.remove(outputParam)
60+
for output in outputs:
61+
command = u"r.out.gdal -c createopt=\"TFW=YES,COMPRESS=LZW\" input={} output=\"{}\" --overwrite".format(
62+
output,
63+
os.path.join(output_dir, output + '.tif')
64+
)
65+
alg.commands.append(command)
66+
alg.outputCommands.append(command)

0 commit comments

Comments
 (0)