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

安装后界面这样

相关推荐
Patrick在香港5 分钟前
Python实战:用数据分析拆解一场AI大会——WAIC 2026参展企业画像、议题演变与城市格局
人工智能·python·数据挖掘·数据分析·ai编程
小猴子爱上树1 小时前
TikTok Shop视频自动翻译工具实战教程
人工智能·python·音视频·机器翻译
humbinal1 小时前
同时支持 gui & cli 的 parquet 文件查看工具,高性能小清新!
hive·python·rust·spark·开源·github·parquet
90后的晨仔2 小时前
Python 开发完全指南:从入门到工程化落地
python
Mikowoo0072 小时前
批量汇总XML格式的发票信息
xml·python
胡耀超2 小时前
从一次批量爬取到生产同步:问题变了,建设边界也要跟着变
爬虫·python·系统架构·数据治理·数据同步·接口设计·爬虫工程
旅僧2 小时前
王树森老师强化学习--同声传译版3
python·深度学习
梦想不只是梦与想2 小时前
python中精度处理:decimal
python·float·精度丢失·decimal·浮点运算
大模型码小白2 小时前
向量化引擎与 AI 排障:当 SIMD 遇到异常检测,存储诊断的范式转移
java·大数据·数据库·人工智能·python
雪的季节3 小时前
【无标题】
linux·服务器·python