R 求固定方位角处线与点之间的距离

max*_*bre 0 r r-sf

这是我的可重现的例子

\n
########################################\n\nlibrary(sf)\n\n# matrix of lon lat for the definition of the linestring\nm<-rbind(\n  c(12.09136, 45.86471),\n  c(12.09120, 45.86495),\n  c(12.09136, 45.86531),\n  c(12.09137, 45.86540),\n  c(12.09188, 45.86585),\n  c(12.09200, 45.86592),\n  c(12.09264, 45.86622),\n  c(12.09329, 45.86624),\n  c(12.09393, 45.86597),\n  c(12.09410, 45.86585),\n  c(12.09423, 45.86540),\n  c(12.09411, 45.86495),\n  c(12.09393, 45.86471),\n  c(12.09383, 45.86451),\n  c(12.09329, 45.86414),\n  c(12.09264, 45.86413),\n  c(12.09200, 45.86425),\n  c(12.09151, 45.86451),\n  c(12.09136, 45.86471)\n)\n\n# define a linestring\nls<-st_linestring(m)\n\n# create a simple feature with appropriate crs\nls<-st_sfc(ls, crs=4326)\n\n# and now again going through the very same \n# definition process for a point\n\n# define a point \npt <- st_point(c(12.09286,45.86557))\n\n# crate simple feature with appropriate crs\npt<-st_sfc(pt, crs = 4326)\n\nplot(ls)\nplot(pt, add=TRUE)\n\n# this is computing the minimum distance from the point to the line\nst_distance(ls, pt)\n\n\n###############\n
Run Code Online (Sandbox Code Playgroud)\n

给定上述玩具数据集,我需要找到合适的方法来计算:

\n

1 - 从线的每个顶点到给定点的距离:这可能很容易通过简单应用勾股定理计算每对点(线顶点与点)之间的距离来完成,即使我是由于使用了 crs(即 epsg 4326,以度为单位),因此对此非常可疑,因此我可能需要首先将整个数据集转换为另一个参考系统(使用公制单位)...

\n

2 - 固定方位角处的点与线之间的距离(距北10\xc2\xb0、20\xc2\xb0、30\xc2\xb0、....、360\xc2\xb0):这是我真正迷失的地方......

\n

请给我一些帮助,以便正确地进行计算,可能通过使用我现在正在尝试熟悉的“sf”标准

\n

谢谢

\n

max*_*bre 5

谢谢你为我指明了正确的方向

我制定了最终的解决方案,为了完整起见,我将其发布在这里

# my reproducible example

library(sf)

# matrix of lon lat for the definition of the linestring
m<-rbind(
  c(12.09136, 45.86471),
  c(12.09120, 45.86495),
  c(12.09136, 45.86531),
  c(12.09137, 45.86540),
  c(12.09188, 45.86585),
  c(12.09200, 45.86592),
  c(12.09264, 45.86622),
  c(12.09329, 45.86624),
  c(12.09393, 45.86597),
  c(12.09410, 45.86585),
  c(12.09423, 45.86540),
  c(12.09411, 45.86495),
  c(12.09393, 45.86471),
  c(12.09383, 45.86451),
  c(12.09329, 45.86414),
  c(12.09264, 45.86413),
  c(12.09200, 45.86425),
  c(12.09151, 45.86451),
  c(12.09136, 45.86471)
)

# define the linestring
ls<-st_linestring(m)

# create a simple feature linestring with appropriate crs
ls<-st_sfc(ls, crs=4326)

# and now again going through the very same 
# definition process for a point

# define the origin point 
pt <- st_point(c(12.09286,45.86557))

# create simple feature point with appropriate crs
pt<-st_sfc(pt, crs = 4326)

plot(ls)
plot(pt, add=TRUE)

# get minimum distance from the origin point to the line
dist_min<-st_distance(ls, pt)

# get cordinates of the origin point
pt_orig<-st_coordinates(pt)

# load library for later use of the function destPoint()
library(geosphere)

# create vector of bearing angles of 10 degress amplitude
b_angles<-seq(0, 350, 10) 

# create empty container for final result as data frame
result<-data.frame(bearing=NULL, distance=NULL)

for(i in 1:length(b_angles)){
  
  result[i,"bearing"]<-b_angles[i]
  
  # calculate destination point coordinates with bearing angle i
  # at fixed safe distance (i.e. 100 times the minimum distance)
  # so that to avoid null intersection in next step calculation
  pt_dest<-destPoint(p=pt_orig, b=b_angles[i],d=dist_min*100)
  
  # define linestring from origin to destination
  b_ls<-st_sfc(st_linestring(rbind(pt_orig, pt_dest)), crs=4326)
  
  # get the intersection point between two features
  pt_int<-st_intersection(ls, b_ls)
  
  # get the distance
  d<-st_distance(pt, pt_int)
  
  result[i,"distance"]<-d
}
Run Code Online (Sandbox Code Playgroud)

我尽可能坚持使用“sf”方法,该方法在 for 循环内给出以下警告,与 st_intersection() 的执行相对应:“虽然坐标是经度/纬度,但 st_intersection 假设它们是平面的”

但考虑到我工作的距离很短,在我看来这是一个可以接受的近似值

顺便说一句,据我了解,“sf”包中不存在与 geosphere::destPoint 相对应的函数

谢谢