|
# 2020-1-19
# 将其它图层(图层A、B)的字段添加到另一图层(图层C)属性表中
# 基于Python3实现
import arcpy
from arcpy import env
# 设置工作空间
env.workspace = r"D:\GPTOOL\空间插值气象站点数据\test.gdb"
# 字段结构
fieldsFrom = "point"
# 添加字段给哪个要素图层
fieldsTo = "气象数据201706"
# 字段列表
fieldList = arcpy.ListFields(fieldsFrom)
# 遍历指标
for fld in fieldList:
print("field name: " + fld.name + " field type: " + fld.type + " " + " field precision: " + str(
fld.precision) + " field scale: " + str(fld.scale))
if fld.name.upper() == "OBJECTID" or fld.name.upper() == "SHAPE" or fld.name.upper() == "SHAPE_LENGTH" or fld.name.upper() == "SHAPE_AREA":
continue
else:
if fld.type == 'SmallInteger':
print(fld.type)
arcpy.AddField_management(fieldsTo, fld.name, "SHORT") # 短整型
print("field name: " + fld.name + " field type: " + fld.type)
elif fld.type == 'Integer':
arcpy.AddField_management(fieldsTo, fld.name, "LONG") # 长整型
print("field name: " + fld.name + " field type: " + fld.type)
elif fld.type == 'Single':
arcpy.AddField_management(fieldsTo, fld.name,
"FLOAT") # 浮点型
print("field name: " + fld.name + " field type: " + fld.type)
elif fld.type == 'String':
arcpy.AddField_management(fieldsTo, fld.name,
"TEXT",
field_length=254) # 文本型
print("field name: " + fld.name + " field type: " + fld.type)
else:
arcpy.AddField_management(fieldsTo, fld.name,
fld.type) #
print("field name: " + fld.name + " field type: " + fld.type)
————————————————
版权声明:本文为CSDN博主「gislaozhang」的原创文章,版权归作者所有
原文链接:https://blog.csdn.net/gislaozhang/article/details/104042653
|
|