Previously I was using raster::crop
and raster::mask
with shapefiles of class Spatial*, read in using rgal::readOGR
.
I am just "upgrading" my scripts to use sf
for reading and manipulating polygons.
raster::crop
raster::crop
expects an 'extent' object as second argument. Up to now, this was automatically extracted from a Spatial* object. So I could just do raster::crop(raster, polygon)
.
To get this working with an sf
object, I can call raster::crop(raster, as.vector(st_bbox(polygon)))
as an ugly workaround.
raster::mask
Since raster::mask
clearly expects a Raster* object or a Spatial* object
the only solution was to coerce the sf
object back to a Spatial* object using as("Spatial")
.
I assume this problem generalized to all raster
functions? Did I overlook something or is it just the case that the raster
package does not (yet) work with sf
objects?