因此,我还没有找到从 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]]