0
点赞
收藏
分享

微信扫一扫

Google Earth Engine(GEE)——2.提取降水值案例(R-GEE版)


安装和负载​​tidyverse​​​和​​sf​​- [R包,在这之后,初始化地球引擎řAPI。

#先加载库,再进行初始化!
library(tidyverse)
library(rgee)
library(sf)

ee_Initialize()

 读取​​nc​​形状文件,加载矢量文件。

nc <- st_read(system.file("shape/nc.shp", package = "sf"), quiet = TRUE)

 绘制 2001 年的每​​幅​​​图像以从​​Terraclimate 数据集中​​提取月降水量 (Pr)

terraclimate <- ee$ImageCollection("IDAHO_EPSCOR/TERRACLIMATE") %>%
ee$ImageCollection$filterDate("2001-01-01", "2002-01-01") %>%
ee$ImageCollection$map(function(x) x$select("pr")) %>% # 这里遍历或者映射都是只选择降水波段就欧克
ee$ImageCollection$toBands() %>% # 将集合转换成影像
ee$Image$rename(sprintf("PP_%02d",1:12)) # 重命名影像波段

 从 Terraclimate ImageCollection 通过 提取月降水值​​ee_extract​​​。​​ee_extract​​​工作原理与 类似​​raster::extract​​,您只需要定义:ImageCollection 对象 (x)、几何图形 (y) 和一个汇总值的函数 (fun)。

#这个雨打功能真的很简单,只需要输入对应的属性x和y就欧克
ee_nc_rain <- ee_extract(x = terraclimate, y = nc["NAME"], sf = FALSE)

 使用ggplot2生成漂亮的静态图!

ee_nc_rain %>%
pivot_longer(-NAME, names_to = "month", values_to = "pr") %>%
mutate(month, month=gsub("PP_", "", month)) %>%
ggplot(aes(x = month, y = pr, group = NAME, color = pr)) +
geom_line(alpha = 0.4) +
xlab("Month") +
ylab("Precipitation (mm)") +
theme_minimal()

 最后结果!Google Earth Engine(GEE)——2.提取降水值案例(R-GEE版)_Rgee


举报

相关推荐

0 条评论