rrasterlandsat

R: Landsat8 DN to reflectance conversion


For an irrigation inventory using the NDVI of satellite images, I need to convert Landsat 8 images from DN to reflectance rates. In R, there are 2 packages (Landsat and Landsat8) that have functions to convert, however, the output of these functions is in a large 'numeric' class.

The input is different: SpatialGridDataframe (see function description). I've tried both methods, but it doesn't work to convert them to a raster or SpatialGridDataframe. The 'numeric' class is not suitable for further calculations (NDVI, image corrections or plotting. There a way to convert this? Could you help me out?

Thanks!

#BAND 4
R4 <- list()
R4 <- lapply(j, FUN = function(x) {raster(paste0('LC81700merged2014',x,'LGN00_B4.tif'))})
names(R4) <- paste0("R4",j) 
Jab=readShapeSpatial('E:/Maps/GIS Data/Jabi IrrigationSchemes/Jabi_Irrigation_Schemes_UTM.shp')
CR <- lapply(R4, FUN=function(x) {crop(x, extent(Jab), snap="out")})
y <- stack( CR) # stack as RasterStack
ty <- as(y, "SpatialGridDataFrame")

#landsat8- package:
ytest <- reflconv(ty$R4016,2.0E-5,-0.1)
class(ytest) #numeric class
ytest[ytest==-0.1] <- NA 
tsa <- as.raster(ytest, max=1)
class(tsa) #raster Object
y.tsa <- rasterize(tsa,background=NA,mask=FALSE, update=FALSE) #not working

#alternative landsat-package
jan16 <-radiocorr(ty$R4016,Grescale=L.var[4,4],Brescale=L.var[4,5],sunelev=SunEvel[1,2],edist=ESdist('2014-01-16'),
                Esun=L.var[4,6],method= "apparentreflectance")
class(jan16) #numeric class again..

Solution

  • Either process the whole RasterStack at once or if you want to process one layer move the "SpatialGridDataFrame" coercion to a different place.

    ...
    y <- stack( CR) # stack as RasterStack
    ty <- as(y, "SpatialGridDataFrame")
    
    #landsat8- package:
    ytest <- reflconv(ty, 2.0E-5, -0.1)
    class(ytest) # "SpatialGridDataFrame"
    

    or

    ...
    y <- stack( CR) # stack as RasterStack
    
    #landsat8- package:
    ty <- as(y$R4016, "SpatialGridDataFrame")
    ytest <- reflconv(ty, 2.0E-5, -0.1)
    class(ytest) # "SpatialGridDataFrame"
    

    reflconv needs a SpatialGridDataFrame, while getting one layer of a SpatialGridDataFrame gives a vector.