Quantcast
Channel: Forums - Python
Viewing all articles
Browse latest Browse all 2485

difficulty calculating field in Python

$
0
0
Hi All,
I'm having difficulty calculating a field in my Python script. I have a bunch of polylines and I want to get the azimuth for each line in degrees.
This is where my code crashes (the math module has already been imported):

Code:

fieldName3 = "Azimuth"
expression2 = "180+math.atan2(( !Shape.firstpoint.X! - !Shape.lastpoint.X! ),( !Shape.firstpoint.Y! - !Shape.lastpoint.Y! ) ) * (180 / math.pi )"
arcpy.CalculateField_management(outFeatureClass, "Azimuth", expression2, "PYTHON")

I get an arcgisscripting.ExecuteError: ERROR 000539:
The confusing thing is I can paste the same code in the field calculator and it works fine.

Thanks in advance for you help,
Jason

Viewing all articles
Browse latest Browse all 2485

Trending Articles