小叶R结合了标记和测地线(以成对连接的坐标)



这是我的数据:

     InitialLat InitialLong  NewLat   NewLong
      62.46972    6.187194 51.4749 -0.221619
      48.09750   16.310800 51.4882 -0.302621

我可以在传单中与地质库成对连接我的坐标
(根据如何使用Reflet在R中的FLEES中连接两个坐标)

library(leaflet)
library(geosphere)
  mydf <- data.frame(InitialLat = c(62.469722,48.0975), # initial df
           InitialLong = c(6.187194, 16.3108),
           NewLat = c(51.4749, 51.4882),
           NewLong = c(-0.221619, -0.302621))
  p1 <- as.matrix(mydf[,c(2,1)]) # it's important to list lng before lat here
  p2 <- as.matrix(mydf[,c(4,3)]) # and here
  gcIntermediate(p1, p2,  
       n=100, 
       addStartEnd=TRUE,
       sp=TRUE) %>% 
 leaflet() %>% 
 addTiles() %>% 
 addPolylines()

如何将标记添加到?

我在没有成功的情况下尝试了这一点:

library(tidyr)    
markers <- mydf %>%
          select(1, 2)
lines <- gcIntermediate (p1, p2,  
             n=100, 
             addStartEnd=TRUE,
             sp=TRUE) 
  leaflet() %>%
  addTiles() %>%
  addPolylines(lines) %>%
  addMarkers(markers, lat =~InitialLat, long =~InitialLong)

您需要指定您的参数linesmarkersdata参数:

leaflet() %>%
  addTiles() %>%
  addPolylines(data = lines) %>%
  addMarkers(data=markers,lat =~InitialLat, lng =~InitialLong)

相关内容

  • 没有找到相关文章

最新更新