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.

  • Just curious, what does the '180 +' do here? – Rex Jun 19 '17 at 21:29

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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