I am trying to use the rasterize function in the R package terra (v.1.6-7) to transfer population values associated with municipalities to a raster. I am doing this for two shapefiles, dipomun00gw.shp and municipiosPOP.shp. This is the code:
library(terra)
# Read shapefiles for 2000 and 2010
v_00 <- vect("dipomun00gw.shp")
v_10 <- vect("municipiosPOP.shp")
# create blank rasters using each year's shape file as extent
r_00 <- rast(v_00, res=.01)
r_10 <- rast(v_10, res=.01)
# Rasterize
x_00 <- rasterize(v_00, r_00, "POTO00")
x_10 <- rasterize(v_10, r_10, "POB_10")
#Error: [rasterize] cannot create dataset
For some reason, v_00 rasterizes without any issues, but v_10 produces the an error.
I cannot identify what characteristic of the shapefile municipiosPOP.shp is causing this error.
Does anyone know what is going on?
Shapefiles can be accessed here.
The reason is that
r_10is too large (it has > 6.4e+16 cells!)This is because you assigned a spatial resolution of 0.01 (that is ~1 cm), where you presumably assumed you were using 0.01 degrees (~1 km). If you first project
v_10to long/lat (likev_00) your code works.