Error: unsupported operand type(s) for /: 'str' and 'float' when converted to Python

2957
2
06-01-2011 07:57 AM
DavidClapp
New Contributor
Hi,

I converted a model to Python but I received an error message when trying to calculate slope cost. I believe that it has to do with Python treating the resulting slope as a string in the formula and that I need to somehow convert forest_slope from a string to a float but anything that I have tried does not seem to work. Any suggestions are appreciated. Forest is a DEM layer.

# Calculate the slope across the surface.

arcpy.gp.Slope_sa(forest, forest_slope, "DEGREE", "1")

# Calculate the slope cost based upon a nonlinear trigonometric cost function.

arcpy.gp.RasterCalculator_sa("Sin((\"%forest_slope%\")/57.2958)*200", forest_slope_cost)

ERROR 000539: Error running expression: rcexec() <type 'exceptions.TypeError'>: unsupported operand type(s) for /: 'str' and 'float'

Failed to execute (RasterCalculator).
Tags (2)
0 Kudos
2 Replies
JakeSkinner
Esri Esteemed Contributor
I would try using the commands outside of the Raster Calculator.  Ex:

import arcpy
from arcpy import sa
from arcpy.sa import *

arcpy.CheckOutExtension("spatial")

forest = r"c:\test.gdb\forest"

forest_slope = arcpy.sa.Slope(forest, "DEGREE", "1")
sin = arcpy.sa.Sin(forest_slope)
divide = arcpy.sa.Divide(sin, 57.2958)
multiply = arcpy.sa.Times(divide, 200)

multiply.save(r"c:\test.gdb\forest_slope_cost")
0 Kudos
DavidClapp
New Contributor
This worked, it maintained the type raster. The conversion of the spatial analyst tools from Model Maker to Python results in script type outputs which caused the errors. Thanks much!
0 Kudos