I want to rasterize a shapefile into a raster according to another raster (97284, 154208, 15001971072 (nrow, ncol, ncell)).

Since the raster is very big, I am using gdal_rasterize following the code below

    rp<-gdal_rasterize(shapefile, big raster)

However, I am getting this error

Error in as.character.default() : no method for coercing this S4 class to a vector

1) What format does the shapefile need to be in to rasterize? 2) Is there another way to rasterize a shapefile? I have tried rasterize() and it is taking very long and I have also read posts that say that gdal_rasterize is much faster for very big raster


1 Answer 1


As per the comment you need to define filename names in character form, and it is usually best to define the bands and the field for rasterization as minimum parameters, e.g.:

# write out the blank raster template to 'burn' values into
# write out the shapefile
writeOGR(shapefile,".","shape",driver="ESRI Shapefile")

# perform gdal_rasterize, defining band structure (this e.g. b=-1) and field to burn
rg <- gdal_rasterize("shape.shp","big_raster.tif",b=1,a="myfield")

this aids speed by not storing all of that raster information in memory and just writing to disk, similar to speed increases found when putting a filename directly inside the rasterize() function

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.