my_raster.tiff文件是2013年中国体内PM2.5的浓度。
为了重现代码,我将数据(my_raster.tiff)上传到Github (https://github.com/lizhiwei1994/example_data/blob/main/my_raster.tiff)。
我想从中国光栅地图(my_raster.tiff)中提取北京(中国首都) PM2.5的平均浓度。
具体来说,代码会将一个值分解成规则,可能如下所示:
data.frame(city = 'Beijing', PM2.5 = 56.66) # PM2.5 = 56.66 is a fake number made up by myself
city PM2.5
1 Beijing 56.66发布于 2022-04-22 05:47:05
示例数据
library(terra)
f <- system.file("ex/elev.tif", package="terra")
pm <- rast(f)
names(pm) <- "PM2.5"
f <- system.file("ex/lux.shp", package="terra")
v <- vect(f)[1]
v$city = "Beijing"解决方案
e <- extract(pm, v, fun=mean, na.rm=TRUE)
data.frame(city=v$city, e[,-1,drop=FALSE])
# city PM2.5
#1 Beijing 467.1052https://stackoverflow.com/questions/71949939
复制相似问题