6.6 Spatial vectorization

raster —> vector: as.point s(), as.polygon()

elev = rast(system.file("raster/elev.tif", package = "spData"))
elev_point = terra::as.points(elev) |> 
  st_as_sf()
plot(elev_point["elev"])

dem = rast(system.file("raster/dem.tif", package = "spDataLarge"))
cl = terra::as.contour(dem) |> 
  st_as_sf()
plot(dem, axes = FALSE)
plot(cl, add = TRUE)

grain = rast(system.file("raster/grain.tif", package = "spData"))
grain_poly = terra::as.polygons(grain) |> 
  st_as_sf()
plot(grain_poly)

grain_poly = terra::as.polygons(grain, dissolve = FALSE) |> 
  st_as_sf()
plot(grain_poly)