如何创建一个以" c(df $ lat,cd $ lon)为中心的填充圆的栅格层"和radius" df $ radius"?
df <- data.frame(lat=c(40.4,42.4,42.4,42.4,42.3),
lon=c(-0.3,1,1.5,2.7,2.1),
radius=c(4.4,8.4,11.4,5.4,10.3))
df
# lat lon radius
# 40.4 -0.3 4.4
# 42.4 1.0 8.4
# 42.4 1.5 11.4
# 42.4 2.7 5.4
# 42.3 2.1 10.3
library(dismo)
df <- data.frame(lat=c(40.4,42.4,42.4,42.4,42.3),
lon=c(-0.3,1,1.5,2.7,2.1),
radius=c(4.4,8.4,11.4,5.4,10.3))
请注意使用LON/LAT,而不是LAT/LON
p <- df[,2:1]
半径为米,因此您的数字很小。我会更改它们
rad <- df[,3]*2500
计算圆
cc <- circles(p, rad, lonlat=TRUE, dissolve=FALSE)
plot(cc)
points(p)
获得多边形
pls <- polygons(cc)
要获得rasterlayer,您可以使用predict(cc, )
或rasterize(pls, )
r <- raster(extent(pls), res=.01)
pr <- predict(cc, r)
(如果您不希望对重叠进行计数,请在circles
函数中使用dissolve=TRUE
)