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

安装后界面这样

相关推荐
天上的光9 分钟前
3.python——数据类型转换
python
钱彬 (Qian Bin)24 分钟前
一文掌握工业缺陷检测项目实战(Pytorch算法训练、部署、C++ DLL制作、Qt集成)
c++·pytorch·python·qt·实战·工业缺陷检测·faster rcnn
Python×CATIA工业智造1 小时前
Python迭代协议完全指南:从基础到高并发系统实现
python·pycharm
THMAIL1 小时前
机器学习从入门到精通 - Transformer颠覆者:BERT与预训练模型实战解析
python·随机森林·机器学习·分类·bootstrap·bert·transformer
0wioiw01 小时前
Python基础(①⑧Queue)
windows·python
Source.Liu2 小时前
【Python自动化】 21 Pandas Excel 操作完整指南
python·excel·pandas
urhero2 小时前
Python 制作的一个小说在线阅读工具
python·免费·小说·应用软件·小说在线阅读·无广告
跟橙姐学代码2 小时前
列表、元组与字典:Python开发者的三大必备利器,再向高手靠近一步
前端·python·ipython
计算机毕设残哥2 小时前
HDFS存储农业大数据的秘密是什么?高级大豆数据分析与可视化系统架构设计思路
大数据·hadoop·python·hdfs·数据分析·spark·django
蛋仔聊测试2 小时前
pytest源码解析(二)剖析 pytest 的核心组件
python·面试