[英]How to extract information based on shapefile from dataframe?
I have a dataframe我有一个 dataframe
lon lat year U CP PS FR NT
1: 87 46 1650 0 0 0.198 0 0.802
2: 87 46 1651 0 0 0.197 0 0.803
3: 87 46 1652 0 0 0.195 0 0.805
4: 87 46 1653 0 0 0.193 0 0.807
5: 87 46 1654 0 0 0.192 0 0.808
6: 87 46 1655 0 0 0.190 0 0.810
I have dataframe that covers lon and lat globally.我有 dataframe 涵盖全球经度和纬度。 I would like to extract information according to my shape file.
我想根据我的形状文件提取信息。 I donot know how can I make a reproducible example of raster showing global data.
我不知道如何制作一个可重现的显示全局数据的栅格示例。 But I have made snippet show longitude and latitude.
但我已经制作了片段显示经度和纬度。
Here is how you can make a global raster这是制作全局栅格的方法
library(raster)
r <- raster()
values(r) <- 1:ncell(r)
You can then extract values for point locations like this然后,您可以像这样提取点位置的值
lonlat <- cbind(c(87, 86), c(46, 47))
extract(r, lonlat)
[1] 16108 15747
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.