I have a model authored in ModelBuilder that uses "RasterCalculator" to process input raster datasets.

 arcpy.gp.RasterCalculator_sa("OutRas = Con(\"%STATIC_forestland%\"  ==  0, -255, Con(\"%mapvictoria20121210%\" >= 115, -255, Con((\"%mapvictoria20121210%\" >100) & (\"%mapvictoria20121210%\" < 115), 100, Con(\"%mapvictoria20121210%\" <= -15, -255, Con((\"%mapvictoria20121210%\" < 0) & (\"%mapvictoria20121210%\" > -15), 0, \"%mapvictoria20121210%\")))))", mapvic1)

It works well as a model. However, when exported to a Python script and saved in the same Toolbox, the script does not work.

The error message is as below

RuntimeError: ERROR 000732: Input Raster: Dataset %mapvictoria20121210% does not exist or is not supported

Failed to execute (RasterCalculator).

I am sure the input raster are there. Can anyone give some help? Is it to do with raster naming issues?

  • 3
    In my experience the Export to Python script-function is not fail safe, and usually only provides a not too bad starting point for a script. I can't remember any non-trivial model that I converted to a script which worked right away. Post your full script and you might get some hints on what is wrong :) – Martin Jul 26 '13 at 7:01
  • 2
    The percent symbols appear to be hardcoded, which I assume is from using them as variables in model builder. – Paul Jul 26 '13 at 7:07
  • The percent symbols are hardcoded from conversion from Model Builder to Python. – alextc Jul 29 '13 at 1:54

The following might help you some:

stat = "STATIC_forestland"    
vict = "mapvictoria20121210"   
con = 'OutRas = Con("{0}" == 0, -255, Con("{1}" >= 115, -255, 
       Con(("{1}" > 100) & ("{1}" < 115), 100, Con("{1}" <= -15, -255, 
       Con(("{1}" < 0) & ("{1}" > -15), 0, "{1}")))))'.format(stat, vict)

arcpy.gp.RasterCalculator_sa(con, mapvic1)
| improve this answer | |

From the ArcGIS help:

The Raster Calculator tool is intended for use in the ArcGIS 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.

You need to use the Spatial Analyst module map algebra syntax instead.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.