Using main memory as cache to raster objects

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Using main memory as cache to raster objects

Paulo Felipe
Hello everyone, I am trying to use main memory in R as cache to rasters
objects, but I am having some problems with overwriting rasters in disk.

To implement the cache, I am limiting the number of rasters that can be
used in the S3 class cacheManager
<https://github.com/ufcg-lsd/SEBAL/blob/sebal-experiment/workspace/R/cacheManager.R>
.

The main features that I am trying to implement is:

   1. put a raster object, already allocated, in the cacheManager
   2. get a raster object from the cacheManager

As we know, in the first feature exist a border case, that is when the
number of raster objects is greater than the cacheManager size. In this
case, I just save in disk one of the rasters objects and put the new raster in
the cacheManager.

This solution appears be reachable, at least to me, but I am stuck in the
save to disk part. To save rasters in disk I tried to use the functions
'writeRaster' and 'writeValues'.

Specifically, my problem is when I already had a version of the same raster
written on disk, this seems to be solvable using the 'overwrite=TRUE'
parameter in the functions 'writeRaster' and 'writeValues', but I got some
errors in each implementation:

   1. writeRaster - 'filenames of source and target should be different' you
   can see this error message in the raster package code
   <https://github.com/cran/raster/blob/2.6-7/R/writeRaster.R>;
   2. writeValues - save the rasters in the disk, but when I read the
   raster from disk, all values came as NA.

Note that I have little experience with rasters and R, if you see anything
stupid or stranger, please alert me.

So, anyone has a suggestion of a better implementation to save the rasters
in disk? Or can see any error in the save in disk implementation?

*OBS: you can reproduce the error that I got just running this code
<https://github.com/ufcg-lsd/SEBAL/blob/sebal-experiment/workspace/R/cacheManager.R#L138>.*

--

*Paulo Felipe*

        [[alternative HTML version deleted]]

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