How to calculate the area of polygon overlap in R?

风格不统一 提交于 2019-11-30 06:47:11

问题


Does anyone know how to calculate the area in common between 2 or more polygons in R? I would like to have the output of such a calculation be the coordinates of a new polygon for that area of overlap. Cheers


回答1:


EDIT: these days I would use the 'intersect', 'cover', 'erase', 'union' and related functions in the 'raster' package. They do the hard work to keep the top-level object and attributes.

ORIG: You could use the rgeos package with its gIntersection function. Successive calls between pairs and resulting intersections will get you there. See

library(rgeos)
?gIntersection

You will need to get into the structure of "SpatialPolygons" in the sp package to get the final coordinates. See the vignette("sp").




回答2:


Just thought I would add the solution that I eventually used - the joinPolys function from the PBSmapping package.

Example:

library(PBSmapping)
p1 <- data.frame(PID=rep(1, 4), POS=1:4, X=c(1,1,6,6), Y=c(1,3,3,1))
p2 <- data.frame(PID=rep(2, 5), POS=1:5, X=c(4,4,8,8,6), Y=c(2,4,4,2,1))
p3 <- joinPolys(p1,p2)
x11()
par(mar=c(3,3,1,1))
plot(1,1,ylim=c(0,5),xlim=c(0,9), t="n", xlab="", ylab="")
polygon(p1$X, p1$Y, border=2)
polygon(p2$X, p2$Y)
polygon(p3$X, p3$Y, col=rgb(0,0,1,0.2))



来源:https://stackoverflow.com/questions/9977074/how-to-calculate-the-area-of-polygon-overlap-in-r

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!