數據處理
在提取數據后,我們需要對字段進行標準化處理,例如統一土地利用類型的命名。
# 定義字段映射字典
field_mapping = {"Residential": "居住用地","Commercial": "商業用地","Industrial": "工業用地","Agricultural": "農業用地"
}# 獲取輸出地理數據庫中的所有要素類
arcpy.env.workspace = output_gdb
feature_classes = arcpy.ListFeatureClasses()# 更新字段值
for fc in feature_classes:with arcpy.da.UpdateCursor(fc, ["Land_Use_Type"]) as cursor:for row in cursor:if row[0] in field_mapping:row[0] = field_mapping[row[0]]cursor.updateRow(row)print(f"要素類 {fc} 的字段已標準化")
通過 arcpy.da.UpdateCursor
,我們可以遍歷每個要素類并更新字段值,確保字段命名的一致性。