Con (Spatial Analyst)

ArcGIS Pro 3.4 | | Help archive

Available with Spatial Analyst license.

Available with Image Analyst license.

Summary

Performs a conditional if/else evaluation on each of the input cells of an input raster.

Learn more about performing conditional evaluation with Con

Illustration

Con illustration
OutRas = Con(InRas1, 40, 30, "Value >= 2")

Usage

  • If either the true raster or the optional false raster is floating point, the output raster will be floating point. If both the true expression and the optional false raster are integer, the output raster will be integer.

  • If the Input conditional raster (in_conditional_raster in Python) is a single-band raster and either the Input true raster or constant value (in_true_raster_or_constant In Python) raster or the optional Input false raster or constant value (in_false_raster_or_constant In Python) raster is a constant, the output will be a single-band raster.

  • If all inputs are multiband rasters, the output will be a multiband raster. The output raster will also be multiband if either the true input or the optional false input is a constant. The number of bands in each multiband input must be the same.

  • The tool will perform the operation on each band from the conditional raster using the corresponding band from the other inputs. If the conditional input is a multiband raster and the true or false raster input is a constant, the tool will perform the operation using the constant value for each band in the multiband input.

  • If the evaluation of the expression is nonzero, it is treated as true.

  • If no Input false raster or constant value is specified, NoData will be assigned to those cells that do not result in true from the expression.

  • If NoData does not satisfy the expression, it does not receive the value of the input false raster; it remains NoData.

  • The Expression uses an SQL query. See the following topics for details on creating queries:

  • In order to use a {where_clause} in Python, it should be enclosed in quotes. For example, "Value > 5000".

    You can consult the help for more information on specifying a query in Python.

  • In Python, you can avoid using a {where_clause} that specifies the Value field by using a Map Algebra expression as the in_conditional_raster instead.

    For example, the following expression:

    • Con("elev", 0, 1, "value > 1000")

    can be rewritten as follows:

    • Con(Raster("elev") > 1000, 0, 1)

    For more information, see the code samples listed below or review Build complex statements in Map Algebra.

  • The maximum length of the logical expression is 4,096 characters.

  • If at least one of the inputs are multidimensional raster data with the same number of variables, the tool will perform the operation for all slices with the same dimension value. The output will be a multidimensional raster in CRF format. The variables in the inputs must have at least one common dimension and one common dimensional value for this tool to process; otherwise. an error will occur.

    If any two inputs are multidimensional rasters and share one variable but with different names, uncheck the Match Multidimensional Variable geoprocessing environment (set arcpy.env.matchMultidimensionalVariable = False in Python) before running the tool.

    If the Input conditional raster value is a multidimensional raster and the Input true raster or constant value and Input false raster or constant value parameters are set to constant values, the tool will perform the operation for all slices for all variables using the constant values, and the output will be a multidimensional raster.

  • See Analysis environments and Spatial Analyst for additional details on the geoprocessing environments that apply to this tool.

Parameters

LabelExplanationData Type
Input conditional raster

The input raster representing the true or false result of the desired condition.

It can be of integer or floating point type.

Raster Layer
Input true raster or constant value

The input whose values will be used as the output cell values if the condition is true.

It can be an integer or a floating-point raster, or a constant value.

Raster Layer; Constant
Input false raster or constant value
(Optional)

The input whose values will be used as the output cell values if the condition is false.

It can be an integer or a floating-point raster, or a constant value.

Raster Layer; Constant
Expression
(Optional)

A logical expression that determines which of the input cells are to be true or false.

The Where clause follows the general form of an SQL expression. It can be entered directly, for example, VALUE > 100, if you click the Edit SQL mode button SQL Query. If in the Edit Clause Mode Edit Clause, you can begin constructing the expression by clicking on the Add Clause Mode button.

SQL Expression

Return Value

LabelExplanationData Type
Output raster

The output raster.

Raster

Licensing information

  • Basic: Requires Spatial Analyst or Image Analyst
  • Standard: Requires Spatial Analyst or Image Analyst
  • Advanced: Requires Spatial Analyst or Image Analyst

Related topics