R/ee_download.R
ee_download_drive.RdMove results of an EE task saved in Google Drive to Hard disk.
ee_download_drive(task, filename, overwrite = FALSE, st = TRUE, quiet = TRUE)
| task | List generated after finished correctly a EE task. See details. |
|---|---|
| filename | Character. Output filename. If absent, a temporary file is created. |
| overwrite | A boolean indicating whether "filename" should be overwritten if it exists. |
| st | logical. By default this is TRUE, returning a sf (stars) object for EE tables (images). If FALSE, the output filename is returned. |
| quiet | logical. Suppress info message |
An sf, stars or character depending on the retunclass argument.
The task argument needs "COMPLETED" task state to work, since the parameters necessaries to locate the file into google drive are obtained from ee$batch$Export$*$toDrive(...)$start()$status().
if (FALSE) { library(rgee) library(stars) library(sf) ee_Initialize() # Example 1 -- Download a Image # Communal Reserve Amarakaeri - Peru xmin <- -71.132591318 xmax <- -70.953664315 ymin <- -12.892451233 ymax <- -12.731116372 ROI <- c(xmin, ymin, xmax, ymin, xmax, ymax, xmin, ymax, xmin, ymin) ROI_polygon <- matrix(ROI, ncol = 2, byrow = TRUE) %>% list() %>% st_polygon() %>% st_sfc() %>% st_set_crs(4326) ee_geom <- sf_as_ee(ROI_polygon) # Get the mean annual NDVI for 2011 cloudMaskL457 <- function(image) { qa <- image$select("pixel_qa") cloud <- qa$bitwiseAnd(32L)$ And(qa$bitwiseAnd(128L))$ Or(qa$bitwiseAnd(8L)) mask2 <- image$mask()$reduce(ee$Reducer$min()) image <- image$updateMask(cloud$Not())$updateMask(mask2) image$normalizedDifference(list("B4", "B3")) } ic_l5 <- ee$ImageCollection("LANDSAT/LT05/C01/T1_SR")$ filterBounds(ee_geom)$ filterDate("2011-01-01", "2011-12-31")$ map(cloudMaskL457) mean_l5 <- ic_l5$mean()$rename("NDVI") mean_l5 <- mean_l5$reproject(crs = "EPSG:4326", scale = 500) mean_l5_Amarakaeri <- mean_l5$clip(ee_geom) task_img <- ee$batch$Export$image$toDrive( image = mean_l5_Amarakaeri, folder = "Amarakaeri", fileFormat = "GEOTIFF", fileNamePrefix = "my_image" ) task_img$start() ee_monitoring(task_img) img <- ee_download_drive(task_img) plot(img) # Example 2 -- Download a Table amk_fc <- ee$FeatureCollection(list(ee$Feature(ee_geom, list(name = "Amarakaeri")))) task_vector <- ee$batch$Export$table$toDrive( collection = amk_fc, folder = "Amarakaeri", fileFormat = "GEOJSON", fileNamePrefix = "geom_Amarakaeri" ) task_vector$start() ee_monitoring(task_vector) # optional amk_geom <- ee_download_drive(task = task_vector) plot(amk_geom$geometry, border = "red", lwd = 10) }