|
30 | 30 |
|
31 | 31 | def checkParameterValuesBeforeExecuting(alg):
|
32 | 32 | """ 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'): |
34 | 34 | return alg.tr("You need to set either inline rules or a rules file !")
|
35 | 35 |
|
36 | 36 | return None
|
@@ -79,19 +79,34 @@ def processCommand(alg):
|
79 | 79 | if color.value == 0:
|
80 | 80 | alg.parameters.remove(color)
|
81 | 81 |
|
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 | + |
83 | 96 | alg.processCommand()
|
84 | 97 |
|
85 | 98 | # re-add the previous output
|
86 | 99 | alg.addOutput(output)
|
| 100 | + alg.addParameter(color) |
| 101 | + alg.addParameter(txtRules) |
87 | 102 |
|
88 | 103 |
|
89 | 104 | def processOutputs(alg):
|
90 | 105 | # Export all rasters with their color tables (and their bands)
|
91 | 106 | rasters = [alg.exportedLayers[f] for f in alg.getParameterValue('map').split(',')]
|
92 | 107 | output_dir = alg.getOutputValue('output_dir')
|
93 | 108 | 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( |
95 | 110 | raster,
|
96 | 111 | os.path.join(output_dir, raster + '.tif')
|
97 | 112 | )
|
|
0 commit comments