I'm getting an error with a line of code that I've run successfully in the past. My goal is to extract landsat pixel values from training data polygon shapefile for classification. Here's my code up until the error:
Load, stack, and brick Landsat rasters
all_landsat_bands<-list.files("E:/NorthBahamas_GDB/WorkingFiles/POST_DORIAN/Train/L2SP_POST", pattern =".tif$", full.names=TRUE) landsat_stack <-stack(all_landsat_bands) landsat_brick <- brick(landsat_stack)
'stack': Links several raster objects written to different files, 'brick': Creates one multi-layer file
Assign column headers to Landsat brick
names(landsat_brick) vecnames=c("b2","b3","b4","b5","b6","b7", "NDVI") names(landsat_brick)=vecnames
Load training data
Check CRS and projection of landsat and training data
Set the CRS of training data to match the landsat brick
ALLCAT_prj <- spTransform(All_CAT, crs(landsat_brick))
Extract the landsat pixel values from training data
ext2<-extract(landsat_brick, ALLCAT_prj, df = TRUE)
The error I'm getting here with the 'extract' function is Error in res[i] <- readBin(x@file@con, what = dtype, n = 1, size = dsize, : replacement has length zero
I obviously still have a lot to learn with spatial analysis in R but was unable to find a solution through troubleshooting.
Do you have any ideas on what could be causing this error?
This line of code worked just yesterday. The only thing that changed was the input rasters.