-
Notifications
You must be signed in to change notification settings - Fork 0
/
changeGPtoSG.py
98 lines (65 loc) · 4.69 KB
/
changeGPtoSG.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#written by Erik Myers for WiM 10/5/2017
#note: to change field names to upper case you must first change the original field name text .gdb
#feature classes are not case-sensitive here so an upper() or lower() won't register as a change.
import arcpy
arcpy.env.workspace = r"D:\ESMData\MapperFiles\SparrowFiles\SparrowPacific\9.24_update\process_wm.gdb"
fcList = arcpy.ListFeatureClasses() # get all feature classes in .gdb
for fc in fcList: #loop through all feature classes in the .gdb
if fc == 'mrb7_rf1_tp_huc8_results':
fields = arcpy.ListFields(fc)
for fc in fcList:
if fc == 'mrb7_rf1_tp_huc8_results' or 'mrb7_rf1_tn_huc8_results':
fields = arcpy.ListFields(fc)
for field in fields:
if field.name.startswith("GP1_"):
oldname = field.name
newname = oldname.replace("GP1_", "GP3_")
print newname
arcpy.AlterField_management(fc, oldname, newname, newname)
print fc + '_________________FINISHED__________'
if fc == 'mrb7_rf1_tp_huc4_results' or 'mrb7_rf1_tn_huc4_results':
fields = arcpy.ListFields(fc)
for field in fields:
if field.name.startswith("GP3_"):
oldname = field.name
newname = oldname.replace("GP3_", "GP1_")
print newname
arcpy.AlterField_management(fc, oldname, newname, newname)
print fc + '_________________FINISHED__________'
if fc == 'mrb7_rf1_tp_state_results' or 'mrb7_rf1_tn_state_results':
fields = arcpy.ListFields(fc)
for field in fields:
if field.name.startswith("GP4_"):
oldname = field.name
newname = oldname.replace("GP4_", "ST_")
print newname
arcpy.AlterField_management(fc, oldname, newname, newname)
print fc + '_________________FINISHED__________'
if fc == 'mrb7_rf1_tp_huc8_state_results' or 'mrb7_rf1_tn_huc8_state_results':
fields = arcpy.ListFields(fc)
for field in fields:
if field.name.startswith("GP5_"):
oldname = field.name
newname = oldname.replace("GP5_", "SG3_")
print newname
arcpy.AlterField_management(fc, oldname, newname, newname)
print fc + '_________________FINISHED__________'
if fc == 'mrb7_rf1_tp_huc6_state_results' or 'mrb7_rf1_tn_huc6_state_results':
fields = arcpy.ListFields(fc)
for field in fields:
if field.name.startswith("GP6_"):
oldname = field.name
newname = oldname.replace("GP6_", "SG2_")
print newname
arcpy.AlterField_management(fc, oldname, newname, newname)
print fc + '_________________FINISHED__________'
if fc == 'mrb7_rf1_tp_huc4_state_results' or 'mrb7_rf1_tn_huc4_state_results':
fields = arcpy.ListFields(fc)
for field in fields:
if field.name.startswith("GP7_"):
oldname = field.name
newname = oldname.replace("GP7_", "SG1_")
print newname
arcpy.AlterField_management(fc, oldname, newname, newname)
print fc + '_________________FINISHED__________'
print "Job Complete"