使用 R + rgee 按区域创建 JRC MonthlyHistory 地表水观测的时间序列

Create time series of JRC MonthlyHistory surface water observations by region with R + rgee

我完全被难住了,我正在尝试使用 R + rgee 创建 JRC MonthlyHistory 地表水计数观测(按区域)的区域时间序列。我可以下载波段的总观测值,但无法按特定值进行过滤,在我的情况下,我想 select 每个月每个区域的“地表水观测值”计数。我认为这可能与作为位掩码的数据集有关,即

位0-1:水检测 0:无数据 1:不是水 2: 水

library(rgee)
library(mapview)

ee_Initialize()

surface_water <- ee$ImageCollection("JRC/GSW1_2/MonthlyHistory")$
      filterDate("2006-01-01", "2006-12-31")$
      map(function(x) x$reproject("EPSG:4326")$select("water[1]"))
    
ee_sw <- ee_extract(x = surface_water, y = wnf_shapes,  scale = 30, fun = ee$Reducer$count(), sf = FALSE)
    
colnames(ee_sw) <- sprintf("%02d", 1:12)
    ee_sw$id <- wnf_shapes$id

link 到形状文件 - https://drive.google.com/file/d/1oWJ_ZpEQ4bEYr7R73oOXrQc9UhOH_oCB/view?usp=sharing

此代码应该有效:

library(rgee)

ee_Initialize()

geom_nauta <- ee$Geometry$Point(c(-73.47693, -4.44500))$buffer(10000)
surface_water <- ee$ImageCollection("JRC/GSW1_2/MonthlyHistory") %>% 
  ee$ImageCollection$filterDate("2006-01-01", "2006-12-31") %>% 
  ee$ImageCollection$map(function(img) img$updateMask(img$eq(1)))

ee_sw <- ee_extract(
  x = surface_water, 
  y = geom_nauta,
  scale = 30,
  fun = ee$Reducer$count(), 
  sf = FALSE
)

plot(ee_sw %>% as.numeric(), type="l")