Calculating angles of lines using pyscripting

1255
1
09-14-2016 09:45 PM
GoldenJiang
New Contributor II

I am trying to put together a tool for calculating the angles of lines but I keep getting this error: "Parameters are not valid. ERROR000735".  I am new learning arcpy, can anyone tell me what have I done wrong here? 

import arcpy
import math
in_table = arcpy.GetParameterAsText(0)
field = arcpy.GetParameterAsText(1)
arcpy.AddField_management(in_table, "angle", "DOUBLE")
expression = "GetAzimuthPolyline(!shape!)"
codeblock = """def GetAzimuthPolyline(shape):
 radian = math.atan((shape.lastpoint.y - shape.firstpoint.y)
 /(shape.lastpoint.x - shape.firstpoint.x))
 degrees = radian * 180/math.pi
 return degrees"""
arcpy.CalculateField_management(in_table,'angle',expression,'PYTHON',codeblock)

0 Kudos
1 Reply
DanPatterson_Retired
MVP Emeritus

throw a print statement after line 5 and print the two parameter values.  If you are running this in standalone mode and not associate with a user tool, a full path would be needed

PS  !Shape!  proper case is needed