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

安装后界面这样

相关推荐
AIAdvocate1 小时前
Pandas_数据结构详解
数据结构·python·pandas
小言从不摸鱼1 小时前
【AI大模型】ChatGPT模型原理介绍(下)
人工智能·python·深度学习·机器学习·自然语言处理·chatgpt
FreakStudio3 小时前
全网最适合入门的面向对象编程教程:50 Python函数方法与接口-接口和抽象基类
python·嵌入式·面向对象·电子diy
redcocal4 小时前
地平线秋招
python·嵌入式硬件·算法·fpga开发·求职招聘
artificiali5 小时前
Anaconda配置pytorch的基本操作
人工智能·pytorch·python
RaidenQ5 小时前
2024.9.13 Python与图像处理新国大EE5731课程大作业,索贝尔算子计算边缘,高斯核模糊边缘,Haar小波计算边缘
图像处理·python·算法·课程设计
花生了什么树~.5 小时前
python基础知识(六)--字典遍历、公共运算符、公共方法、函数、变量分类、参数分类、拆包、引用
开发语言·python
Trouvaille ~6 小时前
【Python篇】深度探索NumPy(下篇):从科学计算到机器学习的高效实战技巧
图像处理·python·机器学习·numpy·信号处理·时间序列分析·科学计算
爆更小小刘6 小时前
Python基础语法(3)下
开发语言·python
哪 吒6 小时前
华为OD机试 - 第 K 个字母在原来字符串的索引(Python/JS/C/C++ 2024 E卷 100分)
javascript·python·华为od