Strange behavior when using writeRaster?

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

Strange behavior when using writeRaster?

Vijay Lulla
Consider the following code snippet:

> library(raster)
> r <- raster(nrows=5, ncols=5)
> rf <- writeRaster(r, 'tst123') ## (1)
> d <- raster('tst123.grd')
> d[] <- 0
> df <- writeRaster(d, 'tst123', overwrite=TRUE) # We're overwriting
tst123!! (2)
> df  ## Shows that datasource is tst123.grd with values 0, 0 (min,max)
> rf  ## Still shows that datasource is tst123.grd with values NA, NA (min,
max)!  Error?
> df[] ## Expected
> rf[] ## Unexpected!!  Is this an error?
> rf  ## Should rf reread the data from the file to update its metadata?

Is it possible to keep track of open connections (for e.g., in (1) and (2)
above) and update metadata of files that may have changed?  I am also not
sure why all examples of raster package show examples of assigning value of
writeRaster function when it is intended to be used for side-effects of
writing to a file?  I would not have stumbled upon this if the examples had
simple `writeRaster(d, 'tst123')` instead of the common `df <-
writeRaster(d, 'tst123')` used in the documentation!


        [[alternative HTML version deleted]]

R-sig-Geo mailing list
[hidden email]