Raster calculator: Python script from Model Builder: Does not work

1402
2
08-19-2011 12:05 PM
ZiaAhmed
New Contributor III
Following script imported from Model builder. I want run it for other states,  it did not work. If python does not support  "arcpy.gp.RasterCalculator_sa" funtion, if there any away to perform following expresion using a python script?

Raster calculator expresion: Con("ia_corn" == 1,"soilmu_in_90")
Where ia_corn is a binary gird ( 1 and 0) and soilmi_in_90 an interger grid.  I want to import values from soilmi_in_90  to ia_corn.

# ---------------------------------------------------------------------------
# cornMUKEY.py
# Created on: 2011-08-19 15:54:25.00000
#   (generated by ArcGIS/ModelBuilder)
# Description:
# ---------------------------------------------------------------------------

# Import arcpy module
import arcpy

# Check out any necessary licenses
arcpy.CheckOutExtension("spatial")

# Local variables:
in_corn ="K:\\CropLand\\STATE.gdb\\in_corn"
soilmu_in_90 = "K:\\STATE_ MUKEY\\RASTER.gdb\\soilmu_in_90"
csoilmu_in = "K:\\STATE_ MUKEY\\CORN_MUKEY.gdb\\csoilmu_in"

# Process: Raster Calculator
arcpy.gp.RasterCalculator_sa("Con(\"%in_corn%\" == 1,\"%soilmu_in_90%\")", csoilmu_in)
print arcpy.GetMessages


Warning (from warnings module):
  File "<string>", line 1
SyntaxWarning: import * only allowed at module level

Traceback (most recent call last):
  File "K:\SCRIPT\Python_Script\cornMUKEY.py", line 21, in <module>
    arcpy.gp.RasterCalculator_sa("Con(\"%in_corn%\" == 1,\"%soilmu_in_90%\")", csoilmu_in)
  File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\geoprocessing\_base.py", line 474, in <lambda>
    return lambda *args: val(*gp_fixargs(args))
ExecuteError: ERROR 000539: Error running expression: rcexec() <type 'exceptions.RuntimeError'>: ERROR 000732: Input Raster: Dataset %soilmu_in_90% does not exist or is not supported
Failed to execute (RasterCalculator).
Tags (2)
0 Kudos
2 Replies
AlexChen
New Contributor III
I know this is an outdated post, but I am really keen to know if anyone can help with it. I am having now exactly the same question.
0 Kudos
RhettZufelt
MVP Frequent Contributor
Note:The Raster Calculator tool is intended for use in the ArcGIS for Desktop application only as a GP tool dialog box or in ModelBuilder. It is not intended for use in scripting and is not available in the ArcPy Spatial Analyst module.


Note:In Python, Map Algebra expressions should be created and executed with the Spatial Analyst module, which is an extension of the ArcPy Python site package.

See Map Algebra in Spatial Analyst to learn about how to perform your analysis in Python.
  http://resources.arcgis.com/en/help/main/10.1/index.html#//00p600000002000000

R_
0 Kudos