I’m trying to write a script for converting degrees to radians in python. A common task and it would just be useful to have around. The problem I’m getting is that the input raster appears to be being read as a string. See below:
import arcpy
from arcpy import env
from arcpy.sa import *
import math
arcpy.CheckOutExtension("Spatial")
env.workspace = "C:\Users\OJB\Desktop\University\UsingRAS\UsingRas.gdb"
degrad = math.pi / 180
PythonRad = "Aspect_Deg" * degrad
outCos = Cos("PythonRad")
outCos.save("C:\Users\OJB\Desktop\University\UsingRAS\UsingRas.gdb\PyTest")
The error I get is:
Traceback (most recent call last):
File "C:/Users/OJB/Desktop/University/UsingRAS/Scripts/DegtoRad", line 11, in <module>
PythonRad = "Aspect_Deg" * degrad
TypeError: can't multiply sequence by non-int of type 'float'
I’m not sure how to use this raster without using the quote marks. I’m very new to Python so any help would be appreciated.
All the best
Use a raster object from the arcpy module to instantiate the raster:
Also, don’t forget to check your spatial analyst extension back in when you are done.