ee_extract: Extract values from EE Images or ImageCollections objects

Description Usage Arguments Details Value Examples

View source: R/ee_extract.R

Description

Extract values from a ee$Image or ImageCollection at the locations of a geometry object. You can use ee$Geometry$*, ee$Feature, ee$FeatureCollection and sf objects. This function try to mimics how extract currently works.

Usage

1
ee_extract(x, y, fun = ee$Reducer$mean(), scale = 1000, sf = FALSE, ...)

Arguments

x

ee$Image or ee$ImageCollection with a single band.

y

ee$Geometry$*, ee$Feature, ee$FeatureCollection or sf objects.

fun

ee$Reducer object. Function to summarize the values. The function should take a single numeric vector as argument and return a single value. See details.

scale

A nominal scale in meters of the Image projection to work in. By default 1000.

sf

Logical. Should the extracted values be added to the data.frame of the sf object y? This only applies if y is a sf object.

...

reduceRegions additional parameters. See ee_help(ee$Image()$reduceRegions) for more details.

Details

In Google Earth Engine the reducer functions that return one value are:

Value

A data.frame or a sf object depending on the sf argument. The columns with the extracted values will get their column name from the image metadata property RGEE_NAME. If is not defined ee_extract will use the band name for ee$Images and the system:index property for ee$ImageCollections.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
## Not run: 
library(rgee)
library(sf)

ee_reattach() # reattach ee as a reserved word
ee_Initialize()

# Define a Image or ImageCollection: Terraclimate
terraclimate <- ee$ImageCollection("IDAHO_EPSCOR/TERRACLIMATE")$
  filterDate("2001-01-01", "2002-01-01")$
  map(function(x){
    date <- ee$Date(x$get("system:time_start"))$format('YYYY_MM_dd')
    name <- ee$String$cat("Terraclimate_pp_", date)
    x$select("pr")$set("RGEE_NAME", name)
  })

# Define a geometry
nc <- st_read(
  dsn = system.file("shape/nc.shp", package = "sf"),
  stringsAsFactors = FALSE,
  quiet = TRUE
)

# Extract values
ee_nc_rain <- ee_extract(
  x = terraclimate,
  y = nc,
  scale = 250,
  fun = ee$Reducer$mean(),
  sf = TRUE
)

# Spatial plot
plot(
  ee_nc_rain["Terraclimate_pp_2001_01_01"],
  main = "2001 Jan Precipitation - Terraclimate",
  reset = FALSE
)

## End(Not run)

ryali93/rgee documentation built on May 13, 2020, 4:34 a.m.