变异找不到功能

酸橙

我正在通过此网页浏览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)

它返回此错误:

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)`.)`

我似乎无法弄清楚如何纠正它,对于这样的密集地理空间代码,我还是比较陌生。

链接中有一个免费的数据集,但是我还没有尝试过,所以可能是我的数据与代码不兼容?但是,我查看了所提供的Gis-data.gpkg,我从gadm获得的数据似乎还不错。

以上代码的前两个代码是:

neighborhood_radius <- 5 * ceiling(max(res(landcover))) / 2
 ebird_buff <- red_knot %>% 
     distinct(year = format(observation_date, "%Y"),
              locality_id, latitude, longitude) %>% 
     # for 2019 use 2018 landcover data
     mutate(year_lc = if_else(as.integer(year) > max_lc_year, 
                              as.character(max_lc_year), year),
            year_lc = paste0("y", year_lc)) %>% 
     # convert to spatial features
     st_as_sf(coords = c("longitude", "latitude"), crs = 4326) %>% 
     # transform to modis projection
     st_transform(crs = projection(landcover)) %>% 
     # buffer to create neighborhood around each point
     st_buffer(dist = neighborhood_radius) %>% 
     # nest by year
     nest(data = c(year, locality_id, geometry))
 calculate_pland <- function(yr, regions, lc) {
     locs <- st_set_geometry(regions, NULL)
     exact_extract(lc[[yr]], regions, progress = FALSE) %>% 
         map(~ count(., landcover = value)) %>% 
         tibble(locs, data = .) %>% 
         unnest(data)
 }
酸橙

该网页的作者已经回答了这个问题。

解决方案是此代码:

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)
}

学分至:Matt Strimas-Mackey

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章