如何使用Ocean for Petrel访问网格中Dictionary Property的数值?
访问Petrel网格中Dictionary Property的方法
要读取网格中像Fluvial facies、lithologies这类Dictionary Property的数值,核心是先获取对应属性的实例,再通过单元格索引取值,以下是具体实现方案:
关键步骤说明
- 获取属性实例:在Petrel插件开发中,最规范的方式是将目标属性设为插件的输入参数,让用户在界面中选择对应属性;也可以通过Petrel项目树API查找指定属性。
- 安全取值:取值前需检查单元格是否定义、属性在该单元格是否有有效值,避免触发异常。
- 编码与标签转换:DictionaryProperty返回的是整数编码值,若需要对应的文本标签,可通过
CodeList.GetLabel()方法转换。
修改后的完整代码示例
Grid grid = arguments.Input_Grid; // 假设Input_TargetProperty是你在插件参数中定义的Dictionary Property输入项(比如对应Fluvial facies) DictionaryProperty targetProp = arguments.Input_TargetProperty; if (grid == null || targetProp == null) { PetrelLogger.ErrorStatus("HelloGrid: 网格或属性不能为空。"); return; } Index3 currentCell = new Index3(); var cellCounts = grid.NumCellsIJK; for (int i = 0; i < cellCounts.I; i++) { for (int j = 0; j < cellCounts.J; j++) { for (int k = 0; k < cellCounts.K; k++) { currentCell.I = i; currentCell.J = j; currentCell.K = k; if (grid.IsCellDefined(currentCell) && grid.HasCellVolume(currentCell)) { // 检查当前单元格的属性值是否已定义 if (targetProp.IsDefined(currentCell)) { // 获取属性的整数编码值 int propValue = targetProp[currentCell]; // 获取编码对应的文本标签(比如"Channel"、"Lobe"等) string propLabel = targetProp.CodeList.GetLabel(propValue); // 这里添加你的业务逻辑,比如打印日志或处理数据 PetrelLogger.InfoStatus($"单元格({i},{j},{k}) 属性值:{propValue},标签:{propLabel}"); } else { PetrelLogger.InfoStatus($"单元格({i},{j},{k}) 无有效属性值。"); } } } } }
补充说明
- 若要通过项目树查找属性,可使用
ProjectTree相关API,比如根据属性名称筛选:var targetProp = ProjectTree.GetItems<DictionaryProperty>().FirstOrDefault(p => p.Name == "Fluvial facies"); - 确保插件的ArgumentDefinition中已添加DictionaryProperty类型的输入参数,这样用户才能在Petrel界面中选择目标属性。
内容的提问来源于stack exchange,提问作者Jason Yang
相关产品推荐
相关产品推荐

