Search code examples
rterra

Terra rasterize() failing after update to 1.8 with 'too many values for writing'


Since updating terra to 1.8-5, rasterize() is throwing the following error:

"Error in h(simpleError(msg, call)) : error in evaluating the argument 'x' in selecting a method for function 'rast': [rasterize] too many values for writing: 84300725 > 83166375"

Data used in example:

  1. NC County Boundaries
  2. MRLC's NLCD

Example:

library(terra)
library(sf)
library(dplyr)



nlcd <- terra::rast("C:/Users/Eliot/Desktop/terra_test_data/nlcd_2021_land_cover_l48_20230630/nlcd_2021_land_cover_l48_20230630.img")

counties <- sf::st_read("C:/Users/Eliot/Desktop/terra_test_data/NCDOT_County_Boundaries/NCDOT_County_Boundaries.shp") %>%
  st_transform(crs(nlcd))

madison <- counties %>% 
  dplyr::filter(NAME == "Madison")

nlcd <- crop(nlcd, vect(counties), mask = FALSE)

rasterize(vect(madison), nlcd)


Based on some experimentation, this appears to be related to the size of the SpatRaster within the Y parameter. In my actual code, I am rasterizing many polygons of plant species observations distributed across the species' range; in which case, the SpatRaster must be, at minimum, the size of the species' range.

OS: Windows 11

Raster Version: 1.8.5

R Version: 4.4.2


Solution

  • This issue has been resolved: https://github.com/rspatial/terra/issues/1686.