R:如何从一串坐标创建多线串 sf

R : How to create multilinestring sf from a tibble of coordinates

考虑以下小标题:

my_tible <- tibble("ID" = c("A","A","A","B","B", "C","C") , X=  c(647851,647875,647875,647766,647766,647826,647822) , 
               Y=c(6859335,6859318,6859319,6859028,6859030,6859314,6859316) )

我想根据那个小标题创建一个 sf 多线串 object :

my_tible %>% 
   group_by(ID) %>% 
   summarise("geometry" = c(X,Y) %>% 
          as.numeric() %>% 
          matrix(ncol = 2, byrow = F) %>% 
          list() %>% 
          st_multilinestring()) %>% 
   st_sf() %>% 
   st_set_crs("+init=epsg:2154") %>% 
   st_transform(crs="+proj=longlat +datum=WGS84")

我在 st_sf() 之后收到以下消息: "Error in st_sf(.) : no simple features geometry column present."

我想了解我做错了什么。

解决方案:

my_tible %>% 
  st_as_sf( coords = c("X", "Y")) %>% 
  group_by(ID) %>% 
  summarize() %>%
  st_cast("MULTILINESTRING") %>% 
  st_set_crs("+init=epsg:2154") %>% 
  st_transform(crs="+proj=longlat +datum=WGS84")

一个解决方案:

my_tible %>% 
  st_as_sf( coords = c("X", "Y")) %>% 
  group_by(ID) %>% 
  summarize() %>%
  st_cast("MULTILINESTRING") %>% 
  st_set_crs("+init=epsg:2154") %>% 
  st_transform(crs="+proj=longlat +datum=WGS84")