繁体   English   中英

如何从 rgbif 中的搜索中保存出现数据

[英]How to save occurrence data from a search in rgbif

我是一个新的 R 用户,我有兴趣使用 rgbif 下载一组特定的数据。 我做了:

occ_search(scientificName = "Lupinus", hasCoordinate = TRUE, continent = c('africa', 'europe', 'asia'),
       basisOfRecord = "PRESERVED_SPECIMEN", decimalLatitude = '-1.50750278, 47.62390556',
       decimalLongitude = '-18.75250000, 52.85138889',
       fields = c('scientificName', 'decimalLatitude', 'decimalLongitude', 'country'), return = 'data')

这可以很好地进行搜索。 但是,我想要做的是将搜索保存为一个对象,以创建它的 .csv 文件。 如果我走:

OS <- occ_search(scientificName = "Lupinus", hasCoordinate = TRUE, continent = c('africa', 'europe', 'asia'),
       basisOfRecord = "PRESERVED_SPECIMEN", decimalLatitude = '-1.50750278, 47.62390556',
       decimalLongitude = '-18.75250000, 52.85138889',
       fields = c('scientificName', 'decimalLatitude', 'decimalLongitude', 'country'), return = 'data')

然后

OS1 <- as.data.frame(OS)

我收到以下错误:

Error in as.data.frame.default(occ) : cannot coerce class ""gbif"" to a data.frame

我也试过这样使用occ_download

OD <- occ_download("scientificName = Lupinus",
                       "hasCoordinate = TRUE",
                       "continent = africa,europe,asia",
                       "basisOfRecord = PRESERVED_SPECIMEN",
                       "decimalLatitude >= -1.50750278", 
                       "decimalLatitude <= 47.62390556",
                       "decimalLongitude >= -18.75250000",
                       "decimalLongitude <= 52.85138889")                        

我得到的只是一个包含 0 个观察值和 235 列的文件。

任何帮助将不胜感激!

您的occ_search输出与as.data.frame不兼容的原因是在continent = c('africa', 'europe', 'asia')参数中。 如果您查看length(OS)str(OS) ,您会发现它实际上包含三个 data.frames。 您可以像这样访问各个元素:

OS$europe
# or
OS['europe']
# or
OS[[1]]

你可以像这样组合这些

OC1 <- rbind(OS$africa, OS$europe, OS$asia)

或者,如果您不打算知道所有不同的名称,如下所示:

do.call(rbind, OS)

要将具有class "gbif"的对象转换为 data.frame,您可以执行OS.df <- do.call(rbind.data.frame, OS)

对于occ_download您需要设置用户名、电子邮件和密码。 正如 gbif 网站(http://www.gbif.org/developer/occurrence#download) 一样,事件下载是异步创建的 - 用户请求下载,一旦完成,就会发送并通过电子邮件发送结果文件的链接。

OD <- occ_download(user = "name", pwd = "pass", email = "e@mail.com", "scientificName = Lupinus", "hasCoordinate = TRUE", "continent = africa,europe,asia","basisOfRecord = PRESERVED_SPECIMEN","decimalLatitude >= -1.50750278","decimalLatitude <= 47.62390556","decimalLongitude >= -18.75250000","decimalLongitude <= 52.85138889")

返回类gbif download的对象,您应该会收到每封邮件的下载链接或访问http://www.gbif.org/user/download直接下载。 这也可以通过gbif.org 上的下载选项来完成。

<<gbif download>> Username: philipprobeck E-mail: phill@gmx.li Download key: 0078579-160910150852091

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM