rrastergaussiangaussianblur

R: no applicable method for 'gaussiansmooth' applied to an object of class "c('matrix', 'array', 'double', 'numeric')" or "c('RasterLayer', 'Raster')


I am trying to use the function gaussiansmooth but I am receiving an error: Error in UseMethod("gaussiansmooth") : no applicable method for 'gaussiansmooth' applied to an object of class "c('RasterLayer', 'Raster', 'BasicRaster')".

From the documentation it states that the input should be a grid object in memory. This is one of my many tests:

library(raster)
library(gridkernel)
library(gridprocess)

pan = raster("path/pan15.tif")

smoothed = gaussiansmooth(m,
                          sd = 0.5 * 920) # the multiplication is because I want my pixel size to become 460m.

In the documentation's example they used a matrix, but the same error occurs: Error in UseMethod("gaussiansmooth") : no applicable method for 'gaussiansmooth' applied to an object of class "c('matrix', 'array', 'double', 'numeric')". Here is the same code but with a matrix instead of a satellite image.

pan = raster("path/pan15.tif")

m = as.matrix(pan)

smoothed = gaussiansmooth(m,
                          sd = 0.5 * 920)

The goal here is to change the pixel size of my image from 15m to 460m by applying a Gaussian filter. This is different from a 'simple' resampling method (e.g., nearest neighbor) because I am trying to model a point spread function.

From here you can download my image.


Solution

  • The author of the package replied to my question on Github and it turned out it was very simple. I just had to convert my raster into a grid object.

    library(raster)
    library(gridkernel)
    library(gridprocess)
    
    pan = raster("path/pan15.tif")
    g = as.grid(pan)