R: Handling of sf objects in raster package R: Handling of sf objects in raster package r r

R: Handling of sf objects in raster package


For future reference, it works now! Here's some slightly modified example code from ?crop, tested with raster version 2.6-7 which has been released on 2017-11-13.

library(raster)library(sf)r <- raster(nrow=45, ncol=90)r[] <- 1:ncell(r)# crop Raster* with sf objectb <- as(extent(0, 8, 42, 50), 'SpatialPolygons')crs(b) <- crs(r)b <- st_as_sf(b) # convert polygons to 'sf' objectrb <- crop(r, b)# mask Raster* with sf objectmb <- mask(r, b)


The announce of "sf" package available on CRAN was written on January 2017.
The last release of "raster" package was in June 2016.

"sf" package is too new to yet work with raster package.
So, for now, you need to use your "ugly workarounds"...