# Name: Con_Ex_02.py
# Description: Performs a conditional if/else evaluation
# on each pixel of an input raster.
# Requirements: Image Analyst Extension
# Import system modules
import arcpy
from arcpy import env
from arcpy.ia import *
# Set environment settings
env.workspace = "C:/output"
# Set local variables
inRaster = Raster("elevation")
inTrueRaster = 1
inFalseConstant = 0
whereClause = "VALUE >= 1500"
# Check out the ArcGIS Image Analyst extension license
arcpy.CheckOutExtension("ImageAnalyst")
# Execute Con and save the output
outCon = Con(inRaster, inTrueRaster, inFalseConstant, whereClause)
outCon.save("C:/output/outcon.tif")
# Execute Con using a map algebra expression instead of a where clause, and save the output.
outCon2 = Con(inRaster >= 1500, inTrueRaster, inFalseConstant)
outCon2.save("C:/output/outcon2.tif")