i'm working with landsat data doing some topographic corrections using the method proposed by Hantson & Chuvieco (2010) which involves a cover separation method based on a certain NDVI value to tell between vegetated and non-vegetated areas.
So, I go from having one multiband raster object to two, which are processed sepparately and subsequently combined to form the original, topographically corrected, scene.
The problem is that I have some NA values in the scene, so if I don't get rid of them I get a blank image as a result. I use the sum
function with the na.rm
option defined as TRUE to tackle this problem, but the result is a one-band raster object instead of a stack or rasterbrick object.
This is my code:
#topographic correction
VEGB1TC<- topocorr(VEGB1,slopeG,aspectG,sunelev,sunazimuth,method="ccorrection",na.value=NA)
VEGB2TC<- topocorr(VEGB2,slopeG,aspectG,sunelev,sunazimuth,method="ccorrection",na.value=NA)
....
SDB1TC<- topocorr(SDB1,slopeG,aspectG,sunelev,sunazimuth,method="ccorrection",na.value=NA)
SDB2TC<- topocorr(SDB2,slopeG,aspectG,sunelev,sunazimuth,method="ccorrection",na.value=NA)
...
#rasterize corrected band and stack them
VB1<-raster(VEGB1TC)
VB2<-raster(VEGB2TC)
....
ADEVEG<-stack(VB1, VB2,...)
SB1<-raster(SDB1TC)
SB2<-raster(SDB2TC)
....
ADESD<-stack(SB1, SB2,...)
#-----------combine images-------
ADE<-sum(stack(ADEVEG,ADESD),na.rm=T)
Is there a function that can add multiband rasters with a na.rm
tag? I've found the do.call
function but it seems to me that it sums several rasters into a single-band object.
Thanks for your help.
ps: Hantson, S. Chuvieco, E. 2010. Evaluation of different topographic correction methods for Landsat imagery. International Journal of Applied Earth Observations and Geoinformation 13(2011):691-700p.
ADE<-stack(sum(ADEVEG,na.rm=T),sum(ADESD,na.rm=T))
– rar