【发布时间】:2019-06-11 12:27:44
【问题描述】:
我有两个经纬度点的数据框。 DatasetA 是一组位置。数据集 B 是距离数据集 A 50 英里(纵向)的一组位置。
我可以毫无意外地绘制两个数据集,如下面的代码所示。但是,当我计算 DatasetA 和 DatasetB 的点(最近点)之间的距离时,我得到不同的距离:
> points$Distance2radius
[1] 44.13807 41.92467 39.39219 36.55992 33.44940
我很难理解为什么这些会有所不同。我假设在 distm 中使用 Haversine 公式可以解释距离计算中的任何球面影响。
任何帮助将不胜感激。
library(leaflet)
library(geosphere)
### Make a dataframe of some test points ###
## Center of the US
dc.lat <- c(38.0000)
dc.long <- c(-97.0000)
## Make the data frame
lats <- c(dc.lat - 10, dc.lat - 5, dc.lat, 5 + dc.lat, 10 + dc.lat)
points <- data.frame(cbind(dc.long, lats))
names(points) <- c("long" , "lat")
coordinates(points) <- ~ long + lat
## The radius we are interested in, in miles
radius <- 50
## Add points that are the radius miles away from the center
points.at.radius <- data.frame(points)
#points$lat <- points$lat + radius/110.54
points.at.radius$long <- points$long + radius / 69.2
coordinates(points.at.radius) <- ~ long + lat
## Get distances with distm
distances <- distm (points, points.at.radius,
fun = distHaversine) / 1609
# Find the closest pint and add this distance to the data set
points$Distance2radius <-
apply(distances , 1, min)
# Plot these points and the points that are 50 miles away
m <- leaflet() %>%
addTiles() %>% # Add default OpenStreetMap map tiles
addCircleMarkers(data = points,
points$long,
points$lat,
color = "red") %>%
addPolygons(
data = gBuffer(
points,
width = radius / 69.2,
joinStyle = "ROUND",
byid = FALSE
),
color = "gray70",
group = "IWER area"
) %>%
addMarkers(data = points.at.radius,
points.at.radius$long,
points.at.radius$lat) %>% addPopups(
points$long,
points$lat,
47.597131,
points$Distance2radius,
options = popupOptions(closeButton = FALSE)
)
m # Print the map
【问题讨论】:
-
您忘记投影数据或计算未投影的半径距离。