Advertisement
Guest User

Untitled

a guest
Mar 1st, 2015
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. import arcpy, os, sys
  2.  
  3. InFolder = sys.argv[1] # folder for shapefiles, or database for feature classes
  4.  
  5. arcpy.env.workspace = InFolder
  6.  
  7. for ThisFC in arcpy.ListFeatureClasses():
  8. # assuming any field with an underscore needs to be split
  9. SplitFields = arcpy.ListFields(ThisFC,"*_*")
  10. # iterate through each field found with an underscore
  11. for ThisField in SplitFields:
  12. # skip shape length and shape area fields
  13. if not ThisField.baseName.lower() == "shape_length" and not ThisField.baseName.lower() == "shape_area" :
  14. # break it up into parts
  15. Parts = ThisField.baseName.split("_")
  16. for ThisPart in Parts:
  17. # Add a field for each part
  18. arcpy.AddField_management(ThisFC,ThisPart,"TEXT",field_length = 30)
  19. # populate with the part (""" is a quote). In order to put a string into
  20. # a field it is necessary to quote it so the processor understands that it's
  21. # a string to be populated and not a field name.
  22. arcpy.CalculateField_management(ThisFC,ThisPart,""" + ThisPart + ""","PYTHON")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement