计算R中两个坐标之间间隔的点

Calculate points at intervals between two coordinates in R

我有一系列坐标,我从中采样了数据,这是地图上的一个例子:

library(ggplot2)
library(ggmap)
library(dismo)
lon <- c(-64.723946, -64.723754, -64.723808, -64.724004)
lat <- c(32.350843, 32.350783, 32.350618, 32.350675)
df <- as.data.frame(cbind(lon,lat))

mapgilbert <- get_map(location = c(lon = mean(df$lon), lat = mean(df$lat)), zoom = 18, maptype = "satellite", scale = 2)
ggmap(mapgilbert) +
  geom_point(data = df, aes(x = lon, y = lat, fill = "red", alpha = 0.8), size = 5, shape = 21) +
  guides(fill=FALSE, alpha=FALSE, size=FALSE) +
  scale_x_continuous(limits = c(-64.725, -64.723), expand = c(0,0)) +
  scale_y_continuous(limits = c(32.350, 32.351), expand = c(0,0))

这是生成的图像:

我想在地图上的南北点和东西点之间画线 - 做一个加号。

但是我希望这条线包含点而不仅仅是一条线,所以我需要计算点的坐标。线大约三十米,我需要每米一个点。我觉得 sp 包可能允许这样的事情,但我不知道如何。

谢谢,

凯兹

重新排列你的数据框;您真正需要的只是 seq。这里是 Hadley 风格,但可以根据需要手动构建:

library(dplyr)
library(tidyr)

              # group rows by opposite pairs
df2 <- df %>% group_by(group = lon %in% range(lon)) %>% 
    # summarize lat and lon for each group into a list of a sequence from the first to the second
    summarise_each(funs(list(seq(.[1], .[2], length.out = 10)))) %>% 
    # expand list columns with tidyr::unnest
    unnest()

head(df2)
# Source: local data frame [6 x 3]
# 
#   group       lon      lat
#   (lgl)     (dbl)    (dbl)
# 1 FALSE -64.72395 32.35084
# 2 FALSE -64.72393 32.35082
# 3 FALSE -64.72392 32.35079
# 4 FALSE -64.72390 32.35077
# 5 FALSE -64.72388 32.35074
# 6 FALSE -64.72387 32.35072

# all I changed here is data = df2
mapgilbert <- get_map(location = c(lon = mean(df$lon), lat = mean(df$lat)), zoom = 18, maptype = "satellite", scale = 2)
ggmap(mapgilbert) +
    geom_point(data = df2, aes(x = lon, y = lat, fill = "red", alpha = 0.8), size = 5, shape = 21) +
    guides(fill=FALSE, alpha=FALSE, size=FALSE) +
    scale_x_continuous(limits = c(-64.725, -64.723), expand = c(0,0)) +
    scale_y_continuous(limits = c(32.350, 32.351), expand = c(0,0))