arcgis更改图层字段名脚本

话不多说,上脚本源码,复制黏贴即可

python 复制代码
#-*- coding:utf-8 -*-
__author__ = 'lumen'
import arcpy 
#输入图层
InputFeature = arcpy.GetParameterAsText(0)
#原始字段
oldField = arcpy.GetParameterAsText(1)
# 获取原始字段类型
oldFieldType = ''
desc = arcpy.Describe(InputFeature)
# 获取字段列表
fields = desc.fields
# 遍历字段列表并打印字段名和字段类型
arcpy.AddMessage(fields)
for field in fields:
    if field.name==oldField:
        oldFieldType = field.type
arcpy.AddMessage(oldFieldType)
#这是xin字段
newField = arcpy.GetParameterAsText(2)
arcpy.AddMessage('fields has been registered')
#为新字段添加唯一指定字段
arcpy.AddField_management(InputFeature, newField, oldFieldType)
#获取数据游标
cursor = arcpy.UpdateCursor(InputFeature)

#遍历数据
for row in cursor:
    newValue = row.getValue(oldField)
    row.setValue(newField,newValue) 
    cursor.updateRow(row)
# 使用 DeleteField 工具删除字段
arcpy.DeleteField_management(InputFeature, oldField)
#完活儿
arcpy.AddMessage('project succeed,best wishes for you')
# 删除游标对象
del cursor, row

安装后界面这样

相关推荐
love530love3 分钟前
【笔记】旧版MSYS2 环境中 Rust 升级问题及解决过程
开发语言·人工智能·windows·笔记·python·rust·virtualenv
程序员杰哥28 分钟前
Postman常见问题及解决方法
自动化测试·软件测试·python·测试工具·职场和发展·测试用例·postman
七七&5561 小时前
java面试-场景题
java·python·面试
我就是全世界1 小时前
2025主流智能体Agent终极指南:Manus、OpenManus、MetaGPT、AutoGPT与CrewAI深度横评
人工智能·python·机器学习
waterHBO1 小时前
python 爬虫工具 mitmproxy, 几问几答,记录一下
开发语言·爬虫·python
pianmian11 小时前
arcpy与扩展模块
python
Blossom.1182 小时前
使用Python和OpenCV实现图像识别与目标检测
人工智能·python·神经网络·opencv·安全·目标检测·机器学习
chicpopoo2 小时前
Python打卡DAY46
开发语言·python
灏瀚星空2 小时前
Python数学可视化:3D参数曲面与隐式曲面绘制技术
开发语言·python·3d
晨尘光2 小时前
在Windows下编译出llama_cpp_python的DLL后,在虚拟环境中使用方法
python·llama