Difficulty with the "calculate_lsm" function in the package
Closed this issue · 2 comments
I'm trying to use the "calculate_lsm" in large list of 341 rasters. This files are land use and land cover data. Like this:
metricas_base <- landscapemetrics::calculate_lsm(landscape = municipios_r,
edge_depth = 1,
what = c('lsm_c_ca',
'lsm_c_area_mn',
'lsm_c_np'),
full_name = TRUE,
verbose = TRUE,
progress = TRUE)
And this error occurs: Error in (function (classes, fdef, mtable) :
unable to find an inherited method for function ‘as.int’ for signature ‘"RasterLayer"’
Using "check_landscape" it appears that everything is ok. And checking with raster::dataType(x) it shows "INT1U". Can anyone give me some help? Still learning about this package.
@TallesBhering -- in short, you should not provide a list of RasterLayers as an input to this function. What you can do? You can either:
- Provide a list of
SpatRaster
s (from the terra package) - Provide one object of the
RasterStack
orRasterBrick
class
Assuming that your object municipios_r
is a list with 341 RasterLayer
objects, you can do:
municipios_r2 = lapply(municipios_r, terra::rast)
metricas_base <- landscapemetrics::calculate_lsm(landscape = municipios_r2,
edge_depth = 1,
what = c('lsm_c_ca',
'lsm_c_area_mn',
'lsm_c_np'),
full_name = TRUE,
verbose = TRUE,
progress = TRUE)
Hi, @Nowosad.
I was using the raster::raster function. Now it work.
Thank you so much for the answer and help!