我正在玩concaveman
包。
我正在使用此示例代码在一些测试点周围创建凹壳的多边形:
library(concaveman)
data(points)
polygons <- concaveman(points)
plot(points)
plot(polygons, add = TRUE)
但是,多边形df的所有坐标都挤成一排,如下所示:
polygons
1
list(c(-122.0809, -122.0813, -122.0812, -122.082, -122.0819, -1...
我尝试使用unlist,但这只是将x / y坐标对与df的相对两端彼此分开:
fixpolygon <- data.frame(unlist(polygons))
输出:
polygons1 -122.0809
polygons2 -122.0813
polygons3 -122.0812
...
polygons210 37.3736
polygons211 37.3764
polygons22 37.3767
我该如何使输出像这样:
c(-122.0809, 37.3736)
c(-122.0813, 37.3764)
...
等等等?
答案 0 :(得分:0)
通过检查
str(polygons)
我们可以看到您想要的东西已经准备好了
polygons$polygons[[1]][[1]]
# V1 V2
# [1,] -122.0809 37.3736
# [2,] -122.0813 37.3764
# [3,] -122.0812 37.3767
# [4,] -122.0820 37.3772
# [5,] -122.0819 37.3792
# [6,] -122.0822 37.3792
# ...
答案 1 :(得分:0)
尝试使用sf
软件包:
library(sf)
st_coordinates(st_as_sf(polygons))
X Y L1 L2
[1,] -122.0809 37.3736 1 1
[2,] -122.0813 37.3764 1 1
[3,] -122.0812 37.3767 1 1
[4,] -122.0820 37.3772 1 1
[5,] -122.0819 37.3792 1 1
[6,] -122.0822 37.3792 1 1