R语言terra包,fill,删除多边形中的孔
# Thu Dec 24 08:26:33 2020 -
# 字符编码:UTF-8
# R 版本:R x64 4.0.3 for window 10
# cgh163email@163.com
# 个人笔记不负责任
# —— 拎了个梨🍐
.rs.restartR()
require(terra)
# fill,删除多边形中的孔
rm(list=ls());gc()
x <- rbind(c(-10,0), c(140,60), c(160,0), c(140,-55))
hole <- rbind(c(80,0), c(105,13), c(120,2), c(105,-13))
z <- rbind(cbind(object=1, part=1, x, hole=0),
cbind(object=1, part=1, hole, hole=1))
colnames(z)[3:4] <- c('x', 'y') # 命名
z <- data.frame(z)
p <- vect(z, "polygons") # 数据框创建spv对象
p
f <- fill(p)
plot(f, col="light blue", lwd=8, border="blue")
lines(p, lwd=2, col="red")
dev.copy(png,'ex1.jpg');dev.off()
# Thu Dec 24 08:28:38 2020 --