[英]extracting coordinates from polygon 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中指定的坐標不匹配。 我已經嘗試了索引的所有組合,但無法獲得所需的答案!
你確定嗎? 它們看起來相同(由於發表評論太長,因此僅作為“答案”發布):
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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.