# deflection angle script

1367
16
11-29-2018 09:50 AM
by
Occasional Contributor

After running the script below the "point" layer that is created does not have any features and of course no angles calculated.  Any ideas on why this might be would be appreciated.

Thanks,

Jim

``````import math
02.... sr = arcpy.Describe("Z77").spatialReference
03.... arcpy.CreateFeatureclass_management('in_memory','points',"POINT",spatial_reference=sr)
05.... insCur = arcpy.da.InsertCursor("points",('SHAPE@','Angle'))
06.... with arcpy.da.SearchCursor("Z77",["SHAPE@"]) as cursor:
07....    for row in cursor:
08....        for part in row[0]:
09....            pt_count = 1
10....            for pnt in part:
11....                pnt = arcpy.PointGeometry(pnt,sr)
12....                if pt_count > 1:
13....                    if pt_count >2:
14....                        distAB = oneBack.distanceTo(twoBack)
15....                        distBC = pnt.distanceTo(oneBack)
16....                        distAC = pnt.distanceTo(twoBack)
17....                        angB = math.degrees(math.acos((((distAB*distAB)+(distBC*distBC))-(distAC*distAC))/(2*distAB*distBC)))
18....                        insCur.insertRow((oneBack,angB))
19....                    twoBack = oneBack
20....                oneBack = pnt
21....                pt_count += 1
22.... del insCur
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍``````
Tags (1)
1 Solution

Accepted Solutions
by
Occasional Contributor

Thanks, I'll double-check the indentation issues when pasting in the code to the python window.

16 Replies
MVP Honored Contributor

Add some print statements, particularly before you try to insert, to ensure the values are what you expect. If not, or if the print never executes, back up and figure out where it's failing.

by
Occasional Contributor

Darrin,

Thanks, I will try the print statement remedy.  Also, can the input "lines" layer be either a dissolved polyline feature or a multi-part polyline feature?

Jim

MVP Honored Contributor

The line(s) must be multi-part (i.e. many line segments joined into one feature).

by
Occasional Contributor

Darren,

Note nothing returned.

Thanks for the help!!

Jim

MVP Honored Contributor

That means there's either no pnts in part, or no parts in row[0], or no rows in cursor.

by
Occasional Contributor

Hmm, just noticed that prior to running script there was attribute field called "angle" and populated from some earlier tinkering. I just deleted it so I will re-run the script.

I really appreciate the help!  I see that the script does work so just have to keep plugging away at it.  I don't have much more time today but will pick up again tomorrow.

Regards,

Jim

by
Occasional Contributor

Darrin,

Just to make sure I understand the "no pnts in part, or no parts in row[0] " is in reference to the multi-part polyline layer (Z77_UTM13splitatpoint)??

Thanks,

Jim

MVP Honored Contributor

For some reason, your print statements aren't printing because the code never gets to them, so you need to back-track to figure out where the problem is. See which prints get executed. If nothing, there would seem to be a problem in the feature class itself.

``````with arcpy.da.SearchCursor("Z77",["SHAPE@"]) as cursor:
for row in cursor:
print('this is a feature')
for part in row[0]:
print('this is a part in the feature')
pt_count = 1
for pnt in part:
print('this is a point in the part in the feature')
...‍‍‍‍‍‍‍‍‍``````
by
Occasional Contributor

Darren,

I used the code above and as you can see above nothing is printed.  The feature class appears normal (a polyline) with 111 segments.  Not sure what is going on here.

Thanks,

Jim