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 at the locations of a geometry object. You can use ee$Geometry$*, ee$Feature, ee$FeatureCollection, sf or sfc objects. This function mimicking how extract currently works.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
ee_extract(
  x,
  y,
  fun = ee$Reducer$mean(),
  scale = NULL,
  sf = FALSE,
  via = "getInfo",
  container = "rgee_backup",
  lazy = FALSE,
  quiet = FALSE,
  ...
)

Arguments

x

ee$Image.

y

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

fun

ee$Reducer object. Function to summarize the values. The function must take a single numeric value as an 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 return a sf object?

via

Character. Method to export the image. Three method are implemented: "getInfo", "drive", "gcs".

container

Character. Name of the folder ('drive') or bucket ('gcs') to be exported into (ignore if via is not defined as "drive" or "gcs").

lazy

Logical. If TRUE, a future::sequential object is created to evaluate the task in the future. Ignore if via is set as "getInfo". See details.

quiet

Logical. Suppress info message.

...

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

Details

The reducer functions that return one value are:

Value

A data.frame or an sf object depending on the sf argument. Column names are extracted from band names, use ee$Image$rename to rename the bands of an ee$Image. See ee_help(ee$Image$rename).

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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
## Not run: 
library(rgee)
library(sf)

ee_Initialize(gcs = TRUE, drive = TRUE)

# Define a Image or ImageCollection: Terraclimate
terraclimate <- ee$ImageCollection("IDAHO_EPSCOR/TERRACLIMATE") %>%
 ee$ImageCollection$filterDate("2001-01-01", "2002-01-01") %>%
ee$ImageCollection$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")$rename(name)
   }
 )

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


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

# Extract values - drive (lazy = TRUE)
ee_nc_rain <- ee_extract(
 x = terraclimate,
 y = nc["NAME"],
 scale = 250,
 fun = ee$Reducer$mean(),
 via = "drive",
 lazy = TRUE,
 sf = TRUE
)
ee_nc_rain <- ee_nc_rain %>% ee_utils_future_value()

# Extract values - gcs (lazy = FALSE)
ee_nc_rain <- ee_extract(
 x = terraclimate,
 y = nc["NAME"],
 scale = 250,
 fun = ee$Reducer$mean(),
 via = "gcs",
 container = "rgee_dev",
 sf = TRUE
)

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

## End(Not run)

csaybar/rgee documentation built on March 11, 2021, 5:48 a.m.