我有一个数据框(predHB.Lv1Hard),其中包含3列“y”=经度,“x”=纬度和“predLv1Hard”=模型输出的概率。所有列都是数字。
>头(predHB.Lv1Hard) …
检查包裹 raster 。
raster
首先需要将数据帧转换为栅格文件(重新排列列以匹配xyz):
r <- rasterFromXYZ(predHB.Lv1Hard[,c(2,1,3)])
然后使用:
writeRaster(r,'filename.asc', format='ascii')
如果这些点不在常规网格中,您可以尝试该功能 rasterize 。我可以用该文件的头部做很多事情,但一个例子可能是:
rasterize
# Convert to SpatialPoinDataFrane coordinates(predHB.Lv1Hard) <- ~x+y # Calculate the extent of the observations ext <- extent(predHB.Lv1Hard) # Get the distance between points table(diff(predHB.Lv1Hard@coords[,1])) #0 0.00010000000000332 #3 2 # With the limited info I have I could assume that the resolution is 0.00010000000000332 degrees. # If you know the original resolution, much better. # Create the template r <- raster(ext=ext,res=0.00010000000000332) # Final raster to_ascii <- rasterize(predHB.Lv1Hard, r, 'predLv1Hard') # Write raster to ascii writeRaster(to_ascii,'filename.asc', format='ascii')