You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

请求协助:从Esri GDB导出所有域至Excel并解决报错

解决Esri文件GDB域导出Excel的报错问题

你的报错原因很明确:直接将ArcGIS的Domain对象写入Excel单元格,openpyxl无法识别这类ArcGIS自定义对象,必须提取域的具体属性值(如名称、编码、对应值等)后再写入。

以下是可直接运行的Python脚本,基于ArcPy和openpyxl实现域导出:

import arcpy
from openpyxl import Workbook

# 替换为你的文件GDB路径
gdb_path = r"C:\Your\FileGDB\Path\data.gdb"
# 替换为要保存的Excel文件路径
excel_output = r"C:\Your\Output\Path\domains_export.xlsx"

# 设置ArcPy工作空间
arcpy.env.workspace = gdb_path

# 创建Excel工作簿和工作表
wb = Workbook()
ws = wb.active
ws.title = "域信息"

# 写入表头
ws.append(["域名称", "域描述", "编码", "值"])

# 获取GDB中所有域
all_domains = arcpy.da.ListDomains(gdb_path)

# 遍历每个域并写入Excel
for domain in all_domains:
    domain_name = domain.name
    domain_desc = domain.description if domain.description else ""
    
    # 处理编码值类型的域(最常用类型)
    if domain.domainType == "CodedValue":
        for code, value in domain.codedValues.items():
            ws.append([domain_name, domain_desc, code, value])
    # 处理范围类型的域(按需保留)
    elif domain.domainType == "Range":
        ws.append([domain_name, domain_desc, f"最小值: {domain.range[0]}", f"最大值: {domain.range[1]}"])

# 保存Excel文件
wb.save(excel_output)
print(f"导出完成,文件路径:{excel_output}")

关键说明

  1. 核心修复点:不再直接赋值Domain对象,而是提取name、description、codedValues等属性值,这些都是字符串/数字类型,openpyxl可正常识别。
  2. 域类型处理:区分两种常见域类型:
    • CodedValue:遍历键值对,逐行写入编码和对应值
    • Range:提取范围的上下限,合并为文本写入
  3. 环境要求:必须在ArcGIS Pro配套的Python环境中运行(arcpy仅随ArcGIS安装),openpyxl已预装在该环境中,无需额外安装。

内容的提问来源于stack exchange,提问作者Fabian Zentner

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.23 00:45:12