Skip to content
Prev 21892 / 29559 Next

Overlaying time designated spatial points from a data frame to match the time of a raster image in a rasterStack

Hi

Is it something like this you want to have?


library(raster)
library(latticeExtra)

f <- system.file("external/test.grd", package="raster")

d <- seq(as.Date("2010-01-01"),as.Date("2014-08-01"),by="month")

rr <- stack(rep(f,length(d)))
names(rr) <- d

rr <- setZ(rr, d, name = 'Month')

rr.mean <- zApply(rr, by = function(x)format(x, '%m'), fun = mean, name = "Month")
names(rr.mean) <- month.abb

### For each date sample 10 points from the rasterbrick
pdat <- NULL
for (i in 1:length(d)){
    cells <- sample(1:ncell(rr[[1]]), 10)
    xy <- xyFromCell(rr, cells)
    tmp <- data.frame(x = xy[,"x"], y = xy[, "y"], Month = format(d[i], '%m'), CellId = cells)
    pdat <- rbind(pdat, tmp)
}

levelplot(rr.mean) + xyplot(y ~ x|Month, data = pdat, pch = 13, col = "black")

Yours sincerely / Med venlig hilsen


Frede Aakmann T?gersen
Specialist, M.Sc., Ph.D.
Plant Performance & Modeling

Technology & Service Solutions
T +45 9730 5135
M +45 2547 6050
frtog at vestas.com
http://www.vestas.com

Company reg. name: Vestas Wind Systems A/S
This e-mail is subject to our e-mail disclaimer statement.
Please refer to www.vestas.com/legal/notice
If you have received this e-mail in error please contact the sender.