Hi. I'm trying to run a Python script in the field calculator to output the azimuth values of a series of polylines. However, everytime I try to run the code it throws the following error:
"File "<string>", line 2, in GetAzimuthPolyline
AttributeError: 'str' object has no attribute 'x'
Failed to execute (CalculateField)."
The code block I am using is:
- import math
- def GetAzimuthPolyline(shape):
- radian = math.atan((shape.lastpoint.x - shape.firstpoint.x)/(shape.lastpoint.y - shape.firstpoint.y))
- degrees = radian * 180 / math.pi
- return degrees
I sourced the code from this thread Calculate angle of each line in a polyline shapefile. It seems to be working for the people in the thread but not for me. I'm running Arc 10.1 with the basic license, by the way.
Can anyone see where this is going wrong?