我正在尝试查找由某些坐标创建的多边形区域。我不确定如何一次遍历一行,因为它为循环的所有迭代存储了相同的区域。我需要在每次循环时对行进行索引,但是不确定如何执行此操作。
如果可以并且更容易使用chull
函数,那将是很棒的。
随附的是我尝试过的代码。
library(geosphere)
Time = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
Court_X1 = c(4, 6, 7, 8, 3, 2, 7, 8, 9, 1)
Court_X2 = c(2, 5, 4, 8, 2, 7, 9, 7, 2, 7)
Court_X3 = c(5, 7, 9, 2, 4, 6, 7, 3, 5, 7)
Court_X4 = c(7, 3, 7, 3, 2, 4, 6, 4, 7, 9)
Court_Y1 = c(2, 6, 7, 8, 9, 4, 2, 5, 7, 3)
Court_Y2 = c(7, 2, 4, 8, 3, 6, 5, 7, 2, 6)
Court_Y3 = c(4, 2, 6, 7, 8, 4, 5, 8, 6, 2)
Court_Y4 = c(3, 2, 1, 3, 7, 8, 9, 4, 2, 4)
surrogate_data = data.frame(Time, Court_X1, Court_X2, Court_X3, Court_X4, Court_Y1, Court_Y2, Court_Y3, Court_Y4)
surrogate_data = rbind(c(Court_X1),c(Court_Y1), c(Court_X2), c(Court_Y2), c(Court_X3), c(Court_Y3), c(Court_X4), c(Court_Y4), c(Court_X1), c(Court_Y1))
surrogate_data = t(surrogate_data)
temp = NULL
for ( i in 1:length(Time)){
temp[[i]] = areaPolygon(surrogate_data)
}
View(temp)
如果我添加此x = surrogate_data[i,]
并尝试按行进行索引,则最终会出现错误Error in (function (classes, fdef, mtable) :
unable to find an inherited method for function ‘area.poly’ for signature ‘"numeric"’