deflection angle script

1870
16
Jump to solution
11-29-2018 09:50 AM
JimFritz
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)  
04.... arcpy.AddField_management('points','Angle',"DOUBLE")  
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)
0 Kudos
16 Replies
JimFritz
Occasional Contributor

Darren,

Disregard the last response.  Print statements seem correct.  Going back to original script now.

Thanks,

Jim

0 Kudos
JimFritz
Occasional Contributor

Darren,

Here's the latest results using the original script.  Seems the print functions are working up to "print (angB)" and then nothing is returned.  Any ideas?

angle deflection script

0 Kudos
DarrenWiens2
MVP Honored Contributor

Check your indentation and notice that pt_count never gets incremented, so it's never > 1.

The idea to debug this is to try to figure why the print statement never gets executed, which is because it never gets into the loop. Why not?

0 Kudos
JimFritz
Occasional Contributor

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

0 Kudos
DanPatterson_Retired
MVP Emeritus

print pnt_count rather than the point object

0 Kudos
JimFritz
Occasional Contributor

Would that be coded like this?

.....

......

pt_count = 1

print (pt_count)  or  print("pt_count")

thanks,

Jim

0 Kudos
JimFritz
Occasional Contributor

Thanks Darren and Dan.  It came down to incorrect indentation. 

Problem solved!

0 Kudos