rgbif - Using "Geometry" in occ_download

Is it possible to use the argument “geometry” with the function occ_download?

I’m trying to retrieve gbif data using the occ_download function. When I include the geometry, I get the following error message:

occ_download('taxonKey = 7228682',  'hasCoordinate = TRUE', 'hasGeospatialIssue = FALSE', 'geometry=POLYGON((30.1 10.1, 10 20, 20 40, 40 40, 30.1 10.1))')

Error: Could not resolve type id '{' into a subtype of [simple type, class org.gbif.api.model.occurrence.predicate.Predicate]
 at [Source: HttpInputOverHTTP@51b1daac; line: 1, column: 289]

I have also tried to include ‘decimalLatitude’ and ‘decimalLongitude’. But it also does not work.

occ_download('taxonKey = 7228682', 'hasCoordinate = TRUE',  'hasGeospatialIssue = FALSE',
                  'decimalLatitude >= -20','decimalLatitude <= -2',
                  'decimalLongitude >= -53', 'decimalLongitude <=-28', type = 'or')

Error: Could not resolve type id '{' into a subtype of [simple type, class org.gbif.api.model.occurrence.predicate.Predicate]
 at [Source: HttpInputOverHTTP@16b169d2; line: 1, column: 495]

Any suggestion?

Thank you very much!

1 Like

Yes, it’s possible to use geometry parameter with occ_download().

I tried your code, and you needed some spaces, so occ_download('taxonKey = 7228682', 'hasCoordinate = TRUE', 'hasGeospatialIssue = FALSE', 'geometry = POLYGON((30.1 10.1, 10 20, 20 40, 40 40, 30.1 10.1))') should work, note spaces at geometry = POLYGON...

That does suggest we should fix the parsing done internally in occ_download since it shouldn’t fail on that. Opened an issue at https://github.com/ropensci/rgbif/issues/217

p.s., note that there is only 1 record for [that query](http://api.gbif.org/v1/occurrence/search?taxonKey=7228682&hasCoordinate=true&hasGeospatialIssue=false&geometry=POLYGON((30.1%2010.1,%2010%2020,%2020%2040,%2040%2040,%2030.1%2010.1))), via the search API - So in that case you could just use the search API via occ_search() or occ_data()

For the 2nd query, it appears that’s another case where spaces are needed around symbols, that is 'decimalLongitude <= -28' instead of 'decimalLongitude <=-28' - will fix in the issue at https://github.com/ropensci/rgbif/issues/217

@justropp Did that help at all?

Hi Scott,

Thank you! Yes, removing the spaces solved the problem.

Cheers,

Juliana

Great.

I’ve also fixed the parsing of inputs to occ_download in the package, see https://github.com/ropensci/rgbif/issues/217 - Reinstall from Github like devtools::install_github("ropensci/rgbif") - and those changes and others should be on CRAN soon.

1 Like