Create buffer and count points in R

醉酒当歌 提交于 2019-12-01 14:57:13

Came up with a (simple) solution for my own question using geosphere:

cbind(coordinates(all.df), X=rowSums(distm (coordinates(all.df)[,1:2], fun = distHaversine) / 1000 <= 10)) # number of points within distance 10 km
    Longitude Latitude  X
0   -119.8304 34.44190 25
1   -119.6768 34.41962 29
2   -119.7162 34.41911 34
3   -119.7439 34.44017 39
4   -120.4406 34.63925 13
5   -119.5296 34.40506  7
6   -120.4198 34.93860 26
7   -119.8221 34.43598 30
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!