Guest User

Untitled

a guest
Jan 17th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. #Archives Historic SAP Numbers
  2. import arcpy
  3.  
  4. fc = "U:/Data/Leases.gdb/LeasePlans"
  5. changes = "U:/Data/To_be_Deleted.csv"
  6.  
  7. #New Field Criteria
  8. field_Name = "Status"
  9. field_Nametype = "Text"
  10. field_NameVal = arcpy.ValidateFieldName(field_Name)
  11.  
  12. #Adds the new field if it doesn't already exist
  13. fList = arcpy.ListFields(fc,field_Name)
  14. if not fList:
  15. arcpy.AddField_management(fc, field_Name, field_Nametype, "", "", "")
  16.  
  17. #List comprehension for IDs
  18. ids = [i for i, in arcpy.da.SearchCursor
  19. (changes, "SAPNO") if i != None]
  20.  
  21.  
  22. Relevant_Fields = ['Property_Ref', 'Status']
  23.  
  24. #update cursor to Insert 'Archived' rows
  25. with arcpy.da.UpdateCursor (fc, Relevant_Fields) as cursor:
  26. for SAPNO, in cursor:
  27. if SAPNO in ids:
  28. row[1] = 'Archived'
  29. cursor.UpdateRow()
  30.  
  31. del cursor
  32.  
  33. import arcpy, csv
  34.  
  35. fc = r'C:database.gdbfeature_class'
  36. codefile = r"C:folderfile.csv"
  37.  
  38. with open(codefile, 'r') as f:
  39. reader = csv.reader(f)
  40. sapno_list = [k for k in reader]
  41.  
  42. fc_fields = ['Property_Ref','Status']
  43.  
  44. with arcpy.da.UpdateCursor(fc, fc_fields) as cursor:
  45. for row in cursor:
  46. if row[0] in sapno_list:
  47. row[1]='Archived'
  48. cursor.updateRow(row)
  49. else:
  50. print "Did not find value for Propetry_Ref: {0}".format(row[0])
Add Comment
Please, Sign In to add comment