【问题标题】:Centroids of a shape file形状文件的质心
【发布时间】:2013-12-02 11:31:04
【问题描述】:

我通过使用unionSpatialPolygons 融合多边形创建了一个shapefile,我如何找出已创建的新多边形的坐标?

【问题讨论】:

  • 我记得 spatial.polygons 类的对象有一个 coordinates 方法。你试过coordinates(yourObject)吗?
  • 你能提供class(yourObject)的结果吗?
  • coordinates(my.object) 确实返回了每个多边形的质心。非常感谢。
  • Ummm....你真的是指质心,还是只是顶点坐标?您似乎在这里混淆了这些术语。

标签: r shapefile


【解决方案1】:

这里有两个选项,具体取决于您要计算的质心类型。我从一些维基百科页面中获取了这些算法。

# polyx and polyy are the x and y coordinates of the polygon vertices 
# notice had to negate these calcs in final line...
 require(pracma,quietly=TRUE)

pchit <- polyarea(polyx,polyy)
    centx <- centy <- 0
    for (kk in 1:(length(polyx)-1) ) {
        centx <- centx + (polyx[kk]+polyx[kk+1]) * (polyx[kk]*polyy[kk+1]-polyx[kk+1]*polyy[kk])
        centy <- centy + (polyy[kk]+polyy[kk+1]) * (polyx[kk]*polyy[kk+1]-polyx[kk+1]*polyy[kk])
    }
    centx <- -1/pchit/6 * centx
    centy <- -1/pchit/6 * centy
    #  These next two are for vertex centroid, rather than polygon centroid
    # centx <- mean(polyx)
    # centy <- mean(polyy)

【讨论】:

    猜你喜欢
    • 2016-08-08
    • 2012-09-01
    • 2021-01-30
    • 2013-11-22
    • 2022-07-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多