【问题标题】:Fastest way to get the timezone from big data set of coordinates(a million coordinates or more)从坐标大数据集中获取时区的最快方法(一百万个坐标或更多)
【发布时间】:2018-10-20 01:52:25
【问题描述】:

在大型坐标数据集的文本中获取本地时区的最快方法是什么?我当前的方法运行良好,但我使用的包“rundel/timezone”(这对于小型集合很简单且非常有用)对于大型集合来说非常慢。

有没有更快的方法来完成下面重现的任务?:

  library(data.table)

#REPRODUCE DATA
  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))

  ###get timezone package via rundel/timezone
  if (!require("timezone")) devtools::install_github("rundel/timezone")
  library(timezone)


###CURRENT SLOW METHOD 

system.time(data[,timezone:=find_tz(longitude,latitude),])
       user  system elapsed 
     49.017  21.394  74.086 

【问题讨论】:

  • 我碰巧找到了名为lutz的包。你检查了吗?
  • @jazzurro,不,我没有看到这一点,就我的目的而言,method="fast" 效果很好。感谢您的提示!
  • 我认为您想检查一切是否准确。 tz_lookup_coords() 可能导致远离人口稠密地区边界附近的时区不准确。
  • 之前的评论已删除。

标签: r timezone coordinates geospatial


【解决方案1】:

当我看到这个问题时,我碰巧找到了lutz 包。这个包似乎适用于 OP。我想在这里留个便条会很好。在包中,有一个名为tz_lookup_coords() 的函数。您可以使用此功能以两种方式设置方法。一个是method = "fast",另一个是method = "accurate"。如果您想要速度,请选择第一个选项。如果您想要准确性,请选择第二个选项。我留下以下结果。您会看到时间上的巨大差异。

library(lutz) 
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[, timezone := tz_lookup_coords(lat = latitude, lon = longitude, method = "fast")])

#user  system elapsed 
#6.46    3.42    9.92 

#Warning message:
#Using 'fast' method. This can cause inaccuracies in timezones
#near boundaries away from populated ares. Use the 'accurate'
#method if accuracy is more important than speed. 

system.time(data[, timezone := tz_lookup_coords(lat = latitude, lon = longitude, method = "accurate")])

#  user  system elapsed 
#154.44    0.18  154.93 

【讨论】:

  • 从您的评论来看,这正是我最终得到的。它比以前快了大约 10 倍。不知道 lutz 存在。
  • @NealBarsch 看到不同之处我很惊讶。我很高兴这个包对你有帮助!
  • 谢谢 - 我将这里提到的两个 R 库添加到 the list
猜你喜欢
  • 2019-03-25
  • 2018-10-31
  • 2018-11-07
  • 2016-10-04
  • 1970-01-01
  • 2015-04-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多