Search code examples
rextractterra

terra extract hangs, what is my best diagnosis?


I want to extract a spatraster from a spatvector,

> rand_samp
class       : SpatRaster 
dimensions  : 4683, 1869, 1  (nrow, ncol, nlyr)
resolution  : 40, 40  (x, y)
extent      : 54689.98, 129450, 5893846, 6081166  (xmin, xmax, ymin, ymax)
coord. ref. : WGS 84 / UTM zone 56S (EPSG:32756) 
source      : randomly_sampled_from_cabramurra.tif 
name        :      layer 
min value   : 0.00010000 
max value   : 0.08172659

> horse_zone
 class       : SpatVector 
 geometry    : polygons 
 dimensions  : 5, 9  (geometries, attributes)
 extent      : 54689.98, 129436.8, 5893846, 6081175  (xmin, xmax, ymin, ymax)
 source      : horse_zone.gpkg
 coord. ref. : WGS 84 / UTM zone 56S (EPSG:32756) 

this code works:

terra::extract(test, horse_zone)

this code:

terra::extract(test, horse_zone, exact=T, na.rm=T)

hangs for 24 hours so far.

What I wonder is are my data too big for my pc (16gb ram), or how do I find out what is going on? Perhaps extract has a progress bar option I can see or some indication it will finish.

If my raster and vector are too big, is there a way to chop this problem up?

I don't have a reproducible example due to data sharing rules for this question, I am afraid, but here is an example that does work, which makes me think the raster is too large:

r1 <- rast(horse_zone, res=10000)
rand_samp10000 <- resample(rand_samp, r1)
terra::extract(rand_samp10000, horse_zone, na.rm=T, exact=T)

Thank you,


Solution

  • It is not possible to diagnose this without inspecting the data. The raster is not very big, that should not be the problem. Perhaps the vector is extremely complex or invalid? You could try using weights=TRUE instead of exact=TRUE. You could also try exactextractr::exact_extract which is very fast.