Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从点坐标创建SpatialLinesDataFrame_R_Sp - Fatal编程技术网

从点坐标创建SpatialLinesDataFrame

从点坐标创建SpatialLinesDataFrame,r,sp,R,Sp,我正在做一个动物追踪项目。我的数据“finaltrimmed”如下所示 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

我正在做一个动物追踪项目。我的数据“finaltrimmed”如下所示

  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。最后,我想使用“AdeTMA”包中的“buffer”函数在每一行周围创建一个缓冲区

我能够使用以下命令创建一个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)

xy以下是一种可行的方法:

示例数据:

finaltrimmed <- read.table(text="TrackIndex  Time x_position y_position
1    1   0.1034  425  171
2    1   0.1379  425  169
3    1   0.1724  427  166
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
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")

finaltrimmed自己没有使用它,但这可以工作:
finaltrimmed <- read.table(text="TrackIndex  Time x_position y_position
1    1   0.1034  425  171
2    1   0.1379  425  169
3    1   0.1724  427  166
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
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")
library(raster)
ft <- split(finaltrimmed, finaltrimmed$TrackIndex)

z <- lapply(ft, function(i) spLines(as.matrix(i[, c('x_position', 'y_position')]), attr=data.frame(TrackIndex=i$TrackIndex[1])))
names(z) <- NULL
zz <- do.call(bind, z)