Learn R Programming

rgee (version 0.2.0)

ee_upload: Upload sf or stars objects into a GEE asset

Description

Upload images and vectors into Google Earth Engine asset

Usage

ee_upload(x, ...)

# S3 method for character ee_upload(x, ..., filename, bucket = NULL, properties = NULL, start_time = "1970-01-01", end_time = "1970-01-01", selenium_params = getOption("rgee.selenium.params"), clean = FALSE, reinit = FALSE, quiet = FALSE)

# S3 method for sf ee_upload(x, ..., filename, bucket = NULL, selenium_params = getOption("rgee.selenium.params"), clean = FALSE, reinit = FALSE, quiet = FALSE)

# S3 method for stars ee_upload(x, ..., filename, bucket = NULL, properties = NULL, start_time = "1970-01-01", end_time = "1970-01-01", selenium_params = getOption("rgee.selenium.params"), clean = FALSE, reinit = FALSE, quiet = FALSE)

# S3 method for stars_proxy ee_upload(x, ..., filename, bucket = NULL, properties = NULL, start_time = "1970-01-01", end_time = "1970-01-01", selenium_params = getOption("rgee.selenium.params"), clean = FALSE, reinit = FALSE, quiet = FALSE)

Arguments

x

Character, sf or stars object to be uploaded into a GEE asset.

...

ignored

filename

Character. Asset destination path, e.g. users/datacolecfbf/mydatacollection.

bucket

bucketname which you are uploading. See details.

properties

List. Set of parameters to be set up as a property of an EE object. See details.

start_time

Character. Timestamp associated with the asset. The initial time stamp is set up as a nominal image acquisition time for single scenes.

end_time

Character. Useful for assets that correspond to a certain interval of time. The ending time stamp is set up as a nominal image acquisition time for single scenes.

selenium_params

List. Optional parameters when bucket is NULL. For parameters to set selenium. See details.

clean

Logical; If is TRUE the cache is cleaned, see Description.

reinit

Logical; run ee_Initialize(gcs=TRUE) before uploading.

quiet

Logical. Suppress info message.

Details

For uploading process, it is necessary an authorization to read & write into a Google Cloud Storage (GCS) bucket. Earth Engine provides a provisional for free space on GCS through gs://earthengine-uploads/. If the bucket argument is absent, this function will use Selenium driver to get access to the URI mentioned bellow, see ee_upload_file_to_gcs for details. Install and check the Selenium drivers for Google Chrome is possible as follow:

  • rgee::ee_install_drivers()

  • rgee::ee_check_drivers()

The properties argument is just available for image uploaded. If you are interesting to set properties in FeatureCollection. Please use ee_manage_set_properties and then ee_upload.

The selenium_params argument is a three-element list which consists of:

  • gmail_account: Google account. If it is not specified, it will obtained from rgee::ee_user_info().

  • showpassword: Logical. Once google account is filled into getPass, should be shown?.

  • cache: Logical. TRUE will use the cookies stored on the /temp directory.

With respect to the variables time_start and time_end, both needs to be specified as seconds (since the epoch 1970-01-01 00:00:00). Assumed to be in the UTC time zone.

Examples

Run this code
# NOT RUN {
library(rgee)
library(stars)
library(sf)

username <- 'data.colec.fbf' #change according to username.
gcs_bucket <- 'rgee_dev'
ee_check_drivers()

ee_reattach() # reattach ee as a reserved word
ee_Initialize(email = 'data.colec.fbf', gcs = TRUE)

# Create a folder in Earth Engine Asset
filename <- sprintf("users/%s/rgee_upload/", username)
ee_manage_create(filename)

# Select an image to upload
tif = system.file("tif/geomatrix.tif", package = "stars")
geomatrix = read_stars(tif) %>% st_warp(crs=st_crs(4326))

# Uploading to earth egnine
ee_upload(x = geomatrix,
          filename = paste0(filename,"geomatrix"),
          bucket = gcs_bucket)

# Read uploaded image
asset_geomatrix <- paste0(filename,"geomatrix")
ee_geomatrix <- ee$Image(asset_geomatrix)
ee_map(ee_geomatrix, zoom_start = 18)
## OPTIONAL: add properties
ee_manage_set_properties(
  path_asset = asset_geomatrix,
  add_properties = list(message='hello-world',language = 'R'))

# Clean EE asset and GCS
ee_manage_delete(dirname(asset_geomatrix))
googleCloudStorageR::gcs_global_bucket(gcs_bucket)
buckets <- googleCloudStorageR::gcs_list_objects()
mapply(googleCloudStorageR::gcs_delete_object, buckets$name)
# }

Run the code above in your browser using DataLab