1

I'm trying to mosaic two raster images using R. I used this script:

setwd("D:\\Modis EVI\\")
raster_dir <-    "D:\\Modis EVI\\"
r1 <- brick(paste(raster_dir,"evi8_stack.tif", sep=""))
r2 <- brick(paste(raster_dir,"evi9_stack.tif", sep=""))
m1 <- mosaic(r1, r2, fun=mean)

The script worked fine but the result mosaic has this black line, see picture

enter image description here

Any advice please on why I have this line, and how could it be removed?

  • You either have a real gap between your data or your rasters have a background value that is being assigned during the mosaic process. If you figure out what the background value is you can explicitly assign it a NA value. – Jeffrey Evans May 13 '16 at 13:51
  • what is the solution if there is a real gap? – nour May 13 '16 at 15:20
  • You could fix it with a conditional focal function or interpolate the missing data. – Jeffrey Evans May 13 '16 at 15:37
1

changing the function in the script to MAX, has solved the problem : m1 <- mosaic(r1, r2, fun=max)

1

I experienced a similar phenomenon mosaicing 203 tiles (7x29) into a single raster. The "line" was a row of NAs between tile rows 5 and 6. I hypothesize this was a memory allocation issue. There was no gap in the tiles (if I mosaiced two of the offending tiles from rows 5 and 6, no NA row would occur), nor was there a background value being assigned. Nor did changing the function help (i.e. fun=max).

After much debugging, my solution was to do two rounds of mosaicing, clearing memory in the process. Thus, I mosaiced 203 tiles to 3 three tiles, then those three tiles to one. No NA rows occurred in the final image. Clearly buggy behavior, thus my hypothesis that it was a memory issue - wish it were definitive though. In any case, my solution worked.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.