【发布时间】:2021-06-09 08:45:34
【问题描述】:
我尝试在点 p1 周围创建几个点,距离为 km_distance。不知何故 km_distance 有奇怪的行为,不作为预期工作。我在某处搞错了。
p1<-c(11.829831, 48.110075)
km_distance<-13
LatDec <- p1[2]
LonDec <- p1[1]
b <- geosphere::bearing(p1, p2,a = 6378137, f = 1/298.257223563)
Km <- km_distance
ER <- 6378 #Mean Earth radius in kilometers.
if(b < 0) {
AngDeg <- seq(b + span_degree,b - span_degree)
}else
{
AngDeg <- seq(b-span_degree,b+span_degree)
}
#AngDeg <- seq(b+100,b-100) #angles in degrees
Lat1Rad <- LatDec*pi/180#Latitude of the center of the circle in radians
Lon1Rad <- LonDec*pi/180#Longitude of the center of the circle in radians
AngRad <- AngDeg*pi/180#angles in radians
Lat2Rad <- asin(sin(Lat1Rad)*cos(Km/ER) + cos(Lat1Rad)*sin(Km/ER)*cos(AngRad)) #Latitude of each point of the circle rearding to angle in radians
Lon2Rad <- Lon1Rad + atan2(sin(AngRad)*sin(Km/ER)*cos(Lat1Rad),cos(Km/ER) - sin(Lat1Rad)*sin(Lat2Rad))#Longitude of each point of the circle rearding to angle in radians
Lat2Deg <- Lat2Rad*180/pi#Latitude of each point of the circle rearding to angle in degrees (conversion of radians to degrees deg = rad*(180/pi) )
Lon2Deg <- Lon2Rad*180/pi#Longitude of each point of the circle rearding to angle in degrees (conversion of radians to degrees deg = rad*(180/pi) )
point_on_circle <- cbind(Lon2Deg,Lat2Deg)
point_on_circle<-as.data.frame(point_on_circle)
point_on_circle <- point_on_circle[seq(1, nrow(point_on_circle), 10), ]
如果我跑步
apply(point_on_circle, 1,function(x) geodist::geodist_vec(p1[1], p2[2], as.numeric(x[1]), as.numeric(x[2]), paired = TRUE, measure = "geodesic"))
我预计到点的距离约为 13 公里,但我得到的距离要大得多。
【问题讨论】:
标签: r geolocation data.table tidyverse geospatial