The solution was proposed off-list by Robert Hijmans by using init(), so
for the record :

```
r <- raster(nrow = 1e5, ncol = 1e5)
r <- init(r, function(x) 1, filename = "big_raster")
```

Allows to (1) fill a large raster with values and (2) write it to disk.

Etienne

2012/9/24 Jean-Daniel Sylvain <[email protected]>

> Hi Etienne,
>
> What's your purpose?
>
> First, I will suppose that you try to estimate a key variable "k" with "n"
> covariables "c".
>
> as
>
> k = c1+c2+c3+cn
>
> To do this, you could treat your raster as a vectorial grid using a
> primary key and use the package bigmatrix. Bigmemory package give you the
> opportunity to manage big dataset by writing on the hard disk (
> http://www.bigmemory.org/). With this option you could model your key
> variable and keeping the spatial coordinate with the grid id.
>
> If you need to do spatial analysis, I will suggest you to convert your
> raster in spatial point data frame and convert it back to raster.
>
> Hope it will help you.
>
> JD
>
>
>
>
>
> 2012/9/24 Etienne B. Racine <[email protected]>
>
>> For test purpose, I want to create a large raster within R and write it to
>> disk. However, I find myself in the situation where I can't write to my
>> raster since it is too big to manage in memory while not being able to
>> write to disk since the raster has no values.
>>
>> Here are the different strategies I've taken, but all failed :
>> ```
>> r <- raster(matrix(1, nrow = 1e5, ncol = 1e5))
>> r <- raster(nrow = 1e5, ncol = 1e5)
>> r <- setValues(r, 1)
>> r <- calc(r, function(x) 1, filename = "big_raster")
>> values(r) <- 1
>> writeRaster(r, filename = "big_raster")
>> ```
>>
>> Any solution ?
>>
>> Etienne
>>
>>         [[alternative HTML version deleted]]
>>
>> _______________________________________________
>> R-sig-Geo mailing list
>> [email protected]
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>
>
>
>
> --
> Jean-Daniel Sylvain
> 215, rue Alleyn
> Québec, Québec
> G1K 4T7
> Tél:418-523-7253
> Courriel:[email protected]
>
>
>
>
>
>

        [[alternative HTML version deleted]]

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

Reply via email to