Open nposdalj opened 3 years ago
As Abby/Pieter suggested there is a topology issue with that polygon (it's sort of NW Cuba). I tried simplifying then computing the hull. Nope. Then I trie computing the hull and then simplifying that. Nope. Then I tried simplify -> hull -> simplify. Nope. You can see in the attached that the hull is not the actual hull - close but no cigar.
So instead of investing in making this one to make it work, I just wrapped the call to robis::occurence()
in a try()
. Then I test what comes back. If it is an error then we force your SpeciesOccurence
variable to have the NULL
value. The logic of your if blocks takes care of the rest so it otherwise keeps humming.
I haven't tested it, but it should work right out of the box for you.
One MPA in Cuba is still giving an internal server error.
To recreate this error:
hull = st_convex_hull(ES50_df$geom[[i]]) #find the convex hull for the polygon
text = st_as_text(hull) #convert it to text
SpeciesOccurence = occurrence(geometry = text) #query OBIS for species within that polygon