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

安装后界面这样

相关推荐
非科班Java出身GISer7 分钟前
ArcGIS JS 基础教程(22):BuildingSceneLayer 建筑场景图层
arcgis·arcgis js 建筑·arcgis building·arcgis加载bim数据·arcgis js bim·arcgis加载建筑数据·arcgis js加载建筑
凡尘——雨落凡尘1 小时前
Python列表索引越界IndexError问题深度解析与解决办法
python·indexerror·list index out of range
郝同学今天有进步吗1 小时前
构建 LangGraph Code Review Agent(七):实现规则匹配、Finding Guardrails 与 Markdown 报告
python·ai·fastapi·code review
xuhe22 小时前
一劳永逸!解决 AutoDL 系统盘(30GB)爆满与 pip 缓存迁移
linux·python·ai·jupyter
CodexDave2 小时前
Python 自动化接单实战(一):把 CSV 需求做成配置驱动解析器
java·python·自动化·json·数据清洗·python自动化·csv处理
m沐沐3 小时前
【深度学习】循环神经网络RNN——结构、原理与长期依赖问题解析
人工智能·pytorch·python·rnn·深度学习·算法·机器学习
风吹心凉3 小时前
python3基础2026.7.28
开发语言·python
曲无忆3 小时前
LLMs赋能依赖类型证明自动化
python
一次旅行3 小时前
act本地预跑GitHub Actions:Python项目完整CI/CD流水线实战
python·ci/cd·github
玉鸯4 小时前
RAG 全链路调优指南:从 Chunking 到 Reranker
python·llm·agent