Solved Raster Calculator And Con Statement Esri Community
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. Illustration 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.
When the input raster has rectangular cells, it will be processed so that the output raster cells will be square with sides equal to the average of the rectangular length and width. See Analysis environments and Spatial Analyst for additional details on the geoprocessing environments that apply to this tool. Parameters Con(in_conditional_raster, in_true_raster_or_constant, {in_false_raster_or_constant}, {where_clause}) Return Value Code sample In this example, the original value will be retained in the output when the input conditional raster value is greater than2000; the value will be NoData when it is not.
import arcpy from arcpy import env from arcpy.sa import * env.workspace = "C:/sapyexamples/data" outCon = Con("elevation", "elevation", "", "VALUE > 2000") outCon.save("C:/sapyexamples/output/outcon.img") # Execute Con using a map algebra expression instead of a where clause outCon2 = Con(Raster("elevation") > 2000, "elevation") outCon2.save("C:/sapyexamples/output/outcon2") In this example, the original value will be retained in the output except NoData, which will be replaced with 0.
import arcpy from arcpy import env from arcpy.sa import * env.workspace = "C:/sapyexamples/data" outCon = Con(IsNull("elevation"),0, "elevation") outCon.save("C:/sapyexamples/output/outcon") In this example, two different rasters are used to create the conditional raster. import arcpy from arcpy import env from arcpy.sa import * env.workspace = "C:/sapyexamples/data" inRaster1 = Raster("landuse") inRaster2 = Raster("landuse2") outCon = Con(((inRaster1 == 1) & (inRaster2 == 5)), inRaster1 + inRaster2, 99) outCon.save("C:/sapyexamples/output/outcon") In this example, multiple Con tools are used inside a Con.
import arcpy from arcpy import env from arcpy.sa import * env.workspace = "C:/sapyexamples/data" inRas1 = Raster("inRaster") outCon = Con(inRas1 < 45,1, Con((inRas1 >= 45) & (inRas1 < 47),2, Con((inRas1 >= 47) & (inRas1 < 49),3, Con(inRas1 >= 49,4)))) outCon.save("C:/sapyexamples/output/outcon") In this example, when the value of the input conditional raster is greater than or equal to 1500, the output value will be 1; when it is less than 1500, the output value will be 0.
# Name: Con_Ex_02.py # Description: Performs a conditional if/else evaluation # on each cell of an input raster.
# Requirements: Spatial Analyst Extension # Import system modules import arcpy from arcpy import env from arcpy.sa import * # Set environment settings env.workspace = "C:/sapyexamples/data" # Set local variables inRaster = Raster("elevation") inTrueRaster = 1 inFalseConstant = 0 whereClause = "VALUE >= 1500" # Execute Con outCon = Con(inRaster, inTrueRaster, inFalseConstant, whereClause) # Execute Con using a map algebra expression instead of a where clause outCon2 = Con(inRaster >= 1500, inTrueRaster, inFalseConstant) # Save the outputs outCon.save("C:/sapyexamples/output/outcon") outCon2.save("C:/sapyexamples/output/outcon2") Environments Licensing information - Basic: Requires Spatial Analyst or Image Analyst - Standard: Requires Spatial Analyst or Image Analyst - Advanced: Requires Spatial Analyst or Image Analyst
People Also Asked
- Solved: Raster calculator and Con statement - Esri Community
- Con (Spatial Analyst)—ArcGIS Pro | Documentation - Esri
- Solved: Con statement with raster calculator - Esri Community
- Solved: Con Statement issue in Raster Calculator - Esri Community
- Solved: Raster calculator - Esri Community
- ArcGIS Pro Tutorial: How to Use Raster Calculator in ArcGIS Pro for ...
- Multiple CON Expression in ArcGIS Raster Calculator
- Using the Raster Calculator for Map Algebra - mapping 101
Solved: Raster calculator and Con statement - Esri Community?
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. Illustration 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 w...
Con (Spatial Analyst)—ArcGIS Pro | Documentation - Esri?
When the input raster has rectangular cells, it will be processed so that the output raster cells will be square with sides equal to the average of the rectangular length and width. See Analysis environments and Spatial Analyst for additional details on the geoprocessing environments that apply to this tool. Parameters Con(in_conditional_raster, in_true_raster_or_constant, {in_false_raster_or_cons...
Solved: Con statement with raster calculator - Esri Community?
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. Illustration 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 w...
Solved: Con Statement issue in Raster Calculator - Esri Community?
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 c...
Solved: Raster calculator - Esri Community?
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.