I have this sampled code that I tried on RStudio these last days :
library ('terra')
binar <- rast("C:/Users/BIC_/Desktop/21_binarisation_SWIR.tif")
poly_rast <- as.polygons(binar , values = TRUE,extent=FALSE)
I want to convert my raster "binar" into a vector; I have tried with the function "rasterToPolygons" from the package "raster" but it was too long.
After 'vectorizing' my raster I wanted to export it as a shapefile, with this line :
writeVector(poly_rast, filename ="C:/Users/BIC_/Desktop/21_contour_im",filetype = "ESRI Shapefile")
But every time I am doing this it's leading me to a fatal error and R crashes. I do not know how to do and what I've done wrong.
Also I have notice that my poly_rast file has a 0x0 dimension, weird...
> binar
class : SpatRaster
dimensions : 10980, 10980, 1 (nrow, ncol, nlyr)
resolution : 10, 10 (x, y)
extent : 3e+05, 409800, 7590220, 7700020 (xmin, xmax, ymin, ymax)
coord. ref. : +proj=utm +zone=38 +south +datum=WGS84 +units=m +no_defs
source : 0121_binarisation_SWIR_MOROMBE_T38KLB.tif
name : 0121_binarisation_SWIR_MOROMBE_T38KLB
min value : 0
max value : 1
> poly_rast
class : SpatVector
geometry : none
dimensions : 0, 0 (geometries, attributes)
extent : -180, 180, -90, 90 (xmin, xmax, ymin, ymax)
coord. ref. : +proj=utm +zone=38 +south +datum=WGS84 +units=m +no_defs
When plotting "poly_rast" to see what's returned this message appears and my plot window is blank :
Error in g[[i]] : subscript out of bounds
Thanks for your help !!