The Conditional Evaluation tool can be used to perform an if-then-else style conditional evaluation on a raster image on a cell-to-cell basis. The user specifies the names of an input raster image and an output raster. The grid cell values in the output image will be determined by the TRUE and FALSE values and a conditional statement. The conditional statement is a logical Boolean expression that must evaluate to either TRUE or FALSE, i.e. a Boolean value. Then depending on how this statement evaluates for each grid cell, the TRUE or FALSE values will be assigned to the corresponding cells of the output raster. The TRUE or FALSE values may take the form of either a constant numerical value or a raster image (which may be the same image as the input).
The conditional statement is a single-line logical condition, expressed using Groovy language syntax. Groovy is a scripting language similar to Python. In additon to the common comparison and logical operators, i.e. < > <= >= == (EQUAL TO) != (NOT EQUAL TO) || (OR) && (AND), there are a number of variables available to build conditional statements. These include the following:
Name | Description |
---|---|
value | The grid cell value. |
nodata | The input raster's NoData value. |
null | The input raster's NoData value. |
minvalue | The input raster's minimum value. |
maxvalue | The input raster's maximum value. |
displayminvalue | The input raster's minimum displayed value. |
displaymaxvalue | The input raster's maximum displayed value. |
rows | The input raster's number of rows. |
columns | The input raster's number of columns. |
row | The grid cell's row number. |
column | The grid cell's column number. |
rowy | The row's y-coordinate. |
columnx | The column's x-coordinate. |
north | The input raster's northern coordinate. |
south | The input raster's southern coordinate. |
east | The input raster's eastern coordinate. |
west | The input raster's western coordinate. |
cellsizex | The input raster's grid resolution in the x-direction. |
cellsizey | The input raster's grid resolution in the y-direction. |
The special variable names are case-sensitive. Each of the special variable names can also be used as valid TRUE or FALSE constant values.
The following are examples of valid conditional statements:
value != 300.0
row > (rows / 2)
value >= (minvalue + 35.0)
(value >= 25.0) && (value <= 75.0)
The Conditional Evaluation tool is replicated by the IF operator in the Raster Calculator. Any grid cell in the input raster containing the NoData value will be assigned NoData in the output raster, unless a NoData grid cell value allows the conditional statement to evaluate to True (i.e. the conditional statement includes the NoData value), in which case the True value will be assigned to the output.
The following is an example of a Python script that uses this tool:
inputFile = "\some_directory\input.dep"
conditionalStatment = "value < (maxvalue - 100.0)"
trueValue = "\some_directory\input.dep"
falseValue = "\some_directory\some_other_image.dep"
outputFile = "\some_directory\output.dep"
args = [inputFile, conditionalStatment, trueValue, falseValue, outputFile]
pluginHost.runPlugin("ConditionalEvaluation", args, False)
This is a Groovy script also using the tool:
def inputFile = "\some_directory\input.dep"
def conditionalStatment = "value > 652.7"
def trueValue = "\some_directory\input.dep"
def falseValue = "nodata"
def outputFile = "\some_directory\output.dep"
String[] args = [inputFile, conditionalStatment, trueValue, falseValue, outputFile]
pluginHost.runPlugin("ConditionalEvaluation", args, false)