Trying to get to the bottom of why, when I read in a raster of NDVI, the @data@values slot does not contain the actual values until I set them manually. For example:
NDVI <- raster("./filename.tif", crs="+proj=longlat +datum=WGS84") NDVI@data@values ## returns: logical(0)
This did not happen with other rasters I had loaded in by the same method, so I'm confused. I wish I could be more specific but I do not remember doing anything differently before. It's easy enough to get the values manually, using:
NDVI1@data@values <- getValues(NDVI19east)
But it's still a pain to have to do so for every file. So, two-part question:
Why did this happen in the first place? I understand that it could have something to do with how the raster file is being stored (i.e. whether it's in memory or not) but I can't really understand how that changes the methods I should use for accessing the data...
Is there a way to automate this process (perhaps using a method similar to lapply) for reading files as RasterLayers and accessing values for those files? My current project involves reading 6-10 files at a time for NDVI, Rainfall and other environmental variables, in order to combine them and perform some weighted overlays. It would be helpful to automate the process of importing the data.