Reviewed

Score300

Please can we include the ability to calculate the angle of rotation from north into the attribute on a two vertex line. i can do this with Iankos tools but ArcGIS 10 needs the script in python which isnt available!

- Comment • 10

Reviewed

Score300

Please can we include the ability to calculate the angle of rotation from north into the attribute on a two vertex line. i can do this with Iankos tools but ArcGIS 10 needs the script in python which isnt available!

#import math somewhere....

#Function to return the north azimuth bearing of a line segment in degrees

def NorthAzimuth(x1,y1,x2,y2):

degBearing = math.degrees(math.atan2((x2 - x1),(y2 - y1)))

if (degBearing < 0):

degBearing += 360.0

return degBearing

This uses atan2 the wrong way round of course, but the rotation effect gives us north azimuth angles.

I have been playing with your script but come up against a problem that it doesnt seem to like field calculator in Arc 10 my script is below can anyone see why it says i have parsing problems...

thanks in advance

David

Field = NorthAzimuth(x1,y1,x2,y2)

Codeblock:

def NorthAzimuth(x1,y1,x2,y2):

degBearing = math.degrees(math.atan2((!Shape.lastPoint.X! - !Shape.firstPoint.X!),(!Shape.lastPoint.Y! - !Shape.firstPoint.Y!)))

if (degBearing < 0):

degBearing += 360.0

return degBearing

Not sure if Ian Ko will provide this with Easy Calculate 10. He is definitely saying it won't be available for 10.1. Bummer his stuff is great. I've tried to reproduce this calculation in Python with no success. Am not familiar with VBA so it it tough to translate to python.

Agree with the user below, any ESRI Solution should handle multi-vertex lines not just simple 2 vertex lines.

I believe Linear Directional Mean (Spatial Statistics Toolbox) will work for my purposes. Just wanted to share, hate to hijack the suggestions box.

The tool is intended to calculate the mean direction of multiple lines; however there is a Case Field option that will compute the 'Compass' angle for each feature. If you use a unique ID field as the Case Field, angle is calculated for each respective feature. Then it's just a cursor or join/calculate operation to populate the original FC with the output FC from Linear Directional Mean.

Use with caution: there are nuiances between spatial reference files and other variables that may generate inaccurate angle values. My results match Easy Calculates resutls sometimes, sometimes they are off by as much as a degree. This may/may not fit a given need; in my case it's acceptable error. Hope this is helpful to someone.

Dave

Dave

thanks,

George