p <- vect(system.file("ex/lux.shp", package="terra"))
h <- hull(p)
plot(p)
lines(h, col="orange")
hh <- hull(p, "convex", by="NAME_1")
lines(hh, col="purple")
pts <- centroids(p)
plot(pts, ext=ext(p)+0.1)
lines(hull(pts, type="convex"), col="darkgreen")
lines(hull(pts, type="rect"), col="blue")
lines(hull(pts, type="circle"), col="red")
Run the code above in your browser using DataLab