案例十四:平台数据对接GEO5

案例概述

本案例从 GDIM 读取钻孔一览表与地层表,并转换为 GEO5 三维地质建模所需格式,导出为 Excel 文件。

你将学到

PipeLine 中连接读表、自定义脚本转换与 Excel 导出模块,生成可在 GDIM 上运行的 .pipe 应用。

  • GdimTableReader 读取 bore_tablelayer_table 等勘察表数据。

  • PythonCoder 调用本地函数,将 GDIM 表数据预处理为 GEO5 格式。

  • DocDataWriter 转为 DocDataExcelPrinter 按模板渲染 Excel 文件。

  • local_functions_path 指定本地函数脚本,add_attribute 暴露 Excel 模板路径。

实现思路

  1. 创建 PipeLine,配置 GDIM 登录信息,并设置 local_functions_path 指向 GenerateGeo5Tables.py

  2. 创建 GdimTableReader,读取 bore_tablelayer_table

  3. 创建 PythonCoder,调用 GenerateGeo5Tables 本地函数,生成 GEO5 所需的 FieldTestslayers_table 等表。

  4. DocDataWriter 将转换结果转为 DocDataExcelPrinter 按模板输出 .xlsx``(``save_to_gdim=True 可上传至 GDIM)。

  5. add_attribute 暴露 template 供前端选择 Excel 模板,save_pipeline 保存 .pipe 并运行。

关键代码

本例关键在于本地函数转换 GEO5 格式并导出 Excel,对应代码如下。

reader = GdimTableReader("Reader")
reader.table_fields = ["bore_table", "layer_table"]

generate_geo5_tables = PythonCoder("GenerateGeo5Tables")
generate_geo5_tables.add_dynamic_ports_in("InputTables")
generate_geo5_tables.add_dynamic_ports_out("OutputTables")
generate_geo5_tables.local_function_name = "GenerateGeo5Tables"

print_excel = ExcelPrinter("PrintExcel")
print_excel.save_to_gdim = True

pipeline.add_links(
    reader.OutputTables >> generate_geo5_tables.InputTables
    | generate_geo5_tables.OutputTables >> excel_writer.InputData
    | excel_writer.OutputDocData >> print_excel.InputDocData
)

pipeline.add_attribute(
    attr_name="template",
    module_name="PrintExcel",
    param_name="template",
    attr_title="Excel模板",
)
pipeline.run()

更进一步

完整代码请查看以下链接:

geo5ExcelOutputPipeline.py