Select to view content in your preferred language

Custom Single Output Map Algebra Script

911
3
08-09-2010 10:59 AM
DanielLusher
Deactivated User
Hi,

I'm trying to create a custom Single Output Map Algebra script so that I can have my user input values to run a model in Model Builder.  As of now, I cannot find a way to connect SOMA to a variable in Model Builder, and saw no answer on a thread on that subject.  Therefore I turned to python, but I am fairly new with python, so I was hoping someone could spot the error I've made in creating this script.

import sys, string, os, arcgisscripting

gp = arcgisscripting.create(9.3)
gp.overwriteoutput = 1

msgNotEnoughParams = 'Incorrect number of input parameters.'

if len(sys.argv) < 1: raise Exception, msgNotEnoughParams
DEMraster = gp.GetParameterasText(0)
inputValue1 = gp.GetParameterasText(1)
inputValue2 = gp.GetParameterasText(2)
inputValue3 = gp.GetParameterasText(3)
outputRaster = gp.GetParameterasText(4)
xmap = gp.GetParameterasText(5)
ymap = gp.GetParameterasText(6)

gp.SingleOutputMapAlgebra_sa("ATan((" + inputValue3 + " - " + DEMraster + ") // ( sqrt(sqr(" + inputValue1 + " - " + xmap + ") + sqr(" + inputValue2 + " - " + ymap + "))))")


I'm currently getting this error:
<class 'arcgisscripting.ExecuteError'>: Failed to execute. Parameters are not valid.
ERROR 000859: The required parameter Output raster is empty, or is not the type of Raster Dataset.
Failed to execute (SingleOutputMapAlgebra).

Failed to execute (CustomMapAlgebra).

Any help on why this is happening would be much appreciated!
0 Kudos
3 Replies
Luke_Pinner
MVP Regular Contributor
ERROR 000859: The required parameter Output raster is empty, or is not the type of Raster Dataset.

The error message is pretty self-explanatory. You don't specify an output raster parameter.
The syntax is: gp.SingleOutputMapAlgebra_sa(InExpression, OutRaster)

See Single" rel="nofollow" target="_blank">http://webhelp.esri.com/arcgisdesktop/9.3/index.cfm?TopicName... Output Map Algebra help.
0 Kudos
DanielLusher
Deactivated User
Ah. That was what I was missing. I thought it was refering to the parameters list above, and could not figure out what was different above it.  Thank you.
0 Kudos
MarcioMoraes
New Contributor
I'm trying to create a custom Single Output Map Algebra script so that I can have my user input values to run using python. My python code is:

# ---------------------------------------------------------------------------
# rad226_67.py
# Created on: Thu Nov 24 2011 11:13:19 AM
#   (generated by ArcGIS/ModelBuilder)
# ---------------------------------------------------------------------------

# Import system modules
import sys, string, os, arcgisscripting, glob

# Create the Geoprocessor object
gp = arcgisscripting.create()

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

# Load required toolboxes...
gp.AddToolbox("C:/Program Files (x86)/ArcGIS/ArcToolbox/Toolboxes/Spatial Analyst Tools.tbx")

# Local variables...
imdir = 'E:\\223_67'        #
os.chdir(imdir)             #
path = '*.tif'              #
lista_in  = glob.glob(path)     #
lista_out = ["E:\\223_67\\rad_223_67_B1.tif", "E:\\223_67\\rad_223_67_B2.tif", "E:\\223_67\\rad_223_67_B3.tif",]
#v226_67_rad_tif = "E:\\223_67_rad.tif"
nimg = [0,1,3]

for i in nimg:
    print i
    img_in = lista_in
    print img_in
    img_out = lista_out
    print img_out
    # Process: Single Output Map Algebra...
    gp.SingleOutputMapAlgebra_sa("- 1.52 + "+ img_in + " * ( 169 + 1.52 ) / 255", img_out, "")

When I ran for one image no errors, but for more I´m currently getting this error:
0
LANDSAT_5_TM_20100617_223_067_L2_BAND1.tif
E:\223_67\rad_223_67_B1.tif
1
LANDSAT_5_TM_20100617_223_067_L2_BAND2.tif
E:\223_67\rad_223_67_B2.tif

Traceback (most recent call last):
  File "C:\Work2011\INPE\landsat\rad226_67.py", line 37, in <module>
    gp.SingleOutputMapAlgebra_sa("- 1.52 + "+ img_in + " * ( 169 + 1.52 ) / 255", img_out, "")
ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000865: Map Algebra expression: LANDSAT_5_TM_20100617_223_067_L2_BAND2.tif does not exist.
Failed to execute (SingleOutputMapAlgebra).

Any help on why this is happening would be much appreciated!
Thanks
0 Kudos