oceanhackweek / ohw20-proj-species-marine-protected-areas

4 stars 15 forks source link

Internal Server Error (HTTP 500) #31

Open nposdalj opened 3 years ago

nposdalj commented 3 years ago

One MPA in Cuba is still giving an internal server error.

To recreate this error:

  1. Run lines 1-99 in the script 'CalculatingES50.R'
  2. Make i = 88 (instead of running through all the MPAs)
  3. Run lines 103-105 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
btupper commented 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. wdpa88_cuba

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.

https://github.com/oceanhackweek/ohw20-proj-species-marine-protected-areas/blob/9c11ab9929c2bc63c9de0d83bd284b4bf6377d67/R/CalculatingES50.R#L105

I haven't tested it, but it should work right out of the box for you.