Con l'aiuto di Mark Cederholm ho una soluzione funzionante che usa python e arcobjects . È agitato attorno ai bordi, ma ha fatto il lavoro. Dopo aver seguito la ricetta su quella pagina, crea un nuovo script che utilizza le GetLibPath, NewObj, CType, OpenFeatureClass
funzioni dasnippets.py
. Crea anche le tabelle di ricerca per rinominare in formato .csv:
Ricerca alias da campo a campo (att_code-name_lookup.csv):
Attrib_Name,Alias_Name
CODE,Specification Code
VALDATE,Validity Date
...
Classe di funzionalità alla ricerca di FC Alias (fc_code-name_lookup.csv):
"FC_Name","AliasName"
"BS_1250009_0","Navigational Aid"
"BS_1370009_2","Residential Area"
...
e la sceneggiatura:
import sys
sys.path.append('k:/code')
from snippets import GetLibPath, NewObj, CType, OpenFeatureClass
sWorkingDir = "k:/code/"
sFileGDB = sWorkingDir + "blank_canvec.gdb"
sResourceDir = "k:/code/"
sFCAliasFile = sResourceDir + "fc_code-name_lookup.csv"
sAttAliasFile = sResourceDir + "att_code-name_lookup.csv"
sProduct = "ArcEditor"
def BuildFieldAliasLookup():
lookup = {}
f = open(sAttAliasFile, "r")
bFirst = True
for line in f:
# Skip first line
if bFirst:
bFirst = False
continue
sTokens = line.replace('"','').split(',')
sFieldName = sTokens[0]
sAlias = sTokens[1]
lookup[sFieldName] = sAlias
return lookup
def AlterAlias():
# Initialize
from comtypes.client import GetModule
import arcgisscripting
sLibPath = GetLibPath()
GetModule(sLibPath + "esriGeoDatabase.olb")
GetModule(sLibPath + "esriDataSourcesGDB.olb")
import comtypes.gen.esriGeoDatabase as esriGeoDatabase
gp = arcgisscripting.create(9.3)
try:
gp.setproduct(sProduct)
except:
gp.AddMessage(gp.GetMessages(2))
# Build field alias lookup table
AttrLookup = BuildFieldAliasLookup()
# Open alias file and loop through lines
f = open(sFCAliasFile, "r")
bFirst = True
for line in f:
# Skip first line
if bFirst:
bFirst = False
continue
sTokens = line.replace('"','').split(',')
sFCName = sTokens[0]
sAlias = sTokens[1]
print "Processing: ", sFCName
# Open feature class
try:
pFC = OpenFeatureClass(sFCName)
except:
print "Could not open ", sFCName
continue
# Alter feature class alias
try:
pSE = CType(pFC, esriGeoDatabase.IClassSchemaEdit)
pSE.AlterAliasName(sAlias)
except:
print "Error altering class alias"
continue
# Alter field aliases
try:
for sKey in AttrLookup.keys():
i = pFC.FindField(sKey)
if i == -1:
continue
sAlias = AttrLookup[sKey]
pSE.AlterFieldAliasName(sKey, sAlias)
except:
print "Error altering field aliases"
print "Done."
print 'Field <--> Alias lookup table is:', BuildFieldAliasLookup()
print AlterAlias()