You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用flexsdm构建物种分布模型时的校准区与地理过滤问题

使用flexsdm构建物种分布模型遇到的两个问题

问题1:创建校准区返回0×0空表

执行calib_area()后得到空表,已排查occurrences_bin无NA值、selected_raster_stack无NA值且两者CRS一致,相关代码及排查过程如下:

# Define calibration area using a buffer method
calibration_area <- calib_area(
  data = occurrences_bin,
  x = "longitude",
  y = "latitude",
  method = c("buffer", width = 500),  # Try a larger width
  crs = crs(selected_raster_stack)
)
summary(calibration_area)
# < table of extent 0 x 0 >

排查代码:

any(is.na(occurrences_bin$longitude))
# [1] FALSE
any(is.na(occurrences_bin$latitude))
# [1] FALSE
occurrences_bin <- na.omit(occurrences_bin)
any(is.na(values(selected_raster_stack)))
# [1] FALSE
selected_raster_stack <- trim(selected_raster_stack)

# 物种分布数据加载与处理流程
occurrences <- fread("Databases/Occurences Folder/CleannedOcc_Classified_Nearctic.txt", 
                     stringsAsFactors = TRUE, encoding = "UTF-8")

# 转换为空间对象
wgs84<-"+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0" 
occurrences_sf <- st_as_sf(occurrences, coords = c("longitude", "latitude"), crs = wgs84)
# 转换为二元存在/缺失格式
occurrences_bin <- dcast(occurrences_sf, 
                         st_coordinates(occurrences_sf)[,1] + st_coordinates(occurrences_sf)[,2] ~ species,
                         value.var = "species", fun.aggregate = length)

setDT(occurrences_bin)

crs(occurrences_sf) ==  crs(selected_raster_stack)
# [1] TRUE

问题2:Moran's I地理过滤报错

执行occfilt_geo()时触发错误,提示缺少TRUE/FALSE值,相关代码及错误信息如下:

# Geographical filtering using Moran's I method
occ_filtered <- occfilt_geo(
  data = occurrences_bin,
  x = "longitude",
  y = "latitude",
  env_layer = selected_raster_stack,
  method = c('moran'),
  prj = crs(selected_raster_stack)
)

错误信息:

Error in if (any(mor <= method[2])) {: 
Missing value where TRUE/FALSE is required
Calls: occfilt_geo -> occfilt_geo_0
Execution interrupted

内容的提问来源于stack exchange,提问作者Gibran Anderson

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.13 12:43:24