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

问题描述

我很困惑,我正在尝试使用R + rgee创建JRC MonthlyHistory地表水计数观测值的区域时间序列(按区域)。我可以下载该波段的总观测值,但无法按特定值进行过滤,就我而言,我想选择每个区域每个月的“地表水观测值”计数。我认为这可能与数据集有关,即Bitmask,即

位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

链接到形状文件- 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")