I don't think you need to do your initial line splitting. If you iterate through the points in the
SHAPE@JSON attribute of the feature class, you can measure the sum of angles for each line and divide by the number of vertices.
from math import acos
from numpy.linalg import norm
"""This function returns the angle p1p2p3 given tuple inputs of the coordinates."""
#The vectors from p2->p1 and p2->p3
v1 = [p1-p2, p1-p2]
v2 = [p3-p2, p3-p2]
#The sum of the dotproducts of each vector.
dotproduct = numpy.sum(p*q for p,q in zip(v1,v2))
#The multiplication of the magnitudes of each vector.
magnitude = float(norm(v1) * norm(v2))
#Rounding here to account for number of decimal places in rads.
if dotproduct != 0 and magnitude != 0.0:
try: x = dotproduct/magnitude
except: print dotproduct, magnitude
if x > 1.0 or x <-1.0:
x = round(x,1)
if x > 1.0 or x < -1.0:
x = float(int(x))
return math.degrees(math.acos(round((x), 4)))
else: return 0
Below is an example of how to measure the angles of vertices in a polygon
with arcpy.da.SearchCursor(polygons, polygonFields) as cursor:
for row in cursor:
if row is not None:
ringlist = json.loads(row.JSON)["rings"]
angle_list = 
for ringIndex, ring in enumerate(ringlist):
vertexList = json.loads(row.JSON)["rings"][ringIndex]
for index, vertex in enumerate(vertexList):
[x,y] = vertex
ptID = index
ringID = ringIndex
if ptID == 0: angle = findangle(vertexList[len(vertexList)-2], vertexList, vertexList)
elif ptID == len(vertexList)-1: angle = findangle(vertexList[index-1], vertexList[index], vertexList)
else: angle = findangle(vertexList[index-1], vertexList[index], vertexList[index+1])
angle_sum = sum(angle_list)
For measuring the angles of a line, the difference would be the
['rings'] value. You should print the
SHAPE@JSONstring for a line and look at the key that has all the vertices in it. Also different: polygon 'rings' are essentially lines where the first and last points are the same. In the logic above, if the current point is the first point of the line, it measures the angle from the next point, current point, and the second to last point. For your purposes, you might want to change that to just use the last point, or skip it if that information isn't useful.