简体   繁体   English

栅格到缺少值的点

[英]Raster to points with the missing values

I'm using the function rasterToPoints() from the package raster . 我正在使用raster包中的函数rasterToPoints() By default, this function omits the NA values. 默认情况下,此函数忽略NA值。

raster <- raster(matrix(c(1,2,NA, 1,2,3, 1,2,3), nrow = 3, ncol = 3 ))
raster_points <- rasterToPoints(raster, na.rm = FALSE)

Therefore, I put a raster with 200 cells and I get a data.frame with only 150 rows. 因此,我放置了一个具有200个像元的栅格,并且得到了只有150行的data.frame。 How can I obtain the point with empty cells in my final data.frame? 如何在最终data.frame中获得带有空白单元格的点?

You could combine xyFromCell , values , and cbind . 您可以结合使用xyFromCellvaluescbind This returns the central coordinates of each cell (when you initialized the raster, it assumes a 1 x 1 extent unless defined otherwise) and its value, including NAs , in matrix form: 这将以矩阵形式返回每个像元的中心坐标(初始化栅格时,除非另有定义,否则它假定为1 x 1范围)及其值(包括NAs

cbind(xyFromCell(raster, 1:ncell(raster)), values(raster))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM