本文整理匯總了Python中arcpy.DeleteField_management方法的典型用法代碼示例。如果您正苦於以下問題:Python arcpy.DeleteField_management方法的具體用法?Python arcpy.DeleteField_management怎麽用?Python arcpy.DeleteField_management使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類arcpy
的用法示例。
在下文中一共展示了arcpy.DeleteField_management方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: rename_col
# 需要導入模塊: import arcpy [as 別名]
# 或者: from arcpy import DeleteField_management [as 別名]
def rename_col(tbl, col, newcol, alias = ''):
"""Rename column in table tbl and return the new name of the column.
This function first adds column newcol, re-calculates values of col into it,
and deletes column col.
Uses arcpy.ValidateFieldName to adjust newcol if not valid.
Raises ArcapiError if col is not found or if newcol already exists.
Required:
tbl -- table with the column to rename
col -- name of the column to rename
newcol -- new name of the column
Optional:
alias -- field alias for newcol, default is '' to use newcol for alias too
"""
if col != newcol:
d = arcpy.Describe(tbl)
dcp = d.catalogPath
flds = arcpy.ListFields(tbl)
fnames = [f.name.lower() for f in flds]
newcol = arcpy.ValidateFieldName(newcol, tbl) #os.path.dirname(dcp))
if col.lower() not in fnames:
raise ArcapiError("Field %s not found in %s." % (col, dcp))
if newcol.lower() in fnames:
raise ArcapiError("Field %s already exists in %s" % (newcol, dcp))
oldF = [f for f in flds if f.name.lower() == col.lower()][0]
if alias == "": alias = newcol
arcpy.AddField_management(tbl, newcol, oldF.type, oldF.precision, oldF.scale, oldF.length, alias, oldF.isNullable, oldF.required, oldF.domain)
arcpy.CalculateField_management(tbl, newcol, "!" + col + "!", "PYTHON_9.3")
arcpy.DeleteField_management(tbl, col)
return newcol