I want to use the the makeEOO
function from the redlistr package to calculate the Extent of Occurrence of 2 species ("binomial" A and B), starting from a shapefile with the corresponding distribution maps in form of polygons. To use the function, I need to convert the polygons into points.
Here the starting shapefile.
I am using the sf
package to import the shapefile
library(sf)
dummy <- st_read(dsn = "Calculate_EOO_dummy/dummy_maps_dissolved.shp")
plot(dummy)
I converted the polygons into multipoint features, and the multipoints into points
multi.p <- st_cast(dummy.diss, "MULTIPOINT")
my.points <- multi.p %>% group_by(binomial) %>% st_cast("POINT")
plot(my.points)
my.points
> my.points
Simple feature collection with 33 features and 1 field
geometry type: POINT
dimension: XY
bbox: xmin: -0.9471488 ymin: -0.9276773 xmax: 1.155772 ymax: 0.8080668
epsg (SRID): 4326
proj4string: +proj=longlat +datum=WGS84 +no_defs
# A tibble: 33 x 2
# Groups: binomial [2]
binomial geometry
<fct> <POINT [°]>
1 A (-0.5855355 0.7913769)
2 A (-0.5771905 0.7774687)
3 A (-0.2267038 0.5771905)
4 A (-0.3936022 0.05702364)
5 A (-0.1098748 -0.1015299)
6 A (0.02642559 -0.340751)
7 A (-0.02920723 -0.4464534)
8 A (-0.3824757 -0.4297636)
9 A (-0.8553547 -0.2878999)
10 A (-0.9471488 -0.1182197)
# ... with 23 more rows
However, if I try to call the makeEOO
function with my.points, I get an error:
eoo <- my.points %>% group_by(binomial) %>% makeEOO()
Error in makeEOO(my.points) : trying to get slot "coords" from an object (class "sf") that is not an S4 object.
How could I convert such polygons (separately for each species A and B) into points to use makeEOO
?
Best Answer
The
redlistr
package depends on thesp
package, and not onsf
, there is an open issue on the package's GitHub about supportingsf
, but has not been addressed yet. So what you should do is add a step where you convert yoursf
object into aSpatialPointsDataFrame
object instead. Be careful though, you cannot applydplyr
verbs tosp
objects. So you will probably need to split your data before using themakeEOO()
function. This is how I would do it: