1

I have 9 layer stacked DEM raster image in .tif format. I would like to smooth the image using focal() function in raster package in R.

img <- brick("/stack.tif")
img <- focal(img, w=matrix(1,4,4), fun=modal)

Getting this error:

Error in (function (classes, fdef, mtable)  : 
  unable to find an inherited method for function ‘focal’ for signature ‘"RasterBrick"’
2
  • You can't run focal over anything with more than one band. You have 9 bands. Do you want to run that operation on each band separately? Loop over the bands?
    – Spacedman
    Commented Nov 15, 2019 at 7:58
  • Do you want to reduce the multiple layers to one getting the mode for each pixel from the "above" or do you want to have a focal image for every single layer?
    – loki
    Commented Nov 22, 2019 at 7:10

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.