GBIF-Europe / nordic_oikos_2018_r

Scientific reuse of openly published biodiversity information: Programmatic access to and analysis of primary biodiversity information using R. Nordic Oikos 2018, pre-conference R workshop. Venue: 18. feb. 2018 10:00 - 19. feb. 2018 16:00, Trondheim
http://www.gbif.no/events/2018/Nordic-Oikos-2018-R-workshop.html
GNU General Public License v3.0
5 stars 4 forks source link

polygon filtering in occ_download #1

Closed andersfi closed 6 years ago

andersfi commented 6 years ago

I can't (for some reason) don't get my head around using polygons as filtering in occ_download (probably just a stupid error somewhere).

occ_download('taxonKey = 2346633,2366645','hasCoordinate = TRUE',
                             'hasGeospatialIssue = FALSE',
                             'country = NO',
                             'geometry = POLYGON((9.33 62.80,9.33 64.20,12.13,64.20,12.13,62.80,9.33 62.80))',
                             type="and")

This will return "Error: Bad Request (HTTP 400)". (with the line 'geometry..." hashed out it works fine). Full example in the "Search and request download key" section of async_download_gbif.Rmd

dagendresen commented 6 years ago

The first thing I noticed was that the WKT includes some extra commas in tuple 3 and 4: 'geometry = POLYGON((9.33 62.80,9.33 64.20,12.13,64.20,12.13,62.80,9.33 62.80))' 'geometry = POLYGON((9.33 62.80,9.33 64.20,12.13 64.20,12.13 62.80,9.33 62.80))'

A web search in the portal gives 66 hits https://www.gbif.org/occurrence/search?country=NO&has_coordinate=true&has_geospatial_issue=false&taxon_key=2346633&geometry=POLYGON((9.33%2062.80,%209.33%2064.20,%2012.13%2064.20,%2012.13%2062.80,%209.33%2062.80))

GBIF REST API search gives 66 hits http://api.gbif.org/v1/occurrence/search?taxon_key=2346633&country=NO&has_coordinate=true&has_geospatial_issue=false&geometry=POLYGON((9.33%2062.80,%209.33%2064.20,%2012.13%2064.20,%2012.13%2062.80,%209.33%2062.80))

Testing with rgbif occ_search() also gives 66 hits

sp_data <- (occ_search (taxonKey = '2346633', hasCoordinate = 'TRUE',
   hasGeospatialIssue = 'FALSE',
   country = 'NO',
   geometry = 'POLYGON((9.33 62.80, 9.33 64.20, 12.13 64.20, 12.13 62.80, 9.33 62.80))',
   limit=100))$data

But for some reason using the occ_download() still gives me an error on the GBIF portal side.

sp_downloadKey <- (occ_download ('taxonKey = 2346633', 'hasCoordinate = TRUE',
   'hasGeospatialIssue = FALSE',
   'country = NO',
   'geometry = POLYGON((9.33 62.80,9.33 64.20,12.13 64.20,12.13 62.80,9.33 62.80))',
   type = "and"))[1]

I get the request posted to the GBIF portal API, but find this error message: "Broken download. The download request was unsuccessful. Please try it again or get in touch." See download URL: https://www.gbif.org/occurrence/download/0002836-171113114016250

dagendresen commented 6 years ago

See also: https://discuss.ropensci.org/t/rgbif-using-geometry-in-occ-download/395

dagendresen commented 6 years ago

When I click "RERUN QUERY" in the failed download request page, I do get the 66 hits https://www.gbif.org/occurrence/download/0002836-171113114016250

RERUN QUERY URL is: https://www.gbif.org/occurrence/search?taxon_key=2346633&has_coordinate=TRUE&has_geospatial_issue=FALSE&country=NO&geometry=POLYGON((9.33%2062.80,9.33%2064.20,12.13%2064.20,12.13%2062.80,9.33%2062.80))

dagendresen commented 6 years ago

When I make the same search in R without the geometry attribute, I do get hits (3317 hits)

sp_downloadKey <- (occ_download ('taxonKey = 2346633', 'hasCoordinate = TRUE',
  'hasGeospatialIssue = FALSE',
  'country = NO',
  type = "and"))[1]

https://www.gbif.org/occurrence/download/0002855-171113114016250

mskyttner commented 6 years ago

Fixed in #2, confirmed and merged by @andersfi