我目前有一个数据框,包含球员姓名、时间、纬度、经度和速度(以米/秒为单位)。我想绘制出球员的热力图,但问题在于将纬度和经度转换为足球场图片上的x和y位置。
目前可以像下面的图1一样绘制出纬度和经度路径,但值的方向不是平坦足球场的方向,而是类似于图2。
目前可以像下面的图1一样绘制出纬度和经度路径,但值的方向不是平坦足球场的方向,而是类似于图2。
我希望能够将纬度和经度值转换为足球场上的位置x和位置y,并输出类似于下面的图表。
到目前为止,我所尝试的是从Google地图中获取左上角、左下角、右上角和右下角的最大和最小经纬度值。计算出场地的长度和宽度,然后使用以下公式向数据框添加了两列。但这并没有解决我的问题,有什么想法吗?非常感谢。#pitch dimensions taken from google
top_left_lat <- 51.662233
top_left_lon <- -0.273183
top_right_lat <- 51.662518
top_right_lon <- -0.272164
bottom_left_lat <- 51.661337
bottom_left_lon <- -0.272539
bottom_right_lat <- 51.661630
bottom_right_lon <- -0.271528
#calculate pitch length
pitch_length <- acos(cos(deg2rad(90 - top_left_lat)) * cos(deg2rad(90 - bottom_left_lat))
+ sin(deg2rad(90 - top_left_lat)) * sin(deg2rad(90 - bottom_left_lat))
* cos(deg2rad(top_left_lon - bottom_left_lon))) * 6371
pitch_length
#calculate pitch width
pitch_width <- acos(cos(deg2rad(90 - top_left_lat)) * cos(deg2rad(90 - top_right_lat))
+ sin(deg2rad(90 - top_left_lat)) * sin(deg2rad(90 - top_right_lat))
* cos(deg2rad(top_left_lon - top_right_lon))) * 6371
pitch_width
#convert lat lon to pos x and y on a pitch
a <- mutate(a, posX = (pitch_width/360)*(180 + a$Lon))
a <- mutate(a, posY = (pitch_length/180)*(90 - a$Lat))