【发布时间】:2018-06-18 22:38:54
【问题描述】:
我有一个不同位置的几百个经纬度坐标对的列表。我的目标是使用 R 估算从“家”位置到每个坐标对的行驶时间。
我在 R 中使用 googleway 包取得了一些成功,但是(可以预见)在远离道路的位置遇到了问题,例如如果坐标是山顶。在这些情况下,我想估计到每个有问题的坐标对的最近道路的行驶时间。
为了说明,假设我的家庭位置是;
home <- "Edinburgh, UK"
...以及我想要查找的驾驶时间的示例数据框;
location <- c("place_a", "place_b", "place_c")
latitude <- c("56.87034", "57.69380", "57.36243")
longitude <- c("-4.199001", "-5.128715", "-5.104728")
df <- data.frame(location, latitude, longitude)
我可以使用类似的东西获得home和place_a之间以及home和place_b之间的距离/持续时间等;
(注意。您需要自己的 Google Maps api 密钥来复制此部分...)
library(googleway)
api_key <- [insert your Google Maps api key here!]
results <- google_distance(origins = home,
destinations = list(c("56.87034,-4.199001"),
("57.69380,-5.128715")),
mode = "driving",
key = api_key,
units = "imperial")
我得到了我想要使用的所有数据:
results$rows[[1]]
但是,当我们对 place_c 的坐标尝试相同的坐标时,我们遇到了麻烦,它返回 ZERO_RESULTS;
results2 <- google_distance(origins = home,
destinations = ("57.36243,-5.104728"),
mode = "driving",
key = api_key,
units = "imperial")
我认为这里的问题是坐标是半山腰,所以在这种情况下,我想找到离坐标最近的道路。我希望对googleway 的nearest_road 函数有一些运气,但似乎无法让它工作,例如这样的东西不起作用;
df_points <- read.table(text = "lat lon
57.36243 -5.104728", header = T)
nearest_road <- google_nearestRoads(df_points, key = api_key)
谁能告诉我这里的问题是什么?还是完全提出更好的解决方案?!
非常感谢。
【问题讨论】:
-
我只能猜测它离公路太远了,找不到。我必须将坐标移动到
57.14743 -5.054728才能正常工作。我在Google's documentation 中也看不到任何关于它必须离道路多近的信息。另一种方法可能是在苏格兰查找道路形状文件并使用地理空间操作,而不是 Google 的 API。 -
感谢@SymbolixAU。多亏了下面有用的帖子和
googlewaysgoogle_distance函数的组合,我最终到达了那里,以使用gmapsdistance克服错误。
标签: r google-maps latitude-longitude googleway