Convert an ee$Image in a SpatRaster object

ee_as_rast(
  image,
  region = NULL,
  dsn = NULL,
  via = "drive",
  container = "rgee_backup",
  scale = NULL,
  maxPixels = 1e+09,
  grid_batch = 1024 * 1024,
  lazy = FALSE,
  public = FALSE,
  add_metadata = TRUE,
  timePrefix = TRUE,
  quiet = FALSE,
  ...
)

Arguments

image

ee$Image to be converted into a SpatRaster object.

region

EE Geometry (ee$Geometry$Polygon) which specifies the region to export. CRS needs to be the same that the argument image. Otherwise, it will be forced. If not specified, image bounds are taken.

dsn

Character. Output filename. If missing, a temporary file is created.

via

Character. Method to export the image. Three methods are implemented: "getDownloadURL", "drive", "gcs". For "drive" and "gcs" see details. Use "getDownloadURL" for small images.

container

Character. Name of the folder ('drive') or bucket ('gcs') to be exported.

scale

Numeric. The resolution in meters per pixel. Defaults to the native resolution of the image.

maxPixels

Numeric. The maximum allowable number of pixels in the exported image. If the exported region covers more pixels than the specified limit in the given projection, the task will fail. Defaults to 100,000,000.

grid_batch

Numeric. Argument used if via is set as "getDownloadURL". The number of pixels to download in each batch without considering the number of bands. Default to 1048576 -(1024*1024).

lazy

Logical. If TRUE, a future::sequential object is created to evaluate the task in the future. See details.

public

Logical. If TRUE, a public link to the image is created.

add_metadata

Add metadata to the stars_proxy object. See details.

timePrefix

Logical. Add current date and time (Sys.time()) as a prefix to files to export. This parameter helps to avoid exported files with the same name. By default TRUE.

quiet

Logical. Suppress info message

...

Extra exporting argument. See ee_image_to_drive and ee_image_to_gcs.

Value

A SpatRaster object

Details

ee_as_rast supports the download of ee$Images using: "drive" (Google Drive) and "gcs" ( Google Cloud Storage). In both cases, ee_as_rast performs as follows:

  • 1. A task is started (i.e., ee$batch$Task$start()) to move the ee$Image from Earth Engine to the intermediate container specified in the argument via.

  • 2. If the argument lazy is TRUE, the task is not be monitored. This is useful to lunch several tasks simultaneously and calls them later using ee_utils_future_value or future::value. At the end of this step, the ee$Image is stored on the path specified in the argument dsn.

  • 3. Finally, if the argument add_metadata is TRUE, a list with the following elements are added to the stars-proxy object.

    • if via is "drive":

      • ee_id: Name of the Earth Engine task.

      • drive_name: Name of the Image in Google Drive.

      • drive_id: Id of the Image in Google Drive.

      • drive_download_link: Download link to the image.

    • if via is "gcs":

      • ee_id: Name of the Earth Engine task.

      • gcs_name: Name of the Image in Google Cloud Storage.

      • gcs_bucket: Name of the bucket.

      • gcs_fileFormat: Format of the image.

      • gcs_public_link: Download link to the image.

      • gcs_URI: gs:// link to the image.

    Run attr(stars, "metadata") to get the list.

For getting more information about exporting data from Earth Engine, take a look at the Google Earth Engine Guide - Export data.

See also

Other image download functions: ee_as_raster(), ee_as_stars(), ee_as_thumbnail(), ee_imagecollection_to_local()

Examples

if (FALSE) { # \dontrun{
library(rgee)

ee_Initialize(drive = TRUE, gcs = TRUE)
ee_user_info()

# Define an image.
img <- ee$Image("LANDSAT/LC08/C01/T1_SR/LC08_038029_20180810")$
  select(c("B4", "B3", "B2"))$
  divide(10000)

# OPTIONAL display it using Map
Map$centerObject(eeObject = img)
Map$addLayer(eeObject = img, visParams = list(max = 0.4,gamma=0.1))

# Define an area of interest.
geometry <- ee$Geometry$Rectangle(
  coords = c(-110.8, 44.6, -110.6, 44.7),
  proj = "EPSG:4326",
  geodesic = FALSE
)

## getDownloadURL - Method 01 (for small images)
img_02 <- ee_as_stars(
  image = img,
  region = geometry,
  scale = 10
)

## drive - Method 02
# Simple
img_02 <- ee_as_rast(
  image = img,
  region = geometry,
  via = "drive"
)

# Lazy
img_02 <- ee_as_rast(
  image = img,
  region = geometry,
  via = "drive",
  lazy = TRUE
)

img_02_result <- img_02 %>% ee_utils_future_value()
attr(img_02_result, "metadata") # metadata

## gcs - Method 03
# Simple
img_03 <- ee_as_rast(
 image = img,
 region = geometry,
 container = "rgee_dev",
 via = "gcs"
)

# Lazy
img_03 <- ee_as_rast(
 image = img,
 region = geometry,
 container = "rgee_dev",
 lazy = TRUE,
 via = "gcs"
)

img_03_result <- img_03 %>% ee_utils_future_value()
attr(img_03_result, "metadata") # metadata

# OPTIONAL: clean containers
# ee_clean_container(name = "rgee_backup", type = "drive")
# ee_clean_container(name = "rgee_dev", type = "gcs")
} # }