R 将空间插槽转换为列表
我有一个带有1657条不同路径的SpatialLines数据帧。每条路线的长度不同,节点或航路点的数量也不同(lat、lon) 例如,R 将空间插槽转换为列表,r,list,geo,sp,R,List,Geo,Sp,我有一个带有1657条不同路径的SpatialLines数据帧。每条路线的长度不同,节点或航路点的数量也不同(lat、lon) 例如,routes@line[[87]]由7个航路点组成。我想知道是否有一种简单的方法来提取每条路线的纬度、经度坐标,或[,1]和[,2],并将它们转换为1657的列表 当我用一个routes@line[[87]],例如,我得到一个错误: > as.list(routes@lines[[87]]) Error in as.list.default(routes@l
routes@line[[87]]
由7个航路点组成。我想知道是否有一种简单的方法来提取每条路线的纬度、经度坐标,或[,1]和[,2],并将它们转换为1657的列表
当我用一个routes@line[[87]]
,例如,我得到一个错误:
> as.list(routes@lines[[87]])
Error in as.list.default(routes@lines[[87]]) :
no method for coercing this S4 class to a vector
是否存在将线对象转换为列表的方法
> str(routes)
Formal class 'SpatialLinesDataFrame' [package "sp"] with 4 slots
..@ data :'data.frame': 1657 obs. of 3 variables:
.. ..$ start_time: Factor w/ 1631 levels "2016/09/09 00:00:02",..: 1 2 3 4 5 6 7 8 9 10 ...
.. ..$ duration : int [1:1657] 786 1248 738 786 651 660 616 889 408 475 ...
.. ..$ difftime :Class 'difftime' atomic [1:1657] 2 4 19 67 92 119 170 202 206 213 ...
.. .. .. ..- attr(*, "units")= chr "secs"
..@ lines :List of 1657
> routes@lines[[87]]
An object of class "Lines"
Slot "Lines":
[[1]]
An object of class "Line"
Slot "coords":
[,1] [,2]
[1,] -79.92976 43.25867
[2,] -79.92984 43.25865
[3,] -79.92986 43.25868
[4,] -79.92989 43.25870
[5,] -79.92983 43.25871
[6,] -79.92983 43.25871
[7,] -79.92983 43.25871
Slot "ID":
[1] "87"
可能值得一看,这是对
库(sp)
的更新。您可以使用sf::st_as_sf()
将sp
对象转换为sf
,并且每一行都将表示为一个列表,在数据的一行中。帧
也可能值得一看routes@lines[[87]]@line[[1]]@coords
-这是坐标矩阵所在的位置,假设lines对象只有一条直线。