Skip to content
Browse files

Add square brackets around the saved expression

When saving a raster expression the generated expression didn't contain square brackets around the letters used for band identifiers. Sticking with the NDVI example:

("NIR@1" - "Red@1") / ("NIR@1" + "Red@1")


(a - b) / (a + b)

Due to the way the expression is parsed these would not be interactie parameters for the user to set as the parameters requre square brackets around the layer tags. This change simply updates the string replacement to include the square brackets so you would get instead:

([a] - [b]) / ([a] + [b])
  • Loading branch information
om-henners authored and nyalldawson committed Sep 14, 2020
1 parent 09ea6be commit 1312cfe599604b8f6e80ec7c219915e339e2174a
Showing with 1 addition and 1 deletion.
  1. +1 −1 python/plugins/processing/algs/qgis/ui/
@@ -188,7 +188,7 @@ def savePredefined(self):
used = [v for v in self.options.values() if v in exp]

for i, v in enumerate(used):
exp = exp.replace(v, chr(97 + i))
exp = exp.replace(v, f'[{chr(97 + i)}]')

dlg = AddNewExpressionDialog(exp)

0 comments on commit 1312cfe

Please sign in to comment.
You can’t perform that action at this time.