mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-13 00:03:09 -04:00
Fix r.colors rules
This commit is contained in:
parent
0119646bd3
commit
4e92a132d2
@ -4,7 +4,7 @@ Raster (r.*)
|
||||
ParameterMultipleInput|map|Name of raster maps(s)|3|False
|
||||
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
|
||||
ParameterString|rules_txt|Color rules|None|True|True
|
||||
ParameterFile|rules|Color rules file|True
|
||||
ParameterFile|rules|Color rules file|False|True
|
||||
ParameterRaster|raster|Raster map from which to copy color table|True
|
||||
ParameterBoolean|-r|Remove existing color table|False
|
||||
ParameterBoolean|-w|Only write new color table if it does not already exist|False
|
||||
|
@ -30,7 +30,7 @@ import os
|
||||
|
||||
def checkParameterValuesBeforeExecuting(alg):
|
||||
""" Verify if we have the right parameters """
|
||||
if alg.getParameterValue(u'rules_txt') and alg.getParameterValue(u'rules'):
|
||||
if alg.getParameterValue('rules_txt') and alg.getParameterValue('rules'):
|
||||
return alg.tr("You need to set either inline rules or a rules file !")
|
||||
|
||||
return None
|
||||
@ -79,11 +79,26 @@ def processCommand(alg):
|
||||
if color.value == 0:
|
||||
alg.parameters.remove(color)
|
||||
|
||||
# TODO Handle rules
|
||||
# Handle rules
|
||||
txtRules = alg.getParameterFromName('rules_txt')
|
||||
if txtRules.value:
|
||||
# Creates a temporary txt file
|
||||
tempRulesName = alg.getTempFilename()
|
||||
|
||||
# Inject rules into temporary txt file
|
||||
with open(tempRulesName, "w") as tempRules:
|
||||
tempRules.write(txtRules.value)
|
||||
|
||||
# Use temporary file as rules file
|
||||
alg.setParameterValue('rules', tempRulesName)
|
||||
alg.parameters.remove(txtRules)
|
||||
|
||||
alg.processCommand()
|
||||
|
||||
# re-add the previous output
|
||||
alg.addOutput(output)
|
||||
alg.addParameter(color)
|
||||
alg.addParameter(txtRules)
|
||||
|
||||
|
||||
def processOutputs(alg):
|
||||
@ -91,7 +106,7 @@ def processOutputs(alg):
|
||||
rasters = [alg.exportedLayers[f] for f in alg.getParameterValue('map').split(',')]
|
||||
output_dir = alg.getOutputValue('output_dir')
|
||||
for raster in rasters:
|
||||
command = u"r.out.gdal createopt=\"TFW=YES,COMPRESS=LZW\" input={} output=\"{}\" --overwrite".format(
|
||||
command = u"r.out.gdal -t createopt=\"TFW=YES,COMPRESS=LZW\" input={} output=\"{}\" --overwrite".format(
|
||||
raster,
|
||||
os.path.join(output_dir, raster + '.tif')
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user