从多边形r提取坐标

爱喵

我试图从最初包含在SpatialPolygons对象中的众多多边形中提取坐标:

 Sr1 = Polygon(cbind(c(2,4,4,1,2),c(2,3,5,4,2)))
 Sr2 = Polygon(cbind(c(5,4,2,5),c(2,3,2,2)))
 Srs1 = Polygons(list(Sr1), "s1")
 Srs2 = Polygons(list(Sr2), "s2")
 SpP = SpatialPolygons(list(Srs1,Srs2), 1:2)

我正在尝试从SpP对象中提取Sr1和Sr2的坐标。我在堆栈交换的其他地方看到了以下代码:

Coords<-SpP@polygons[[2]]@Polygons[[1]]@coords

我无法理解方括号中索引的不匹配,尽管如此,它仍然有效。但是输出与我在Sr1或Sr2中指定的坐标不匹配。我已经尝试了索引的所有组合,但无法获得所需的答案!

hrbrmstr

确定吗?它们看起来相同(由于发表评论太长,因此仅作为“答案”发布):

library(sp)

Sr1 <- Polygon(cbind(c(2, 4, 4, 1, 2), c(2, 3, 5, 4, 2)))
Sr2 <- Polygon(cbind(c(5, 4, 2, 5), c(2, 3, 2, 2)))
Srs1 <- Polygons(list(Sr1), "s1")
Srs2 <- Polygons(list(Sr2), "s2")
SpP <- SpatialPolygons(list(Srs1, Srs2), 1:2)

SpP@polygons[[1]]@Polygons[[1]]@coords

##      [,1] [,2]
## [1,]    2    2
## [2,]    1    4
## [3,]    4    5
## [4,]    4    3
## [5,]    2    2

Sr1@coords
##      [,1] [,2]
## [1,]    2    2
## [2,]    4    3
## [3,]    4    5
## [4,]    1    4
## [5,]    2    2


SpP@polygons[[2]]@Polygons[[1]]@coords
##      [,1] [,2]
## [1,]    5    2
## [2,]    2    2
## [3,]    4    3
## [4,]    5    2

Sr2@coords
##      [,1] [,2]
## [1,]    5    2
## [2,]    4    3
## [3,]    2    2
## [4,]    5    2

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章