Conditional evaluation

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:

Special Variable Names For Use In Conditional Statements
NameDescription
valueThe grid cell value.
nodataThe input raster's NoData value.
nullThe input raster's NoData value.
minvalueThe input raster's minimum value.
maxvalueThe input raster's maximum value.
displayminvalueThe input raster's minimum displayed value.
displaymaxvalueThe input raster's maximum displayed value.
rowsThe input raster's number of rows.
columnsThe input raster's number of columns.
rowThe grid cell's row number.
columnThe grid cell's column number.
rowyThe row's y-coordinate.
columnxThe column's x-coordinate.
northThe input raster's northern coordinate.
southThe input raster's southern coordinate.
eastThe input raster's eastern coordinate.
westThe input raster's western coordinate.
cellsizexThe input raster's grid resolution in the x-direction.
cellsizeyThe 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.

See Also:

Scripting:

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)

Credits: