【问题标题】:Finding coordinates from heading and distance in R从R中的航向和距离查找坐标
【发布时间】:2021-11-03 06:48:51
【问题描述】:

我想获得新点的坐标,最好使用 sf 包,当初始位置以及行进的距离和航向已知时。 考虑一下;我们有三个点(pts),附有一个航向和一个以公里为单位的距离。如何找到新位置的坐标?

library(data.table, dplyr, sf)
dat <- data.table(lon = c(10,10.1,10.4), lat = c(58.4,57.4,57.8), 
                      heading = c(45,10,235), distance_km = c(1,5.3,3))
pts <- dat %>%
      sf::st_as_sf(coords = c("lon","lat")) %>%
      sf::st_set_crs(4326)

Simple feature collection with 3 features and 2 fields
Geometry type: POINT
Dimension:     XY
Bounding box:  xmin: 10 ymin: 57.4 xmax: 10.4 ymax: 58.4
Geodetic CRS:  WGS 84
  heading distance_km          geometry
1      45         1.0   POINT (10 58.4)
2      10         5.3 POINT (10.1 57.4)
3     235         3.0 POINT (10.4 57.8)

正在考虑围绕这些点制作圆圈,但不知道如何将点连接到具有正确航向的圆圈。

buf <- st_buffer(pts, dist = pts$distance_km*1000)
circ <- st_cast(buf, "LINESTRING")

【问题讨论】:

    标签: distance sf heading 360-degrees


    【解决方案1】:

    在这里找到答案:Calculate coordinate from starting point, having distance and an angle for all quadrants 和这里: Convert radians to degree / degree to radians

    将发布我的 R 解决方案以确保完整性。如果有人有更好或更流畅的解决方案,请随时发布。

    library(data.table, sf, mapview)
    dat <- data.table(lon = c(10,10.1,10.4), lat = c(58.4,57.4,57.8), 
                      heading = c(45,10,235), distance_km = c(1,5.3,3))
    
    pts <- dat %>%
      sf::st_as_sf(coords = c("lon","lat")) %>%
      sf::st_set_crs(4326)
    
    pts <- st_transform(pts, 32632)
    pts$utm_n <- st_coordinates(pts)[,1]
    pts$utm_e <- st_coordinates(pts)[,2]
    
    buf <- st_buffer(pts, dist = pts$distance_km*1000)
    
    circ <- st_cast(buf, "LINESTRING")
    
    rad2deg <- function(rad) {(rad * 180) / (pi)}
    deg2rad <- function(deg) {(deg * pi) / (180)}
    
    pts$newp_e <- pts$utm_e + (pts$distance_km*1000* cos(deg2rad(pts$heading)))
    pts$newp_n <- pts$utm_n + (pts$distance_km*1000* sin(deg2rad(pts$heading)))
    
    dt <- data.table(pts)
    
    pts2 <- dt %>%
      sf::st_as_sf(coords = c("newp_n", "newp_e")) %>%
      sf::st_set_crs(32632)
    
    mapview(pts2) + mapview(pts, zcol = "heading") + mapview(circ)
    

    【讨论】:

      猜你喜欢
      • 2018-02-15
      • 1970-01-01
      • 2013-06-20
      • 2016-11-06
      • 1970-01-01
      • 2020-08-06
      • 1970-01-01
      • 1970-01-01
      • 2012-06-13
      相关资源
      最近更新 更多