1

I'm trying to count how many cells on a fine resolution raster fit inside each cell of a coarser raster. The resolutions and the extents differ. Assume for now the coordinate systems have been reprojected and they match.

require(raster)

# make a fine res raster (and create some NA cells)
set.seed(234)
fine <- raster(xmn=0,xmx=500,ymn=0,ymx=500,res=c(10,10))
fine[] <- sample(c(1:3),size=2500,replace=T)
fine[runif(50*50) >= 0.50] <- NA

# make a coarse res raster
set.seed(345)
coarse <- raster(xmn=-47,xmx=558,ymn=-13,ymx=592,res=c(55,55))
coarse[] <- 1:ncell(coarse)

# plot for visual
plot(coarse)
plot(fine,add=T)

Where coarse cells are not totally covered by the fine res raster, i'm not interested.

# crop the coarse by the fine (using snap="in) 
# to retain coarse cells totally covered by fine 
coarse.red <- crop(coarse, fine, snap="in")

So how can I go about

  1. counting how many fine resolution cells fit in each coarse
    resolution cell (including NA cells).
  2. counting how many fine resolution cells per value are in each coarser cell.

Turning the fine res raster into points and doing various nice little tricks as answered by jbaums in this answer (using rasterToPoints and tab) is great, but I cannot use this technique for my final data, the amount of points generated will be inhibitive due to the very large size of the rasters.

Zonal isn't an option due to extent/resolution issues

Community
  • 1
  • 1
Sam
  • 1,400
  • 13
  • 29

0 Answers0