terra icon indicating copy to clipboard operation
terra copied to clipboard

Does rasterize(cover=TRUE) fail silently when ncell too big?

Open sebdunnett opened this issue 2 years ago • 2 comments

I am attempting to rasterize polygons to a ~1km global grid using cover=TRUE to get a measure of uncertainty for rasterising the polygons (some input data are small and detailed, others not - but I am using touches=TRUE so both transfer to the resulting raster).

I think I was being naive and optimistic, but I thought that terra would be able to do this at ~1km resolution, just really slowly. It works at ~10km resolution with the code below, but seems to silently fail at ~1km. Is this deliberate as a result of the number of cells being too big?

library(terra)
#1.7.39

r = rast(res=1/12)
v = vect(spatSample(ext(r),size=1000,lonlat=FALSE))
v = crop(voronoi(v),rast())
v = sample(v,size=100)

rr = rasterize(v,r,cover=TRUE)
rr

r = rast(res=1/120)
rr = rasterize(v,r,cover=TRUE)
rr

sebdunnett avatar Sep 18 '23 12:09 sebdunnett

Thanks. That is not intentional.

rhijmans avatar Sep 21 '23 02:09 rhijmans

( still valid on 1.7-71 )

right now I'm :

  1. rasterizing the polygon's variable at a finer resolution
  2. extracting a matrix containing the centers of the cells
  3. rasterizing them at a coarser resolution counting with fun = length

Are there any other viable alternatives as workaround?

spono avatar Feb 02 '24 17:02 spono