I have the following error when trying to use the writeraster function in R:

Error in (function (classes, fdef, mtable) : unable to find an inherited method for function ‘writeRaster’ for signature ‘"SpatialGridDataFrame", "character"’

This is the code:

x <- readGDAL("LC81360442014322LGN00_B5.TIF")
z <- reflconv(x,2.0000E-05,-0.100000)
writeRaster(z,filename="test.tif",format="GTiff",overwrite=TRUE) #ERROR LINE

I want to store variable z in a raster file. Can any one help me out from this error?

  • It is unclear where you get this error. Please edit your question to make it clearer.
    – user32309
    Sep 28, 2015 at 7:20
  • when I try to convert the landsat band5 image to reflectance i got this error
    – user28536
    Sep 28, 2015 at 7:24
  • Do you have to use readGDAL? You could try raster("LC81360442014322LGN00_B5.TIF")?
    – Iris
    Sep 28, 2015 at 8:22
  • And you also need to load library(landsat8)
    – Iris
    Sep 28, 2015 at 8:25
  • landsat8 is also there
    – user28536
    Sep 28, 2015 at 8:28

2 Answers 2


First coerce z to a RasterLayer:

z <- raster(z)
writeRaster(z, filename="test.tif", overwrite=TRUE)

If you import your file with gdal, it is best to export it with gdal, too:

# str(x) #what is the Formal class of your raster
# > Formal class 'SpatialGridDataFrame'
writeGDAL(z, fname="test_gdal.tif", drivername = "GTiff")

Your Answer

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

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