Skip to content

Commit 4e92a13

Browse files
author
Médéric RIBREUX
committed
Fix r.colors rules
1 parent 0119646 commit 4e92a13

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

python/plugins/processing/algs/grass7/description/r.colors.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Raster (r.*)
44
ParameterMultipleInput|map|Name of raster maps(s)|3|False
55
ParameterSelection|color|Name of color table|not selected;aspect;aspectcolr;bcyr;bgyr;blues;byg;byr;celsius;corine;curvature;differences;elevation;etopo2;evi;fahrenheit;gdd;greens;grey;grey.eq;grey.log;grey1.0;grey255;gyr;haxby;kelvin;ndvi;ndwi;oranges;population;population_dens;precipitation;precipitation_daily;precipitation_monthly;rainbow;ramp;random;reds;rstcurv;ryb;ryg;sepia;slope;srtm;srtm_plus;terrain;wave|0|False|True
66
ParameterString|rules_txt|Color rules|None|True|True
7-
ParameterFile|rules|Color rules file|True
7+
ParameterFile|rules|Color rules file|False|True
88
ParameterRaster|raster|Raster map from which to copy color table|True
99
ParameterBoolean|-r|Remove existing color table|False
1010
ParameterBoolean|-w|Only write new color table if it does not already exist|False

python/plugins/processing/algs/grass7/ext/r_colors.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
def checkParameterValuesBeforeExecuting(alg):
3232
""" Verify if we have the right parameters """
33-
if alg.getParameterValue(u'rules_txt') and alg.getParameterValue(u'rules'):
33+
if alg.getParameterValue('rules_txt') and alg.getParameterValue('rules'):
3434
return alg.tr("You need to set either inline rules or a rules file !")
3535

3636
return None
@@ -79,19 +79,34 @@ def processCommand(alg):
7979
if color.value == 0:
8080
alg.parameters.remove(color)
8181

82-
# TODO Handle rules
82+
# Handle rules
83+
txtRules = alg.getParameterFromName('rules_txt')
84+
if txtRules.value:
85+
# Creates a temporary txt file
86+
tempRulesName = alg.getTempFilename()
87+
88+
# Inject rules into temporary txt file
89+
with open(tempRulesName, "w") as tempRules:
90+
tempRules.write(txtRules.value)
91+
92+
# Use temporary file as rules file
93+
alg.setParameterValue('rules', tempRulesName)
94+
alg.parameters.remove(txtRules)
95+
8396
alg.processCommand()
8497

8598
# re-add the previous output
8699
alg.addOutput(output)
100+
alg.addParameter(color)
101+
alg.addParameter(txtRules)
87102

88103

89104
def processOutputs(alg):
90105
# Export all rasters with their color tables (and their bands)
91106
rasters = [alg.exportedLayers[f] for f in alg.getParameterValue('map').split(',')]
92107
output_dir = alg.getOutputValue('output_dir')
93108
for raster in rasters:
94-
command = u"r.out.gdal createopt=\"TFW=YES,COMPRESS=LZW\" input={} output=\"{}\" --overwrite".format(
109+
command = u"r.out.gdal -t createopt=\"TFW=YES,COMPRESS=LZW\" input={} output=\"{}\" --overwrite".format(
95110
raster,
96111
os.path.join(output_dir, raster + '.tif')
97112
)

0 commit comments

Comments
 (0)