我正在尝试计算海洋位置和陆地点之间最近的距离,但不通过海岸线。最终,我想创建一个到陆地特征的距离地图。
此地图是使用rdist.earth创建的,是一条直线距离。因此,它并不总是正确的,因为它没有考虑海岸线的曲率。
c<-matrix(coast_lonlat[,1], 332, 316, byrow=T)
image(1:316, 1:332, t(c))
min_dist2_feature<-NULL
for(q in 1:nrow(coast_lonlat)){
diff_lonlat <- rdist.earth(matrix(coast_lonlat[q,2:3],1,2),as.matrix(feature[,1:2]), miles = F)
min_dist2_feature<-c(min_dist2_feature, min(diff_lonlat,na.rm=T))
}
distmat <- matrix( min_dist2_feature, 316, 332)
image(1:316, 1:332, distmat)
陆地特征数据是一个包含xy坐标的二列矩阵,例如:
ant_x <- c(85, 90, 95, 100)
ant_y <- c(-68, -68, -68, -68)
feature <- cbind(ant_x, ant_y)
有没有人有什么建议?谢谢。