Advertisement
Guest User

Untitled

a guest
Jun 28th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. def add_average_width(featureClass, averageWidthField='Width'):
  2. '''
  3. (str, [str]) -> str
  4.  
  5. Calculate the average width of each feature in the feature class. The width
  6. is reported in units of the feature class' projected coordinate systems'
  7. linear unit.
  8.  
  9. Returns the name of the field that is populated with the feature widths.
  10. '''
  11. import arcpy
  12. from math import pi
  13.  
  14. # Add the width field, if necessary
  15. fns = [i.name.lower() for i in arcpy.ListFields(featureClass)]
  16. if averageWidthField.lower() not in fns:
  17. arcpy.AddField_management(featureClass, averageWidthField, 'DOUBLE')
  18.  
  19. fnsCur = ['SHAPE@LENGTH', 'SHAPE@AREA', averageWidthField]
  20. with arcpy.da.UpdateCursor(featureClass, fnsCur) as cur:
  21. for row in cur:
  22. perim, area, width = row
  23. row[-1] = ((perim/pi) * area) / (perim**2 / (4 * pi))
  24. cur.updateRow(row)
  25.  
  26. return averageWidthField
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement