0
votes

I am working exclusively on the terra package.

spatRaster details: Carbon flux data of South America (~500 GB)

spatVector details: Protected Areas database of South America (~70 MB)

Goal: To compute zonal statistics

Error: While performing zonal statistics operation, the extents do not overlap.

Possible reason for error: Raster files have only the terrestrial extent. Polygons, however, extend up to marine regions, thus have terrestrial, marine, and terrestrial-marine combined extents.

Question: Is it possible to extend the raster file up to the extent of Polygon without losing any values for this much large file? Is there any efficient way to solve this kind of problem?

PS: I am new here, and if anyone finds out that the similar question is answered already, please help me out. I am sorry that I couldn’t make a reproducible example for this problem.

1

1 Answers

1
votes

There is no "'SpatRaster,SpatVector" method for zonal, so your question has no answer. I assume you use rasterize first and make a mistake there. As for all R questions, you should have included a minimal, self-contained reproducible example, like the below that suggests that there is no need to do what you think you need to do

library(terra)
#terra version 1.1.16
f <- system.file("ex/lux.shp", package="terra")
v <- vect(f)
f <- system.file("ex/elev.tif", package="terra")
r <- rast(f)

# remove part of raster, such that polygons have larger extent 
r <- crop(r, v[1:5])

z <- rasterize(v, r, "NAME_1")    
zonal(r, z, mean, na.rm=TRUE)

#        NAME_1 elevation
#1     Diekirch  403.4237
#2 Grevenmacher  329.4595
#3   Luxembourg  315.2139