从sf包r中的长纬度列表创建multipolygon

时间:2018-08-25 03:50:38

标签: r sf

我有两个包含如下较长经纬度的列表

> typeof(sec1)
[1] "list"
> sec1
         lon      lat
1   10.77996 76.51189
2   10.78049 76.51223
3   10.78101 76.51257
4   10.78154 76.51290
5   10.78206 76.51324
6   10.78259 76.51358
7   10.78271 76.51357

> typeof(sec2)
[1] "list"
> sec2
         lon      lat
1   10.77224 76.65794
2   10.77090 76.65812
3   10.76956 76.65830
4   10.76821 76.65848
5   10.76687 76.65866
6   10.76552 76.65884
7   10.76559 76.65886
8   10.76566 76.65889
9   10.76574 76.65892

我想使用R中的sf包创建多面几何。

根据文档,我需要将数字矩阵列表传递给st_multipolygon函数...但是似乎没有crs转换选项

我在下面的尝试

> a<-st_multipolygon(list(sec1,sec2))
Error in vapply(y, ncol, 0L) : values must be length 1,
 but FUN(X[[1]]) result is length 0

失败..

我知道我在犯一些基本的错误。.有人可以帮忙吗

谢谢

1 个答案:

答案 0 :(得分:0)

这几乎正是我想要做的,所以我拿了这些清单,并做了一些工作。生成的多边形并不是最好的(必须在原始问题中遗漏一些点),但是我成功采用了这种策略:

sec1 <- list( rbind(c(10.77996, 76.51189), c(10.78049,76.51223), c(10.78101,76.51257), c(10.78154,76.51290), c(10.78206,76.51324), c(10.78259,76.51358), c(10.78271,76.51357), c(10.77996, 76.51189)) )

sec2 <- list( rbind(c(10.77224,76.65794), c(10.77090,76.65812), c(10.76956,76.65830), c(10.76821,76.65848), c(10.76687,76.65866), c(10.76552,76.65884), c(10.76559,76.65886), c(10.76566,76.65889), c(10.76574,76.65892), c(10.77224,76.65794)) )

a <- st_multipolygon(list(sec1,sec2))

plot(a)

  

dput(sec1)

list(structure(c(10.77996, 10.78049, 10.78101, 10.78154, 10.78206, 10.78259, 10.78271, 10.77996, 76.51189, 76.51223, 76.51257, 76.5129, 76.51324, 76.51358, 76.51357, 76.51189), .Dim = c(8L, 2L)))

  

dput(sec2)

list(structure(c(10.77224, 10.7709, 10.76956, 10.76821, 10.76687, 10.76552, 10.76559, 10.76566, 10.76574, 10.77224, 76.65794, 76.65812, 76.6583, 76.65848, 76.65866, 76.65884, 76.65886, 76.65889, 76.65892, 76.65794), .Dim = c(10L, 2L)))