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?
-
3In 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– Martin2013年07月26日 07:01:52 +00:00Commented Jul 26, 2013 at 7:01
-
2The percent symbols appear to be hardcoded, which I assume is from using them as variables in model builder.Paul– Paul2013年07月26日 07:07:30 +00:00Commented Jul 26, 2013 at 7:07
-
The percent symbols are hardcoded from conversion from Model Builder to Python.alextc– alextc2013年07月29日 01:54:28 +00:00Commented Jul 29, 2013 at 1:54
2 Answers 2
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.
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)
Explore related questions
See similar questions with these tags.