Angle between internal polyline line segments

4591
3
10-28-2010 07:19 AM
AustinDavis
New Contributor III
Hello,

Is there a way to find the angle between internal polyline segments?  I do not want to find the azimuth or bearing of each line segment; but rather, the "turn angle" at each segment junction if one was to travel along the entire polyline. I am using ArcGIS 9.3-- Any help would be much appreciated!
0 Kudos
3 Replies
AustinDavis
New Contributor III
Thanks- I'll take a look at it!

I've yet to program in python but I have a lot of VB experience.
0 Kudos
KimOllivier
Occasional Contributor III
If all you want is the bearing differences of vertices within a single polyline then a cursor can step through the vertices and calculate the angles like this:
# vertex_angle.py
# find change in angle along a polyline at each vertex
# assume :
# in a projected coordinate system, not dd
# don't know what to do with output, maybe add value to a point
# Kim Ollivier
# 29 October 2010
#
import arcgisscripting
import math
import sys

gp = arcgisscripting.create(9.3)

try:
    inlay = sys.argv[1]
except :
    inlay = "d:/work/test.gdb/wiggle"
desc = gp.Describe(inlay)
shapefield = desc.ShapeFieldName
cur = gp.SearchCursor(inlay)
row = cur.next()
n = 0
m = 0
p = 0
while row:
    feat = row.getValue(shapefield)
    print "Feature",n
    for partNum in range(feat.partCount) :
        part = feat.getPart(partNum)
        ptLast = None
        bearingLast = None
        print "Part",m
        for ptNum in range(part.count):
            pt = part.next() 
            if ptLast:
                bearing = math.atan2((pt.Y - ptLast.Y),(pt.X - ptLast.X))
                if bearingLast:
                    delta = bearing - bearingLast
                    print p,delta/math.pi*180.0
                bearingLast = bearing
            ptLast = pt
            p+=1
        m+=1
    n+=1
    row = cur.next()
del cur,row

Otherwise getting the vertices required is a lot harder if you do not have arc-node topology available. You would have this in a coverage if you built for nodes.

This provides a unique list of nodes and tags on each "polyline" for the node at each end in the attribute tables AAT and NAT. I could then run a valence script to count the number of segments at each node to assist with the angle calculations. A simple extension of the valence concept can tag nodes as sources, sinks or passthrough. I know that a network dataset has all these capabilites, but the relationships and status are not accessible for python scripting, so I build my own network attributes.

To build arc-node topology that is accessible for scripting in ArcGIS there is a very good tool in ET GEOTools called RenodePolylines. To get implied nodes at a T junction, clean the layer to a temporary layer using ETGeotools CleanPolyline in the absence of workstation clean. I would make sure there were no multi-parts to complicate the calculations.

It is easy to then select each node and do some angle calculations between each segment. Rather than run a buffer I would just look up the last or first point of a polyline and then step back one vertex. A useful python function math.atan2() gives the absolute bearing of two points. The next issue is to get direct access to the polyline verticies. Opening a cursor on a featureclass is not enough, so I open it once and load the parts of the featureclass into Python list and dictionary structures. After processing in double-quick time, then open an update cursor and write out the results.

It all sounds like reinventing Network in Python, and it is. Maybe this could be done with C#.NET and ArcObjects? I challenge anyone with idle time to a competition!
0 Kudos
AlexanderBeavis
New Contributor II
Hey there,

I think I may be trying to do the same thing.

I'm looking for a way to calculate the bearing of a polyline with two vertex points.

But I'm using ArcGIS 10 so VBA coding wont work. Does any one have python or dot net coding to calculate bearing of a single polyline with only one segment in ArcGIS 10?
0 Kudos