Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am looking for a Python code block to calculate azimuth per each polyline feature. So far I have been able to use the following Python code to calculate bearing:

180  + math.atan2(( !Shape.firstpoint.X! - !Shape.lastpoint.X! ),
(!Shape.firstpoint.Y! - !Shape.lastpoint.Y! ) ) * (180 / math.pi)

However bearing is not sufficient for me as I am looking to ultimately find line directions which can be detected by caclulating an azimuth.

share|improve this question

Not in arcpy but the math is pretty clear. From Bill Huber in 2004.

How do I compute azimuth for line segment and add to attribute table

z = (-y/x).ATan.AsDegrees
if (x < 0) then z = z+180 end ' Adjust ATan in quadrants II and III
z = -(z + 180 mod 360 - 180)  ' Convert to the range -180..180
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.