0

我在这里有 .dem 文件:http: //ddfe.curtin.edu.au/models/ERTM2160/data/dem/

在 python pyvista 我有例如:

import pyvista as pv
file = 'pick_one_from_the_link_above.dem'
mesh = pv.read(file)

输出说:

mesh.dimensions
[-2147483648,-2147483648,1]

除了减号之外,它是 mesh.n_points 的平方根

尝试使用 mesh.points 绘制或提取点时,我收到一条消息,即不允许使用负尺寸。尝试以下方法:

mesh.dimensions = [int(numpy.sqrt(mesh.n_points)),int(numpy.sqrt(mesh.n_points)),1]

导致错误消息:

溢出错误:SetDimensions 参数 1:值超出 int 范围

有人可以告诉我我做错了什么,我不知道吗?或者可能知道如何读取这些文件以制作曲面图?

非常感谢 :)

4

1 回答 1

2

@larsks 在上面的评论中是正确的。这些“.dem”文件不是 PyVista 和它包装的 VTK 阅读器所期望的格式。您应该使用np.fromfile来读取数据:arr = np.fromfile('N00E015.dem', dtype=np.int16). 进一步从您的链接中列出的文档

由于其总大小为 44 GB,该模型以 881 个 5 度 x 5 度大小的二进制文件为每个功能分区和分布。每个 5 度 x 5 度图块包含 2500 x 2500 个网格点,以单元格中心表示(网格点不位于整数经线和平行线上)

您只需创建一个pv.UniformGrid该大小的并添加数据。例如:

import numpy as np
import pyvista as pv

arr = np.fromfile('N00E015.dem', dtype=np.int16)

grid = pv.UniformGrid()
grid.dimensions = (2500, 2500, 1)
grid.origin = (0, 0, 0) # you need to figure this out
grid['dem'] = arr

grid.plot()

在此处输入图像描述

为了获得网格的正确空间参考,您需要设置origin每个子集/网格的点。

此外,PyVista 社区在 PyVista 支持论坛上比在 Stack Overflow 上更活跃:https ://github.com/pyvista/pyvista-support

于 2021-02-18T17:53:00.737 回答