Last active
March 21, 2018 15:36
-
-
Save pyRobShrk/8a8bfc7ad0bb26b56906e515ce7188bb to your computer and use it in GitHub Desktop.
arcpy script to write field aliases based on an Excel lookup table using pandas
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# start with an excel table with two columns | |
# first row should be headers "FIELD" and "ALIAS" | |
# copy both columns to clipboard including headers | |
# use copyFieldsToClipboard to get the list | |
# optionally add a column called "RENAME" and run renameFields | |
import pandas as pd | |
def copyFieldsToClipboard(lyr): | |
fieldList = [f.name for f in arcpy.ListFields(lyr)] | |
pd.DataFrame(fieldList).to_clipboard() | |
def writeFieldAliases(lyr): | |
#create a dictionary, alias found by fieldDict['FIELD']['ALIAS'] | |
fieldDict = pd.read_clipboard(index_col=0).to_dict('index') | |
for f in arcpy.ListFields(lyr): | |
if f.name in fieldDict: | |
arcpy.management.AlterField(lyr,f.name,new_field_alias=fieldDict[f.name]['ALIAS']) | |
def renameFields(shp): | |
fieldDict = pd.read_clipboard(index_col=0).to_dict('index') | |
for f in arcpy.ListFields(shp): | |
if f.name in fieldDict: | |
arcpy.management.AlterField(shp,f.name,new_field_name=fieldDict[f.name]['RENAME']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment