我正在通过这个网页的 eBird 代码工作:https : //github.com/CornellLabofOrnithology/ebird-best-practices/blob/master/03_covariates.Rmd
除了使用我自己的数据。我有一个来自澳大利亚 gadm.org 的 .gpkg,以及我自己为澳大利亚选择的电子鸟数据。我完全遵循了代码,除了不使用“bcr”,因为我的数据集没有 bcr 代码,同时st_buffer(dist = 10000)
从 rgdal 代码中删除,因为这使我由于某种原因无法实际下载 MODIS 数据。
编辑:我还使用了网站提供的数据,但仍然收到相同的错误
我被这个代码困住了:
lc_extract <- ebird_buff %>%
mutate(pland = map2(year_lc, data, calculate_pland, lc = landcover)) %>%
select(pland) %>%
unnest(cols = pland)
Run Code Online (Sandbox Code Playgroud)
它返回此错误:
Error: Problem with `mutate()` input `pland`.
x error in evaluating the argument 'x' in selecting a method for function 'exact_extract': invalid layer names
i Input `pland` is `map2(year_lc, data, calculate_pland, lc = landcover)`.)`
Run Code Online (Sandbox Code Playgroud)
我似乎无法弄清楚如何纠正它,我对这样的密集地理空间代码很陌生。
链接里有免费的数据集,但是我还没试过,所以可能是我的数据与代码不兼容?但是,我查看了提供的 Gis-data.gpkg,我的 gadm 数据似乎很好。
上面的前两个代码是:
lc_extract <- ebird_buff %>%
mutate(pland = map2(year_lc, data, calculate_pland, lc = landcover)) %>%
select(pland) %>%
unnest(cols = pland)
Run Code Online (Sandbox Code Playgroud)
该网页的作者已经回答了这个问题。
解决方案是这段代码:
lc_extract <- NULL
for (yr in names(landcover)) {
# get the buffered checklists for a given year
regions <- ebird_buff$data[[which(yr == ebird_buff$year_lc)]]
# get landcover values within each buffered checklist area
ee <- exact_extract(landcover[[yr]], regions, progress = FALSE)
# count the number of each landcover class for each checklist buffer
ee_count <- map(ee, ~ count(., landcover = value))
# attach the year and locality id back to the checklists
ee_summ <- tibble(st_drop_geometry(regions), data = ee_count) %>%
unnest(data)
# bind to results
lc_extract <- bind_rows(lc_extract, ee_summ)
}
Run Code Online (Sandbox Code Playgroud)
致谢:Matt Strimas-Mackey