I would like to display the results in a raster times series object (rts) using levelplot function in rasterVis.
Here is a short code frome rts package:
library(raster)
library(rasterVis)
library(rts)
path <- system.file("external", package="rts")
lst <- list.files(path=path,pattern='.asc$',full.names=TRUE)
r <- stack(lst)
d <- c("2000-02-01","2000-03-01","2000-04-01","2000-05-01") # corresponding dates to 4 rasters
d <- as.Date(d)
# creating a RasterStackTS object:
rt <- rts(r,d)
To coerce from .rts to raster I used:
r=rt@raster
proj=CRS("+proj=longlat +datum=NAD27 +no_defs +ellps=clrk66 +nadgrids=@conus,@alaska,@ntv2_0.gsb,@ntv1_can.dat")
proj4string(r) <- proj
wgs84.p4s <- CRS("+proj=longlat +datum=NAD83 +ellps=GRS80 +no_defs")
reprojecting r
from UTM coordinates to latlong coordinates
rx <- projectRaster(from=r, crs=wgs84.p4s@projargs, method="ngb")
writeRaster(rt, file="myfile100.tif", format="GTiff", overwrite=TRUE)
ras = raster("myfile100.tif")
How can I read all 4 layers in myfile100.tif
?
ras = raster("myfile100.tif")
reads only layer 1
proj4string(ras) <- proj
plot(ras)
levelplot(ras)
I get this error:
Error in projectExtent(from, projto) : cannot do this transformation
In addition: Warning message:
In rgdal::rawTransform(projfrom, projto, nrow(xy), xy[, 1], xy[, :
146 projected point(s) not finite
How can I get around this? Maybe there is even a shorter and reasonable way to do this. Thanks for your suggestions.