Learn R Programming

rgee (version 1.0.5)

ee_as_stars: Convert an Earth Engine (EE) image into a stars object

Description

Convert an ee$Image into a stars object

Usage

ee_as_stars(
  image,
  region = NULL,
  dsn = NULL,
  via = "drive",
  scale = NULL,
  maxPixels = 1e+09,
  container = "rgee_backup",
  quiet = FALSE,
  ...
)

Arguments

image

ee$Image to be converted into a stars object

region

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

dsn

Character. Output filename. If missing, ee_as_stars will create a temporary file.

via

Character. Method to fetch data about the object. Two methods are implemented: "drive", "gcs". See details.

scale

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

maxPixels

Numeric. The maximum allowed number of pixels in the exported image. The task will fail if the exported region covers more pixels in the specified projection. Defaults to 100,000,000.

container

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

quiet

Logical. Suppress info message

...

Extra exporting argument. See ee_image_to_drive and ee_image_to_gcs.

Value

A stars-proxy object

Details

ee_as_stars supports the download of ee$Image by two different options: "drive" that use Google Drive and "gcs" that use Google Cloud Storage. Previously, it is necessary to install the R packages googledrive or googleCloudStorageR respectively. 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_thumbnail(), ee_imagecollection_to_local()

Examples

Run this code
# NOT RUN {
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
)

## drive - Method 01
img_02 <- ee_as_stars(
  image = img,
  region = geometry,
  via = "drive"
)

## gcs - Method 02
# img_03 <- ee_as_stars(
#   image = img,
#  region = geometry,
#   container = "rgee_dev",
#  via = "gcs"
#)

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

Run the code above in your browser using DataLab