我已经通过使用unionSpatialPolygons
融合了多边形来创建了shapefile,如何找到已经创建的新多边形的坐标?
最佳答案
这是两个选项,具体取决于您要计算的质心类型。我从一些维基百科页面上获取了这些算法。
# 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)
关于r - 形状文件的质心,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20327244/