1

I am trying to create a species richness raster in R, using the lets.presab() function from the letsR library, as follows:

RichnessMap <- lets.presab(SpeciesSubsets)

SpeciesSubsets looks as follows:

Simple feature collection with 1041 features and 18 fields
Geometry type: MULTIPOLYGON
Dimension:     XY
Bounding box:  xmin: -180 ymin: -55.97681 xmax: 180 ymax: 83.11072
Geodetic CRS:  WGS 84
First 10 features:
      sisid              sci_nam presenc origin seasonl
1  22721194 Amphispiza bilineata       1      1       1
2  22721194 Amphispiza bilineata       1      1       2
3  22721194 Amphispiza bilineata       1      1       3
4  22721194 Amphispiza bilineata       1      1       4
5  22718556     Anthus pratensis       1      1       2
                                                                                      source
1         Sibley, 2000; Howell and Webb, 1995; Poole & Gill, 1992-2002; del Hoyo et al, 2011
2                                                      Sibley, 2000; Poole & Gill, 1992-2002
3                                                                                eBird, 2020
4                                                                                eBird, 2020
5           Cramp 1997; Flint 1984; Boertmann 1994; Alstrom & Mild 2003; Keller et al., 2020
                                                                                                      
1                                                                          NatureServe, 2005; Anna Motis (HBW)
2                                                                                            NatureServe, 2005
3                                                                      Claudia Hermes (BirdLife International)
4                                                                      Claudia Hermes (BirdLife International)
5  BirdLife International; Hannah Wheatley (BirdLife International); Karris McGonigle (BirdLife International)
   dat_sns sns_cmm dst_cmm tax_cmm genrlsd
1        0    <NA>    <NA>    <NA>       0
2        0    <NA>    <NA>    <NA>       0
3        0    <NA>    <NA>    <NA>       0
4        0    <NA>    <NA>    <NA>       0
5        0    <NA>    <NA>    <NA>       0
                                                                citatin yrcmpld yrmodfd
1  BirdLife International and Handbook of the Birds of the World (2021)    2018    2021
2  BirdLife International and Handbook of the Birds of the World (2021)    2015    2021
3  BirdLife International and Handbook of the Birds of the World (2021)    2020    2021
4  BirdLife International and Handbook of the Birds of the World (2021)    2020    2021
5  BirdLife International and Handbook of the Birds of the World (2021)    2021    2021
   version     Shp_Lng    Shap_Ar                       geometry
1   2023.1  137.408414 148.515116 MULTIPOLYGON (((-109.0927 3...
2   2023.1   90.862548  87.616972 MULTIPOLYGON (((-114.3344 4...
3   2023.1   14.207916   6.407769 MULTIPOLYGON (((-106.0315 2...
4   2023.1    9.914815   3.586253 MULTIPOLYGON (((-107.2083 2...
5   2023.1 1516.630955 966.522215 MULTIPOLYGON (((5.582886 60...

And I get the following error:

Error in .removeCells(Resultado) : 
  No cells left after removing cells without occurrences

My understanding is that this should only occur when no cells have any overlap with any polygons, and I am not sure how this could have had with this set of multi polygons. I have tried to convert the Multipolygon object into a SpatVector object, which made it become structured as follows:

 class       : SpatVector 
 geometry    : polygons 
 dimensions  : 1041, 18  (geometries, attributes)
 extent      : -180, 180, -55.97681, 83.11072  (xmin, xmax, ymin, ymax)
 coord. ref. : lon/lat WGS 84 (EPSG:4326) 
 names       :    sisid         sci_nam presenc origin seasonl          source
 type        :    <int>           <chr>   <int>  <int>   <int>           <chr>
 values      : 22721194 Amphispiza bil~       1      1       1 Sibley, 2000; ~
               22721194 Amphispiza bil~       1      1       2 Sibley, 2000; ~
               22721194 Amphispiza bil~       1      1       3     eBird, 2020

           compilr dat_sns sns_cmm dst_cmm (and 8 more)
             <chr>   <int>   <chr>   <chr>             
   NatureServe, 2~       0      NA      NA             
 NatureServe, 2005       0      NA      NA             
   Claudia Hermes~       0      NA      NA             

but I got the same error.

1
  • Hard to tell without your data. The only difference I can really see with the example for lets.presab is you have MULTIPOLYGON and the example Phyllomedusa object has POLYGON geometry. Tried casting to POLYGON via st_cast(data, "POLYGON")? (I did just try casting that up to MULTIPOLYGON but it worked). Check your data with sf::is_valid maybe?
    – Spacedman
    Commented Sep 25 at 12:13

1 Answer 1

0

You have to name your columns correctly. The sample data set uses:

> names(Phyllomedusa)
[1] "binomial" "presence" "origin"   "seasonal" "geometry"
> p = lets.presab(Phyllomedusa)

But if I change the name "binomial" to "sci-nam" it fails with that error:

> names(Phyllomedusa)[1] = "sci_nam"
> p = lets.presab(Phyllomedusa)
Error in .removeCells(Resultado) : 
  No cells left after removing cells without occurrences

The help says:

  shapes: Object of class ‘SpatVect’ or ‘Spatial’ (see packages terra
          and sf to read these files) containing the distribution of
          one or more species. Species names should be stored in the
          object as BINOMIAL/binomial or SCINAME/sciname.

The code looks like it also allows "SPECIES", setting all these variants (upper and lower case) to "BINOMIAL" and then it works on that:

    names(shapes)[names(shapes) %in% c("SCINAME", "SCI_NAME", 
                                       "SPECIES")] <- "BINOMIAL"

So rename your column and try again!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.