批量新增字段

2021-10-02 07:18:24 字數 2084 閱讀 4439

將其它圖層(圖層a、b)的字段新增到另一圖層(圖層c)屬性表中

下圖中「氣象資料201706」圖層已有6個字段,現在想將「point」圖層中除了objectid、shape之外的字段新增到「氣象資料201706」圖層中。

具體**:

# 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)

MYSQL 多表批量新增字段

set exe concat alter table tab,add create date date comment 建立時間 prepare sql1 from exe execute sql1 end if if not exists select 1 from information sch...

ArcGis Python指令碼 批量新增字段

插個廣告,製作arcgis的tool工具學習下面的教程就對了 零基礎學習python製作arcgis自定義工具 鏈結 零基礎學習python製作arcgis自定義工具 課程簡介 以下是正文 函式 arcpy.addfield management 語法 addfields management in...

oracle 多表批量新增相同字段

目標 實現方法 先查詢表空間包含的所有表 此處表空間名要注意大小寫 select alter table table name add 欄位名 字段型別 from all tables where owner 表空間名 將查詢得出的結果右鍵全選並複製,將複製的結果貼上到sql視窗中執行即可。在網上還...