转眼间,这一年又结束了,再记录一点知识吧

同事说他有好多shapefile,想给每个shapefile添加一字段,并设置该字段的内容为shapefile文件名,想着用arcpy实现,于是有了下面的代码

import os
import arcpy
arcpy.env.workspace = r"F:\workspace\2017\other"

fcs = arcpy.ListFeatureClasses()  

for fc in fcs:
    arcpy.AddField_management(fc,"Test2","TEXT","","","100","","NULLABLE","NON_REQUIRED")
  
for fc in fcs:
   cursor = arcpy.UpdateCursor(fc)
   feminus = str(fc)[::-1]
   fea = str(feminus)[4:]
   feature = str(fea)[::-1]
   for row in cursor:
       row.setValue("Test2", feature) 
       cursor.updateRow(row)

由于是测试代码,添加的字段名为Test2,文本型,长度为100。

相关文章:

  • 2021-12-31
  • 2022-02-09
  • 2021-06-30
  • 2022-12-23
  • 2022-12-23
  • 2021-11-18
  • 2021-06-18
  • 2022-02-02
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-28
  • 2021-11-18
  • 2022-12-23
  • 2021-11-18
相关资源
相似解决方案