如何在 python pyvista 中读取 dem 文件

How to read dem files in python pyvista

我有像这里这样的 .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]

导致错误消息:

OverflowError:SetDimensions 参数 1:值超出 int 范围

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

非常感谢:)

@larsks 在上面的评论中是正确的。这些“.dem”文件不是 PyVista 和它包装的 VTK reader 期望的格式。您应该使用 np.fromfile 来读取数据:arr = np.fromfile('N00E015.dem', dtype=np.int16)。进一步从 the docs listed at your link:

Due to its total size of 44 GB, the model is partitioned and distributed in terms of 881 binary files of 5 deg x 5 deg size for each functional. Each 5 deg x 5 deg tile contains 2500 x 2500 grid points in centre-of-cell representation (grid points are not situated on integer meridians and parallels)

您只需创建一个 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()

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

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