Closed NB-Bio closed 4 years ago
Thank you for the excellent bug report. I've reproduced it locally and hope to have a fix available shortly.
Hi, I found the problem. The problematic multi-polygon has its coordinates exceeding the extent of the input raster, so it's not a a package issue!
Thank you and congrats for this very useful package! NB
The problematic multi-polygon has its coordinates exceeding the extent of the input raster
The package is supposed to automatically extend the input raster with NA
values in that case, though. As you pointed out, this works in the unweighted calculation.
I have a fix, if you'd like to test it:
remotes::install_git('https://gitlab.com/isciences/exactextractr', ref='gh-12')
Now it works perfectly, thank you so much!
Hi, I am using the exactextractr R package to calculate the mean value of raster cells overlapped by a set of multi-polygon geometries (each multi-polygon represents the distribution of a species).
Here, the example files.
Since the raster is in geographic coordinates and the cells don't have all the same area, I actually need to calculate the weighted mean of the raster values, using the coverage fraction and the cell area as weights. So:
I read the raster and the shapefile:
Then, following the package instructions, I create a two-layer RasterStack, with the first layer containing my raster and the second layer containing the area of each cell:
Finally, I used the exact_extract function from the exactextractr package, with a customized function to calculate the weighted mean:
but I obtained the following error:
Error in .local(x, ...) : row <= x@nrows is not TRUE
The error is due to a single geometry(field "scntfcN" = Mirimiri acrodonta, here the shapefile).
It's a tiny multipolygon located on the Fiji Island (a theoretically single polygon split into two by the anti-meridian line) not intersecting the original raster.
Strangely, if I try to calculate the (no-weighted) mean through the predefined function of the package, it works well:
What could be the cause of the error?
Thanks, NB