我正在尝试编写一个函数来创建一个方形边框周围的坐标(Lat,Long)。
首先,我需要为Lat-Long"添加"一个距离(比如5公里)。
- 我可以忽略边长为10公里的小网格的投影吗?
- 我可以忽略球面考虑的最大近似方形盒子是多少?
- 我如何在纬度/经度(24.5,-88.65)上加减X公里(比如5)来获得边界框的边缘?
注:我的工作在美国大陆,如果有帮助的话。
在封装geosphere
中有一个称为destPoint()
的函数,它将初始位置、方向(以度为单位的角度)和距离(以米为单位)作为输入。你可以用这个函数两次,一次用于水平方向,一次用于垂直方向。例如:
library(geosphere)
# Starting longitude and latitude:
coords <- c(-71, 42)
# Distance in meters:
distance <- 5000
ne.coords <- c(destPoint(p = coords, b = 90, d = distance)[1],
destPoint(p = coords, b = 0, d = distance)[2])
sw.coords <- c(destPoint(p = coords, b = 90, d = -distance)[1],
destPoint(p = coords, b = 0, d = -distance)[2])
这给:
R> ne.coords
[1] -70.93965 42.04502
R> sw.coords
[1] -71.06035 41.95498