1

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?

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Jul 26, 2013 at 6:58
3
  • 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 :) Commented Jul 26, 2013 at 7:01
  • 2
    The percent symbols appear to be hardcoded, which I assume is from using them as variables in model builder. Commented Jul 26, 2013 at 7:07
  • The percent symbols are hardcoded from conversion from Model Builder to Python. Commented Jul 29, 2013 at 1:54

2 Answers 2

6

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.

answered Jul 27, 2013 at 6:20
0
3

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)
answered Jul 26, 2013 at 7:18
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.