Get line direction/orientation as a numeric field

42978
15
05-01-2011 08:48 PM
AlanAitken
New Contributor
Should be a simple one here.


How do I get ArcGIS 10 to return the orientation (or direction) of each line in a polyline feature into a field.

what do I need to type into field calculator (or is there a better way)

Ta
Alan
Tags (2)
0 Kudos
15 Replies
FrédéricPRALLY
Esri Contributor
Hi,

To calculate angle of lines fill calculate values with parser python using this python line:

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


Hope this help you,

Best regards,

Fred
AlanAitken
New Contributor
Thanks Fred,

Trig seems obvious now, but good to get the python syntax

Works

Alan
0 Kudos
SteveFeeney
New Contributor II
Is there any means to attribute a field of a Polyline with the line bearing within a model? I have a model I need to package and distribute to other operators who are still using 9.3. Ideally it needs as few add-ons as possible to function.


Thank you,
Steve
0 Kudos
SteveFeeney
New Contributor II
Please disregard my last post.
Some revision and self education later and I can see it has already been answered above.

When I input the python code, I'm using the "Calculate Field" management tool with expression type as "Python 9.3". The function calculates fine but returns different values to the ones I manually measured using MA. Am I using it correctly?
Kind regards,
Steve
0 Kudos
AlexanderBeavis
New Contributor II
So does this code provide the bearing of a polyline with reference to north?
0 Kudos
chriss_
New Contributor II
Hi!
I wanted to use the Code to define the deviation from north in degree. Where north would be 0 east 90 south 180 and west 270. So I changed the code to this:

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

So far so good, BUT for everything in western direction I get a negative value eg. -90 instead of 270.

Any mathematical genius that can enlighten me?
Thanks
Chris
0 Kudos
BradyCallahan
New Contributor III
The radians thing didn't help me either so I used this to return a North Azimuth based reference. Hope it helps someone...


Field (type double) = NorthAzimuth( !Shape! )

Codeblock:

def NorthAzimuth(Pline):
  degBearing = math.degrees(math.atan2((Pline.lastPoint.X - Pline.firstPoint.X),(Pline.lastPoint.Y - Pline.firstPoint.Y)))
  if (degBearing < 0):
      degBearing += 360.0
  return degBearing
by Anonymous User
Not applicable

Thank you! it worked !

0 Kudos
SteveFeeney
New Contributor II
This may be a bit basic,

There is a tool called 'Linear Directional Mean' that will create and populate a compass bearing field with the mean direction of a shapefile/featureclass or, if you use a unique field, for each feature.

As far as I can tell it is planar rather than geodesic but it's a sound, quick fix and saves coding trig.