The idea is to convert some raster files (39 fire occurrences) into vector points (.shp), allowing the use of the extract() function in the terra package to relate the occurrence points to another raster file, e.g., land use, temperature, solar radiation. Is there a better way to do this? The only strategy I thought of was to convert it into a point file.
The size of a single raster file is about 85 MB, and after using the as.points() function, the vector file is about 5.8 GB (318 GB for all 39 files). The rbind does't work, memory crash.
Here's what I have so far:
library(terra)
arquivos <- list.files('Matriciais', pattern = '*.tif$', full.names = T)
matriciais <- sapply(arquivos, rast)
dir.create('Vetoriais', showWarnings = F)
for (i in seq_along(matriciais)) {
pontos <- as.points(matriciais[[i]])
nome <- basename(arquivos[[i]])
ano <- sub('.*_(\\d{4})\\.tif$', '\\1', nome)
pontos$ID <- seq_len(nrow(pontos))
pontos$Ano <- as.numeric(ano)
pontos$Mes <- values(matriciais[[i]])
writeVector(pontos, file.path('Vetoriais', paste0('Pontos_Focos_', ano, '.shp')), overwrite = T)
print(paste0('Processo do ano ', ano, ' concluído'))
}
vetores <- do.call(rbind, lapply(list.files('Vetoriais', pattern = '*.shp$', full.names = T), vect))
na.rm = TRUEoption is set. Do the raster have only two values like yes/no for occurence? If that's the case, filter out only those cells which are relevant to vectorization.