r-spatialecology/landscapemetrics

Receive 'length' error when using sample_lsm with polygons

Closed this issue · 5 comments

Hello,

I'm using package version 2.0.0. and keep receiving the following error when using sample_lsm(): Error in numeric(NA) : invalid 'length' argument.

My code looks like this:

EVT20 = raster("LC20_EVT_220rcl_11142023.tif")

g18 = st_read("PTT18_MCPs_redo_NAD83.shp")

#Simple feature collection with 36 features and 1 field
#Geometry type: POLYGON
#Dimension: XY
#Bounding box: xmin: -1758059 ymin: 2370639 xmax: -1684142 ymax: 2553837
#Projected CRS: NAD83(2011) / Conus Albers

g18_metrics = sample_lsm(EVT20, g18, what = c("lsm_c_clumpy", "lsm_c_iji"), plot_id = g18$ID)

Error in numeric(NA) : invalid 'length'

The raster and shapefile have overlapping extents in the same datum. I've tried remaking the polygon file, subsetting to run fewer polygons, and even tried running one polygon at a time, and I'm still receiving the same error.

Any help is greatly appreciated!

Hey,

Your code looks like it should run. Do you have any MULTIPOLYGONS in your data? I remember we changed some of the behaviour there recently.

If you could actually share your data with us (or a sub-sample) so we could reproduce the error, we could look into this further.

Hi!

The issue was the calculation of the clumpy index. If I asked for just area and iji everything ran smoothly. I had to adjust my input rasters and calculate the clumpy index separately. My vector file did not contain any MULTIPOLYGONS.

Thanks for getting back to me!
Terrah

Hey Terrah,

Glad it's working for you now. Is there any chance you could still share some of the data with us? It sounds like you found a workaround, which is great, but something is still not working properly. You could also email the data to me and I won't share it with anyone else.

Okay, I think I found the bug. Was related to classes for which clumpy can not be calculated and how the corresponding NA is created. Should be fixed in f714a61.

Will close this for now, but please re-open if needed.