AnsweredAssumed Answered

Calculating polyline azimuth - code error

Question asked by CRootes on Aug 5, 2014
Latest reply on Feb 19, 2015 by david.harbor

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:

  1. import math 
  2. def GetAzimuthPolyline(shape): 
  3. radian = math.atan((shape.lastpoint.x - shape.firstpoint.x)/(shape.lastpoint.y - shape.firstpoint.y)) 
  4. degrees = radian * 180 / math.pi 
  5. 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?

Outcomes