[R-sig-Geo] Strange behavior when using writeRaster?
Vijay Lulla
vij@ylull@ @ending from gm@il@com
Wed Jul 25 23:37:38 CEST 2018
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!
Thanks,
Vijay.
[[alternative HTML version deleted]]
More information about the R-sig-Geo
mailing list