Issue when using polygons in sample_lsm
Closed this issue · 8 comments
Hello there,
I am trying to run:
sample_lsm(habitats.r,estuaries,plot_id=estuaries@data$EST_NAME, level = "class")
'estuaries' is a SpatialPolygonsDataFrame.
And I get:
"Error in lapply(X = raster::as.list(landscape), FUN = sample_lsm_int, :
argument "size" is missing, with no default"
I tried with a SpatialPolygons object, but get the same error. Any help would be much appreciated.
Thanks
Ana
Hey Ana,
Oh I see...the problem is that you currently need a size
-arugment, eventhough it is not used for polygons.
Please try to use sample_lsm(habitats.r, estuaries, size = 0, plot_id = estuaries@data$EST_NAME, level = "class")
as a quick fix.
We will work on a better solution in a way that size
won't be needed for polygons in the future.
Thanks for the quick reply!
I get another error and warnings now:
samples = sample_lsm(habitats.r,y=estuaries,plot_id=estuaries@data$EST_NAME, level = "class", size=0)
Error in .local(x, y, ...) : Cannot get an Extent object from argument y
In addition: There were 11 warnings (use warnings() to see them)
warnings()
Warning messages:
1: Length of plot_id is not identical to length of y. Using 1...n as plot_id.
2: Class 18: ENN = NA for class with only 1 patch
3: Class 18: ENN = NA for class with only 1 patch
4: Class 18: ENN = NA for class with only 1 patch
5: Class 4: PAFRAC = NA for class with < 10 patches
6: Class 8: PAFRAC = NA for class with < 10 patches
7: Class 10: PAFRAC = NA for class with < 10 patches
8: Class 11: PAFRAC = NA for class with < 10 patches
9: Class 12: PAFRAC = NA for class with < 10 patches
10: Class 14: PAFRAC = NA for class with < 10 patches
11: Class 18: PAFRAC = NA for class with < 10 patches
Warnings 2-11 are ok, but I do not know why I get warning 1, as:
length(estuaries)
[1] 126
length(estuaries@data$EST_NAME)
[1] 126
Also, what does that error mean?
Thanks
Ana
That's a good question what the error means 😄 Seems like, there is a problem with your polygon. This might also be the reason you get the first warning. Would it be possible for you to share your (either here or via mail if you don't want to share your data publicly) so I can reproduce the error?
This does work:
extent(estuaries)
class : Extent
xmin : 217815.1
xmax : 561367
ymin : 5847562
ymax : 6884361
I think I might have found the problem. The subsetting of the polygons you used is not correct for SpatialPolygonsDataFrame.: y[current_plot,] should be used instead of y[current_plot]
I still cannot run the code because of other errors that derive from the fact that I am running the function in the wrong environment (this is as far as my R skills go).
Thanks for digging deeper into the problem and I think I fixed it. You can get the newest development version using devtools::install_github("r-spatialecology/landscapemetrics")
and see if it works.
However, there seems to be several problems with your data, I'm not sure how to fix at the moment (@marcosci, @Nowosad ).
- The first problem is, that some of your sample plots because of their location, shape and size return no cells at all (e.g.
estuaries[54,]
). - Another problem is that your sample plots are not necessarily continuous (e.g.
plot(estuaries[89,])
), which will actually result in 3 sample plots because we need to disaggregate them.
Thanks! I'll fix my polygons and try again.
I will close this for now. Pleas re-open if any other problems occur.