【问题标题】:extracting coordinates from polygon r从多边形 r 中提取坐标
【发布时间】:2015-08-22 09:38:20
【问题描述】:

我正在尝试从最初包含在 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 中指定的坐标不匹配。我已经尝试了所有索引组合,但无法得到我正在寻找的答案!

【问题讨论】:

    标签: r coordinates s4 slots sp


    【解决方案1】:

    确定吗?它们看起来一样(仅作为“答案”发布,因为评论太长了):

    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
    

    【讨论】:

    • 检查每个坐标集中的第 3 行和第 2 行,它们不匹配。但我刚刚意识到第 2 行和第 3 行的顺序已经交换了。这有关系吗?为什么要这样做?
    • 具有此方向的环被解释为孔多边形。由于它们不能是没有周围多边形的孔,因此将环方向反转以反映非孔多边形。
    猜你喜欢
    • 1970-01-01
    • 2013-12-26
    • 2020-09-02
    • 1970-01-01
    • 1970-01-01
    • 2015-09-03
    • 2014-08-02
    • 1970-01-01
    相关资源
    最近更新 更多