2

我正在尝试使用 R 包从多个区域下载多个分类群的出现数据rgbif。我更喜欢通过将所有区域组合在一起来进行一次下载(因为我有数千个区域,单独下载会很疯狂)。但是,我没有找到这样做的方法。我可以occ_download为每个查询做一个区域。

这是我的示例代码:

library(rgbif)
gbif_taxon_keys = c(212, 359)
# below are bbox of 3 regions;
# I have polygons as WKT, but they are clockwise 
# (how to convert to counter clockwise??)
wkts = c("POLYGON((11.3431 47.2451,11.4638 47.2451,11.4638 47.2919,11.3431 47.2919,11.3431 47.2451))",
"POLYGON((12.9644 47.7608,13.0922 47.7608,13.0922 47.8453,12.9644 47.8453,12.9644 47.7608))",
"POLYGON((14.2284 48.2217,14.3669 48.2217,14.3669 48.3443,14.2284 48.3443,14.2284 48.2217))")

# this works
queries = occ_download_prep(
  pred_in("taxonKey", gbif_taxon_keys),
  pred("hasCoordinate", TRUE),
  pred("hasGeospatialIssue", FALSE),
  pred_within(wkts[1]),
  user = gbif_user, pwd = gbif_pwd,
  email = gbif_email)
out_test = occ_download_queue(.list = list(queries))

# now try to combine regions in one download
# this does not work
queries = occ_download_prep(
  pred_in("taxonKey", gbif_taxon_keys),
  pred("hasCoordinate", TRUE),
  pred("hasGeospatialIssue", FALSE),
  pred_within(wkts),
  user = gbif_user, pwd = gbif_pwd,
  email = gbif_email)
out_test = occ_download_queue(.list = list(queries))
Error: 'value' must be length 1
# this does not work neither (it runs though)
queries = occ_download_prep(
  pred_in("taxonKey", gbif_taxon_keys),
  pred("hasCoordinate", TRUE),
  pred("hasGeospatialIssue", FALSE),
  pred("geometry", paste0(wkts, collapse = ";")),
  user = gbif_user, pwd = gbif_pwd,
  email = gbif_email)
out_test = occ_download_queue(.list = list(queries))
<<gbif download metadata>>
  Status: KILLED

从我的GBIF下载中心,它说“下载请求不成功。”。

有人能帮忙吗?谢谢!

4

2 回答 2

0

只是将多边形连接成一个多多边形会导致重叠,这是无效的,并且会导致下载失败。

相反,使用 GIS 库来组合多边形。这是我为 R 找到的第一个:

library(sf)
x = st_as_sfc("POLYGON((5.032 52.237, 5.426 52.237, 5.426 52.525, 5.032 52.525, 5.032 52.237))")
y = st_as_sfc("POLYGON((5.234 52.033, 5.546 52.033, 5.546 52.311, 5.234 52.311, 5.234 52.033))")
u = st_union(x, y)

st_as_text(u)
[1] "POLYGON ((5.032 52.525, 5.426 52.525, 5.426 52.311, 5.546 52.311, 5.546 52.033, 5.234 52.033, 5.234 52.237, 5.032 52.237, 5.032 52.525))"

Wicket的快速检查显示我们现在有一个 8 边多边形,它应该可以用作 inside 谓词。

我认为,使用它,您可能可以将所有多边形放入一次下载中。单次下载的总积分上限为 10,000。

于 2021-05-06T12:04:12.960 回答
0

我想我知道如何做到这一点。我只是将所有多边形组合成一个多多边形,它似乎有效。

换句话说,我只是把上面的 3 个多边形放进去:

wkts2 = "MULTIPOLYGON (((11.3431 47.2451, 11.4638 47.2451, 11.4638 47.2919, 11.3431 47.2919, 11.3431 47.2451)), ((12.9644 47.7608, 13.0922 47.7608, 13.0922 47.8453, 12.9644 47.8453, 12.9644 47.7608)), ((14.2284 48.2217, 14.3669 48.2217, 14.3669 48.3443, 14.2284 48.3443, 14.2284 48.2217)))"

然后,我运行:

queries = occ_download_prep(
  pred_in("taxonKey", gbif_taxon_keys),
  pred("hasCoordinate", TRUE),
  pred("hasGeospatialIssue", FALSE),
  pred_within(wkts2),
  user = gbif_user, pwd = gbif_pwd,
  email = gbif_email)
out_test = occ_download_queue(.list = list(queries))

它适用于这个例子。@sckott 可能有更好的方法。

于 2021-04-20T16:08:19.167 回答