将栅格导入 R - 值显示为 NA? [英] Import raster to R - values appear as NAs?
本文介绍了将栅格导入 R - 值显示为 NA?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为什么 R 为导入的栅格值显示 NA?
Why does R display NA for the values of an imported raster?
#load libraries
library(raster)
#set working directory
setwd("C:/Users/Documents/myData")
#import raster data
r <- raster("myRasterdata.tif")
返回:类:光栅层
dimensions: 34073, 19663, 669977399 (nrow, ncol, ncell)
resolution : 30, 30 (x, y)
extent : -969193.5, -379303.5, 277627.9, 1299818 (xmin, xmax, ymin, ymax)
coord. ref. : +proj=lcc +lat_1=49 +lat_2=77 +lat_0=49 +lon_0=-95 +x_0=0 +y_0=0 +datum=NAD83 +units=m +no_defs +ellps=GRS80 +towgs84=0,0,0
data source : C:/Users/Documents/myData/myRasterdata.tif
names : dem
values : 0, 1857 (min, max)
如您所见,它可以很好地导入文件,并显示有从 0 到 1857 的值,但是当我使用函数 head(r) 时,我返回了所有 NA 值.
As you can see, it imports the file fine, and shows that there are values ranging from 0 to 1857, but when I use the function head(r), I get all NA values returned.
同样,当我导入许多栅格并构建堆栈时,以及当我尝试读取 GDAL 函数时也是如此.
Likewise when I import many rasters and build a stack, and likewise when I try to readGDAL function.
因此,当我尝试对多边形图层执行提取"功能时,我会返回所有 NA 值.
So when I try to do an "extract" function with a polygon layer, I get all NA values returned.
推荐答案
您可以使用 trim 函数删除 NA 值.
You can use the trim function to remove NA values.
r<-trim(r)
这篇关于将栅格导入 R - 值显示为 NA?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文