A previous script that I had is no longer working after the sf package major change. I am using sf 0.9.6 and raster 3.0.2. I have tried to modify my code but cannot run raster::extract()
.
My previous code now breaks on the second command and does not generate extent_program. I receive: Error in sp::CRS(SRS_string = from$wkt): unused argument (SRS_string = from$wkt)
.
# Read in polygons from 'my_shapefile.shp'
sf_program_fallow <- 'my_shapefile.shp' %>% sf::st_read() %>% sf::st_transform(crs = 32611)
# Generate extent of polygons (now generates error)
extent_program <- extent(sf::as_Spatial(sf_program_fallow))
# Calculate zonal statistics (note: 'my_ndvi_RasterLayer' created earlier)
ndvi_fallowed_fields <- raster::extract(x = 'my_ndvi_RasterLayer',
y = sf_program_fallow,
method = 'simple',
fun = mean,
na.rm = T,
sp = TRUE)
Updating the first line of code to the following produces extent_program but not ndvi_fallowed_fields
. I get the same error: Error in sp::CRS(SRS_string = from$wkt): unused argument (SRS_string = from$wkt)
sf_program_fallow <- 'my_shapefile.shp' %>% sf::st_read() %>% sf::st_transform(., sf::st_crs(32611))
sp = TRUE
, according to help is for spatial* objects,sf_program_fallow
is ansf
object; I'm not sure .img files have crs info and, also according toextract
manual, x should be araster
object, not sure if it can be read from disk straight into the function