Wrapper function around ee$Image$getThumbURL to create a stars or RasterLayer R object from a EE thumbnail image.

ee_as_thumbnail(
  image,
  region,
  dimensions,
  vizparams = NULL,
  raster = FALSE,
  quiet = FALSE
)

Arguments

image

EE Image object to be converted into a stars object.

region

EE Geometry Rectangle (ee$Geometry$Rectangle) specifies the region to be exported. The CRS must match the 'x' argument; otherwise, it will be forced.

dimensions

Numeric vector of length 2 that specifies the dimensions of the thumbnail image in pixels. If only one integer is provided, it determines the size of the larger dimension of the image and scales the other dimension proportionally. Defaults to 512 pixels for the larger image aspect dimension.

vizparams

A list containing the visualization parameters.See details.

raster

Logical. Should the thumbnail image be saved as a RasterStack object?

quiet

logical; suppress info messages.

Value

An stars or Raster object depending on the raster argument.

Details

vizparams set up the details of the thumbnail image. With ee_as_thumbnail allows exporting only one-band (G) or three-band (RGB) images. Several parameters can be passed on to control color, intensity, the maximum and minimum values, etc. The table below provides all the parameters that admit ee_as_thumbnail.

ParameterDescriptionType
bandsComma-delimited list of three band (RGB)list
minValue(s) to map to 0number or list of three numbers, one for each band
maxValue(s) to map to 1number or list of three numbers, one for each band
gainValue(s) by which to multiply each pixel valuenumber or list of three numbers, one for each band
biasValue(s) to add to each Digital Number valuenumber or list of three numbers, one for each band
gammaGamma correction factor(s)number or list of three numbers, one for each band
paletteList of CSS-style color strings (single-band only)comma-separated list of hex strings
opacityThe opacity of the layer (from 0 to 1)number

See also

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

Examples

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

ee_Initialize()

nc <- st_read(system.file("shp/arequipa.shp", package = "rgee"))
dem_palette <- c(
  "#008435", "#1CAC17", "#48D00C", "#B3E34B", "#F4E467",
  "#F4C84E", "#D59F3C", "#A36D2D", "#C6A889", "#FFFFFF"
)

## DEM data -SRTM v4.0
image <- ee$Image("CGIAR/SRTM90_V4")
world_region <- ee$Geometry$Rectangle(
  coords = c(-180,-60,180,60),
  proj = "EPSG:4326",
  geodesic = FALSE
)

## world - elevation
world_dem <- ee_as_thumbnail(
  image = image,
  region = world_region,
  dimensions = 1024,
  vizparams = list(min = 0, max = 5000)
)

world_dem[world_dem <= 0] <- NA
world_dem <- world_dem * 5000

plot(
  x = world_dem, col = dem_palette, breaks = "equal",
  reset = FALSE, main = "SRTM - World"
)

## Arequipa-Peru
arequipa_region <- nc %>%
  st_bbox() %>%
  st_as_sfc() %>%
  sf_as_ee()

arequipa_dem <- ee_as_thumbnail(
  image = image,
  region = arequipa_region$buffer(1000)$bounds(),
  dimensions = 512,
  vizparams = list(min = 0, max = 5000)
)

arequipa_dem <- arequipa_dem * 5000
st_crs(arequipa_dem) <- 4326
plot(
  x = arequipa_dem[nc], col = dem_palette, breaks = "equal",
  reset = FALSE, main = "SRTM - Arequipa"
)

suppressWarnings(plot(
  x = nc, col = NA, border = "black", add = TRUE,
  lwd = 1.5
))
dev.off()

## LANDSAT 8
img <- ee$Image("LANDSAT/LC08/C01/T1_SR/LC08_038029_20180810")$
  select(c("B4", "B3", "B2"))
Map$centerObject(img)
Map$addLayer(img, list(min = 0, max = 5000, gamma = 1.5))

## Teton Wilderness
l8_img <- ee_as_thumbnail(
  image = img,
  region = img$geometry()$bounds(),
  dimensions = 1024,
  vizparams = list(min = 0, max = 5000, gamma = 1.5),
  raster = TRUE
)
crs(l8_img) <- "+proj=longlat +datum=WGS84 +no_defs"
plotRGB(l8_img, stretch = "lin")
} # }