SPOCC and Bounding Boxes

I want to assemble some species occurrence data from inat and GBIF for New Zealand using SPOCC.
I’d like to do that using a bounding box to cover NZ and offshore islands.
The obvious bounding box has the usual issue of failing because it crosses the 180/-180 meridian.
The solution, I assumed, was to provide two adjacent bounding boxes on either side of the meridian.
Here’s an example without too much data …

NZBox <- list(c(165,-53,180,-29),c(-180,-53,-175,-29))
spp <- c('Amanita muscaria','Chalciporus piperatus')
out <- occ(query=spp, from=c('inat','gbif'),  geometry=NZBox, has_coords = TRUE)

Unfortunately I get back records outside the combined boxes, in eastern Australia.
What am I doing wrong?

1 Like

Thanks for your question. I’ll look closely in the morning, but at first glance I think we may not allow for multiple bounding boxes passed in at once. …

@JC_NZ What version of spocc are you using?

This shouldn’t work, providing two boxes. In the current version this errors for me with Error: length(bbox) == 4 is not TRUE. Maybe we should support multiple bounding boxes :smile: For now, you could just pass those in a for loop or lapply type call.

Looking at the actual search results now, not sure why that’s not working…

Are these the bounding boxes you are going for? Just want to be on the same page

Yes. They cover the mainland and the Chatham islands, beyond the 180 meridian.

Yes now I get that error. Not sure why I didn’t before, or why this example, top of p16 of the SPOCC manual, works …

occ(geometry = list(c(-125.0,38.4,-121.8,40.9), c(-115.0,22.4,-111.8,30.9)), from = “gbif”)

Okay, i’m on the same page wrt the boundaries.

Ah, there must be some interaction when you give geometry as a list and when you also give a taxon name to query. I think i’ve identified the line of code that’s causing the problem https://github.com/ropensci/spocc/blob/master/R/occ.r#L80 - looks like when a taxon name and geometry as a character or numeric vector we’re fine, but if it’s a list, then it blows up.

I’ll try to get a fix soon…

@JC_NZ Okay, try it again, after installing from Github. devtools::install_github("ropensci/spocc")

library(spocc)
NZBox <- list(c(165,-53,180,-29), c(-180,-53,-175,-29))
spp <- c('Amanita muscaria', 'Chalciporus piperatus')
out <- occ(query = spp, from = c('gbif', 'inat'),
       geometry = NZBox, 
       has_coords = TRUE)

Searched: gbif, inat
Occurrences - Found: 289, Returned: 289
Search type: Scientific
  gbif: Amanita muscaria (0), Chalciporus piperatus (59)
  inat: Amanita muscaria (220), Chalciporus piperatus (10)

still need to do some fixing to the print method for this, as there are gbif results, but they aren’t shown in the print method…coming soon https://github.com/ropensci/spocc/issues/143 - UPDATE: fixed the print methods i believe

Note that the way occ() behaves when you pass in more than one thing to the geometry is that we do a separate request to the data provider for each geometry element (i.e., bounding box or WKT string). None of the data providers allow multiple geometry elements in one call, so this is what we’re left with. Internally, we do a separate request for each geometry element, and combine those results for each taxon name queried. Of course if you don’t query for any taxa, then each result is just for that geometry bounding box/WKT string

@JC_NZ Did you get a chance to try this again? Hope it’s working for you now :smile:

Yes it works now thanks.

Great, glad it works.