Fastest way to determine COUNTRY from millions of GPS coordinates [R]

丶灬走出姿态 提交于 2019-12-04 13:45:50

There are two similar questions. They are in my comments above. The questions are asking how to get country names from coordinates. Here the OP is asking which is a faster way to do the task. Based on the posts, we have three options. One is to use the custom function in this question. Another is to use the geonames package. The other is to use map.where() in the map package. The second option needs a bit of setup. So I just tested map.where(). The following is the result. As the OP said, this function is working must faster.

library(maps)
set.seed(111)
data <- data.table(latitude=sample(seq(47,52,by=0.001), 1000000, replace = TRUE),
                   longitude=sample(seq(8,23,by=0.001), 1000000, replace = TRUE))

system.time(data[, country := map.where(x = longitude, y = latitude)])

#   user  system elapsed 
#   7.20    0.05    7.29 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!