-
Notifications
You must be signed in to change notification settings - Fork 0
/
StandardizeFieldNames_Layouts.py
70 lines (57 loc) · 2.23 KB
/
StandardizeFieldNames_Layouts.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
"""--------------------------------------------------------------------------------
StandardizeFieldNames_Layouts.py
Description:
Rename fields to fit standards
Input:
1) A geodatabase or folder holding polygon layers
Output:
1) Feature class with renamed fields and new fields
Version 0.1
Created by: Juel Paul/Land Analytical
Date: March 12, 2020
--------------------------------------------------------------------------------"""
# Import modules
import arcpy
from arcpy import env
import os
inGDB = arcpy.GetParameterAsText(0)
# Set workspace and environment variables
arcpy.env.workspace = inGDB
arcpy.env.overwriteOutput = True
namesDict = {
"Layout_No" : "LayoutNo",
"IndexID" : "LayoutNo",
"Application_Reference_No" : "ApplicationReferenceNo",
"Applicatio" : "ApplicationReferenceNo",
"Applicat" : "ApplicationReferenceNo",
"ApplicationNumber" : "ApplicationReferenceNo",
"FieldApplicationNumber" : "ApplicationReferenceNo",
"SiteArea_M" : "SiteArea_M2",
"SiteArea_H" : "SiteArea_HA",
"SiteArea_S" : "SiteArea_SF",
"SiteArea_A" : "SiteArea_ARP",
"ProposedLa" : "ProposedLanduse",
"ProposedLanduseType" : "ProposedLanduse"
}
arcpy.AddMessage("Searching the folder now...")
ftrs = []
checkCount = 0
fixedCount = 0
# Walk GDB and list all polygon features
for dirpath, dirnames, filenames in arcpy.da.Walk(inGDB, datatype="FeatureClass", type="Polygon"):
for filename in filenames:
ftrs.append(os.path.join(dirpath, filename))
ftrCount = len(ftrs)
for ftr in ftrs:# Pass qualified ftrs to list fields
field_names = [f.name for f in arcpy.ListFields(ftr)]
# Check if listed fields are in name dict
for field_name in field_names:
# If field is in dict, rename field
if field_name in namesDict:
arcpy.AlterField_management(ftr, field_name, namesDict[field_name], "", "", "", "", "TRUE")
arcpy.AddMessage("{0} is in {1}. Renaming now...".format(field_name, ftr))
fixedCount = fixedCount + 1
else:
arcpy.AddMessage("{0} in {1} does not need renaming.".format(field_name, ftr))
checkCount = checkCount + 1
arcpy.AddMessage("{0} fields checked and {1} fields renamed.".format(checkCount, fixedCount))