案例八:生成三维沉降曲面
案例概述
本案例从 GDIM 读取沉降点坐标表与累计沉降数据表,生成所选监测时间的三维沉降曲面。
你将学到
将多表沉降监测数据接入 PipeLine,串联读表、分表提取、时间筛选与自定义脚本绘图,生成可在 GDIM 上运行的 .pipe 应用。
用
GdimTableReader一次读取坐标表与累计沉降表,并用TableSelector分别提取。用
TablesQuery与TemplateVariableConfig实现监测时间单选过滤(auto_select下拉)。用
PythonCoder调用本地函数完成 IDW 插值与 Plotly 三维曲面绘制,并通过OutputPlotData供前端渲染。用
add_attributes与ui_schema_function_name配置竖向放大系数、曲面不透明度、着色色带等 UI 控件。
实现思路
创建
GdimTableReader,分别读取 ``settlement_point_info_table``(坐标)与 ``cumulative_settlement_data_table``(沉降与时间)。用两个
TableSelector从TableCollection中提取各表,再用TablesQuery按tpl_time过滤所选时间的沉降数据。创建
PythonCoder,调用settlement_3d_surface执行 IDW 插值(p=2)并生成三维曲面;插值范围为所有沉降点的矩形包围盒,向外扩展对角线的 10%。将坐标表与过滤后的沉降表分别连入
Plot3dSurface的两个动态输入端口,add_attribute暴露监测时间与可视化参数。
关键代码
本例关键在于按时间筛选沉降数据,并通过 PythonCoder 生成三维曲面,对应代码如下。
filter_time = TablesQuery("FilterByTime")
filter_time.query_template = "`time` == {tpl_time}"
filter_time.template_variables = {
"tpl_time": TemplateVariableConfig(
title="监测时间",
value_type="str",
schema_type="auto_select",
)
}
plotter = PythonCoder("Plot3dSurface")
plotter.local_function_name = "settlement_3d_surface"
plotter.ui_schema_function_name = "settlement_3d_surface_ui_schema"
plotter.add_dynamic_ports_in("InputPointInfo")
plotter.add_dynamic_ports_in("InputSettlementData")
plotter.add_dynamic_ports_out("OutputPlotData")
pipeline.add_links(
select_point_info.OutputTable >> plotter.InputPointInfo
| filter_time.OutputTables >> plotter.InputSettlementData
)
pipeline.run()
更进一步
完整代码请查看以下链接: