Supondo que o polígono de interesse seja a envoltória convexa dos pontos.
library(sp)
library(rgdal)
library(raster)
pts_shp <- shapefile("X/x.shp")
plot(pts_shp)
p <- coordinates(pts_shp)
ch <- chull(p)
coords <- p[c(ch, ch[1]), ] # fechando o polígono
plot(p, pch = 19)
lines(coords, col = "red", lwd = 3)
sp_pol <- SpatialPolygons(
list(Polygons(
list(Polygon(coords)),
ID = 1
))
)
plot(sp_pol, axes = TRUE)
points(pts_shp, pch = 20, cex = 0.2)
sp_pol_df <- SpatialPolygonsDataFrame(
sp_pol,
data = data.frame(ID = 1)
)
#shapefile(sp_pol_df, "pol-from-pts.shp", overwrite = TRUE)
#x <- shapefile("pol-from-pts.shp")
#plot(x, axes = TRUE)