简体   繁体   English

使用python覆盖属性表

[英]Overwrite attribute table using python

When I try to use python codes to add fields and update the fields using geometry (x and y) to the attribute table of feature class, it gives me this error: 当我尝试使用python代码向要素类的属性表中添加字段并使用几何图形(x和y)更新字段时,出现以下错误:

field A already exists 栏位A已存在
Failed to execute (AddField). 执行失败(AddField)。

I used 我用了

  arcpy.env.overwriteOutput = True

in my codes but seem not to work. 在我的代码中,但似乎不起作用。

How to overwrite attribute table of feature class? 如何覆盖要素类的属性表? Does this overwrite code also work for the overwriting attribute table? 此覆盖代码是否也适用于覆盖属性表? I know that even for geoprocessing the codes don't work well sometimes. 我知道即使进行地理处理,有时代码也无法正常工作。

arcpy.env.overwriteOutput will overwrite existing datasets, not existing fields. arcpy.env.overwriteOutput将覆盖现有数据集,而不覆盖现有字段。

You should ckeck if the field exists, and if it does, either: 您应该检查该字段是否存在,如果存在,请执行以下任一操作:

Delete it and re-add it: 删除并重新添加:

if len(arcpy.ListFields(your_dataset, A)) > 0:
  arcpy.DeleteField_management(your_dataset, A)
  arcpy.AddField_management(your_dataset, A, field_type)

Not add it: 不添加:

if len(arcpy.ListFields(your_dataset, A)) > 0:
  arcpy.AddMessage("Field A already exists")
else:
  arcpy.AddField_management(your_dataset, A, field_type)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM