如何使用 python 读取或转换 .MAP 文件扩展名文档?

2024-06-28

是否有一种简单的方法(或可用的库)来读取“.map”文件扩展文档中的数据,最好使用Python(或R)?

我正在使用 python (PCRaster) 中的建模工具,该工具使用 .map 文件扩展名编写地图。然而有趣的是,我还没有找到可以打开和研究这些文件的 python 库。

Cheers,

这里提出了类似的问题,不幸的是没有答案 https://stackoverflow.com/questions/24393424/how-can-i-convert-a-map-file-to-a-fits-file

这里 .txt 文件被转换为 .map,但不知道如何反转 https://stackoverflow.com/questions/40877629/convert-text-file-to-plink-ped-and-map-format

以下是维基百科中 .map 文件格式的用例列表 https://en.wikipedia.org/wiki/MAP_(file_format)


因此,我还没有找到从 PCRaster 读取 .map 文件并能够直接绘制它们的方法,但我确实遇到了将 .map 文件转换为 Numpy 数组的功能,然后可以将其用于在其他地方绘制。

为此,NumpyAguila http://pcraster.geo.uu.nl/pcraster/4.0.1/doc/aguila/index.html and PCRaster http://pcraster.geo.uu.nl/downloads/latest-release/需要安装。之后,可以从 python 脚本文件运行命令。

从 PCRaster 映射到 Numpy:

pcr2numpy(map, mv)

从 Numpy 到 PCRaster

numpy2pcr(dataType, array, mv)

以下是来自的示例PCRasterPython 文档页面 http://pcraster.geo.uu.nl/pcraster/4.0.1/doc/python/pcraster/differences.html:

import numpy
from pcraster import *
from pcraster.numpy import *

setclone("clone.map")

a = numpy.array([[12,5,21],[9,7,3],[20,8,2],[5,6,-3]])

# conver a to a PCRaster Python map
# with the value 20 indicating a 'missing value' cell
n2p = numpy2pcr(Nominal, a, 20)
print "cellvalue:", cellvalue(n2p, 2, 3)[0]

# write it to a PCRaster map
report(n2p, "n2p.map")
# read the PCRaster map back
p2n = readmap("n2p.map")
# print it as a numpy array
# missing value is replaced by 9999
print pcr2numpy(p2n, 9999)

上面打印:

cellvalue: 3
[[  12    5   21]
 [   9    7    3]
 [9999    8    2]
 [   5    6   -3]]
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何使用 python 读取或转换 .MAP 文件扩展名文档? 的相关文章

随机推荐