28 Nov 2011

Retrieve GBIF Species Occurrence Data with Function from dismo Package

..The dismo package is awesome: with some short lines of code you can read & map species distribution data from GBIF (the global biodiversity information facility) easily:


# get GBIF data with function:
myrger <- gbif("Myricaria", "germanica", geo = T)

# check:

# plot occurrences:
plot(wrld_simpl, col = "light yellow", axes = T)
points(myrger$lon, myrger$lat, col = "red", cex = 0.5)
text(-140, -50, "MYRICARIA\nGERMANICA")


  1. Hi there. This is very cool. I've given it a few tries though and consistently get the below error. Any ideas?

    > myrger <- gbif("glaucomys", "*", geo = T)
    glaucomys * : 3714 occurrences found
    1-1000Start tag expected, '<' not found
    Error: 1: Start tag expected, '<' not found

    1. ..apparently there is a server-problem at the moment - I tried to query http://data.gbif.org/occurrences/ and got this message: "The server is temporarily unable to service..."

    2. Just tried it again & there seem to be more serious issues. I get the same error over and over again, as reported above.

      I will keep track on that & report in case I can resolve the error..

  2. I've been up against this problem over the last few days. The answer is brute force... just keep trying. I've rehashed the gbif function a bit to make it keep trying until the server responds. It will, eventually. For species/genera with many records (e.g. genus 'bufo'), it's a major pain to have the function exit halfway through the download... I'll post my code soonish (although the above is of course pretty straight-forward to implement).

    1. John, thanks for your comments. So, you support my notion that this is a server issue..

      To make your hacked version of the function available would be very much appreciated!!

      I guess contacting the author of the function and to report about this issue would also be a good idea..

  3. Yep, I'm pretty sure it's server-side... an email response from their support people: "...sometimes the portal database is heavily loaded and that can lead to long response times".

    Good point about contacting Robert... I raised another issue with him today and he was very receptive.

    I said I'd post the code, but I don't know enough about GPL licenses to feel comfortable with meddling with RH's code and distributing, but I've emailed him and will leave it to him to update.

    Anyway, the temporary fix I used was just a couple of while loops:
    while (!exists('x')) { ... } and while (!exists('zz')) { ... }
    along with try or tryCatch statements and informative cat'd text.

  4. FYI Robert has added an ntries argument to the gbif function. The new version is now available at R-Forge (https://r-forge.r-project.org/R/?group_id=623), and I believe it will be on CRAN in the near future.