Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def add_average_width(featureClass, averageWidthField='Width'):
- '''
- (str, [str]) -> str
- Calculate the average width of each feature in the feature class. The width
- is reported in units of the feature class' projected coordinate systems'
- linear unit.
- Returns the name of the field that is populated with the feature widths.
- '''
- import arcpy
- from math import pi
- # Add the width field, if necessary
- fns = [i.name.lower() for i in arcpy.ListFields(featureClass)]
- if averageWidthField.lower() not in fns:
- arcpy.AddField_management(featureClass, averageWidthField, 'DOUBLE')
- fnsCur = ['SHAPE@LENGTH', 'SHAPE@AREA', averageWidthField]
- with arcpy.da.UpdateCursor(featureClass, fnsCur) as cur:
- for row in cur:
- perim, area, width = row
- row[-1] = ((perim/pi) * area) / (perim**2 / (4 * pi))
- cur.updateRow(row)
- return averageWidthField
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement