我正在做一个动物跟踪项目。我的数据“finaltrimmed”看起来像这样从点坐标创建SpatialLinesDataFrame
TrackIndex Time x_position y_position
1 1 0.1034 425 171
2 1 0.1379 425 169
3 1 0.1724 427 166
.........
125 25 1.1030 462 397
126 25 1.1380 462 397
127 25 1.1720 462 397
128 25 1.2070 462 397
129 25 1.2410 461 398
130 25 1.2760 462 399
131 25 1.3100 461 399
132 25 1.3450 461 399
133 25 1.3790 460 399
134 25 1.4140 460 399
.....
268 41 1.8280 302 280
269 41 1.8620 303 279
270 41 1.8970 302 280
271 41 1.9310 302 280
272 41 1.9660 302 281
273 41 2.0000 302 281
274 41 2.0340 302 281
275 41 2.0690 302 282
276 41 2.1030 302 282
277 41 2.1380 302 282
278 41 2.1720 302 283
........
我要为每一个独特的TrackIndex,随着时间的推移,基本上如何跟踪每个个体昆虫招行。从那里我想创建一个基于TrackIndex的SpatialLinesDataFrame。最后,我想在“adehabitatMA”包中使用“缓冲区”功能在每条线周围创建一个缓冲区。
我能创建使用以下命令SpatialPointsDataFrame。
xy<-cbind(finaltrimmed$x_position,finaltrimmed$y_position)
MatrixofPoints<-matrix(xy,ncol=2)
points<-SpatialPoints(MatrixofPoints)
dataframe=data.frame(finaltrimmed$TrackIndex)
df.points<-SpatialPointsDataFrame(points,dataframe)
但是,我无法以类似的方式创建SpatialLinesDataFrame。
我的想法是分割数据帧“最终修整”先用“分裂”功能。
splitfinal<-split(finaltrimmed,finaltrimmed$TrackIndex)
这使我有下面的数据结构 $ 1
TrackIndex时间x_position y_position newindex 1:1246 347.0 316 214 1 2:1246 347.0 316 214 2 ...... :1246 348.9 325 201 57 58 :1246 349.0 330 201 58 TrackIndex时间x_position y_position newindex
$ 25
TrackIndex时间x_position y_position newindex 1:1318 363.6 375 422 1 2:1318 363.7 375 422 2 ..... 57:1318 365.6 399 406 57 58:1318 365.6 400 406 58 从那里,我可以cbind的x和y位置在“splitfinal”(这个步骤没有解决,因为“splitfinal”是列表的列表)。我也不确定如何创建一个Lines类,这是创建SpatialLinesDataFrame所必需的。
我一直坚持了很多天,想不出办法。
任何人都可以帮忙吗?
没有使用它自己,但是这可能工作:https://开头rpubs.com/walkerke/points_to_line – lbusett