Diann,

It looks like you aren't passing a raster. Try
# ...
risk_mn<- apply(risk,c(1,2),mean)
r <- raster(risk_mn)
writeRaster(r, 'risk_mn.tif', format="GTiff", overwrite=TRUE)

Note that if your matrix contains characters, you'll have to convert to
integers before passing it to raster().

Etienne

2012/3/16 Diann Prosser <[email protected]>

> Hi all,
>
> I'm running the latest version of R (info below) with the raster and rgdal
> libraries loaded.
> I get the following error when trying to write to a raster (one I have not
> seen before with previous runs of this code):
>
> > rRisk_mn <- writeRaster(risk_mn, 'risk_mn.tif', format=raster,
> > overwrite=TRUE)  # for ArcGIS
> *Error in function (classes, fdef, mtable)  :
>  unable to find an inherited method for function "writeRaster", for
> signature "matrix", "character"*
>
> More code is supplied below in case it's helpful. Thanks for any help in
> fixing this error.
>
> Kind regards,
> Diann
> ________________________________________________________________
> bits from sessionInfo():
> R version 2.14.2 (2012-02-29)
> Platform: x86_64-pc-mingw32/x64 (64-bit)
>
> attached base packages:
> [1] stats     graphics  grDevices utils     datasets  methods   base
>
> other attached packages:
> [1] rgdal_0.7-8      raster_1.9-70    sp_0.9-97        mc2d_0.1-12
> [5] mvtnorm_0.9-9992
>
> loaded via a namespace (and not attached):
> [1] grid_2.14.2    lattice_0.20-0 tools_2.14.2
> _________________________________________________________________
>
> #building final array (4 simulations on 4848x4053 cells)
> risk <- array(risk, dim=c(ny,nx,nsimu))
>
> #mean for each location
> risk_mn<- apply(risk,c(1,2),mean)
>
> setwd("C:/Trisk/Output")
> rRisk_mn <- writeRaster(risk_mn, 'risk_mn.tif'see, format=raster,
> overwrite=TRUE)  # for ArcGIS
>
> --
> View this message in context:
> http://r-sig-geo.2731867.n2.nabble.com/Error-in-writeRaster-tp7379982p7379982.html
> Sent from the R-sig-geo mailing list archive at Nabble.com.
>
> _______________________________________________
> R-sig-Geo mailing list
> [email protected]
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[email protected]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Reply via email to