R求固定方位角下直线和点之间的距离

R求固定方位角下直线和点之间的距离,r,sf,R,Sf,这是我重复的例子 ######################################## 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

这是我重复的例子

########################################

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 a linestring
ls<-st_linestring(m)

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

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

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

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

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

# this is computing the minimum distance from the point to the line
st_distance(ls, pt)


###############
########################################
图书馆(sf)
#用于定义线串的lon-lat矩阵

谢谢你给我指出了正确的方向

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

# 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
}
#我的可复制示例
图书馆(sf)
#用于定义线串的lon-lat矩阵
M