我通过使用unionSpatialPolygons
融合多边形创建了一个shapefile,如何找到已创建的新多边形的坐标?
答案 0 :(得分: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)