[R-sig-Geo] Replacing values in a RasterBrick

BEUTEL Terry S Terry.Beutel at daf.qld.gov.au
Thu Sep 7 00:22:31 CEST 2017


Hi.

I'm working with the Raster package. I have a RasterBrick of 374 monthly rainfall rasters called Rain2.


> Rain2
class       : RasterBrick
dimensions  : 374, 315, 117810, 374  (nrow, ncol, ncell, nlayers)
resolution  : 0.05, 0.05  (x, y)
extent      : 137.925, 153.675, -29.275, -10.575  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +ellps=GRS80 +no_defs
data source : K:\RainStuff\RainRaster.grd
names       :    X198601,    X198602,    X198603,    X198604 ...
min values  :       0.00,       0.00,       0.00,       0.00 ...
max values  :  962.01929,  534.42188,  929.24780,  790.83087 ...



I want to replace the 374 monthly rainfall pixel values at a particular location (defined by the intersection of a single row and a single column) with a different series of 374 values. But when I try the reassignment, I run into memory issues....



> Rain2[100,100]<-c(1:374)

Error: cannot allocate vector of size 336.2 Mb



I've also tried using setValues to reassign the values, as per the "Writing functions with the 'raster' package" vignette, but without success e.g. ...

> f2<-

+ function(x,row,col,a){

+ x[row,col]<-setValues(x[row,col],a)

+ return(x)}

>

> a<-c(1:374)

> f2(Rain2,100,101,a)



Error in (function (classes, fdef, mtable)  :

  unable to find an inherited method for function 'setValues' for signature '"matrix"'





I don't work much with the Raster package and I'm sure I'm making an elementary error here, but I'd appreciate any advice on the best way replace these values efficiently.

Many thanks

Terry

------------------------------
The information in this email together with any attachments is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. There is no waiver of any confidentiality/privilege by your inadvertent receipt of this material. 
Any form of review, disclosure, modification, distribution and/or publication of this email message is prohibited, unless as a necessary part of Departmental business.
If you have received this message in error, you are asked to inform the sender as quickly as possible and delete this message and any copies of this message from your computer and/or your computer system network.
------------------------------

	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list