Is This Content Helpful?
We're glad to know this article was helpful.
When running a Python script exported from ModelBuilder that includes a Raster Calculator function, the code fails because it is not able to run the rcexec() expression. The following error message is returned:
"ERROR 000539: Error running expression: rcexec()"
This error is due to Raster Calculator not being exposed to Python as a tool. Currently, Raster Calculator is only exposed as a geoprocessing tool in ArcGIS or in ModelBuilder. However, there are a number of different ways to use Raster Calculator functions in Python.
This example shows how Python can use the Spatial Analyst Math toolset to perform mathematic functions on raster datasets, in a stand-alone script that can be run outside of the arcmap process.
# Name: Minus_Ex_02.py
# Description: Subtracts the value of the second input raster from the
# value of the first input raster on a cell-by-cell basis
# Requirements: Spatial Analyst Extension
# Import system modules
from arcpy import env
from arcpy.sa import *
# Set environment settings
env.workspace = "C:/sapyexamples/data"
# Set local variables
inRaster1 = "degs"
inRaster2 = "negs"
# Check out the ArcGIS Spatial Analyst extension license
# Execute Minus to subtract inRaster2 from inRaster1
outMinus = Minus(inRaster1, inRaster2)
# Save the output