【发布时间】:2018-05-10 14:24:03
【问题描述】:
我有一个线串,代表沿着一些街道行驶的旅程。但我想实际代表一个骑自行车的人的旅程,它偏离这条线,即他们在路边附近行驶。我正在为如何做到这一点而苦苦挣扎。我制作了一段可重现的 R 代码来说明。
## Let's say I have a route along some streets.
library(ggplot2)
## It can be described by this
data <- data.frame(x = c(1,3,10,5,0,5),
y = c(1,3,1,0,5,7),
label = c('a', 'b', 'c', 'd', 'e', 'f'))
## Visualised by this
ggplot(data, aes(x, y)) +
geom_path() +
geom_text(aes(label=label),hjust=0, vjust=0)
但是我想做的事情就像有人在骑自行车一样。假设他们从道路中心线向左骑行 0.5 圈,但“左”当然是相对于线路的方向 旅程的开始实际上看起来像这样 注意“new_x”和“new_y” ' 在数学上不正确。它们是用于说明目的的估计值。
data <- data.frame(x = c(1,3,10,5,0,5),
y = c(1,3,1,0,5,7),
new_x = c(0.7, 3, 10.5,NA, NA, NA) ,
new_y = c(1.5, 3.5, 1, NA, NA, NA),
label = c('a', 'b', 'c', 'd', 'e', 'f'))
## Visualised by this showing the old line and the new line
ggplot(data, aes(x, y)) +
geom_path() +
geom_text(aes(label=label),hjust=0, vjust=0) +
geom_path(data = data, aes(new_x, new_y), colour='red')
所以问题是我如何正确计算 new_x 和 new_y 以创建一条连续的线,表示骑自行车者的旅程偏离道路中心
【问题讨论】:
标签: r coordinates gis geospatial spatial