sf_as_ee(..., via = "gcs_to_asset")是一个两步函数。首先,将几何图形上传到 Google Cloud Storage (GCS),然后使用清单上传从 GCS 移动到 Earth Engine。
要使用sf_as_ee(..., via = "gcs_to_asset")必须保存具有写入/读取 GCS 资源权限的服务帐户密钥(SAK)。无法通过 Google Drive 上传文件。
library(rgee)
library(googleCloudStorageR)
ee_Initialize("csaybar", gcs = TRUE)
#> ── rgee 1.0.7 ─────────────────────────────────────── earthengine-api 0.1.245 ──
#> ✓ email: csaybar
#> ✓ GCS credentials: NOT FOUND
#> ✓ Initializing Google Earth Engine: DONE!
#> ✓ Earth Engine user: users/csaybar
#> ────────────────────────────────────────────────────────────────────────────────
#> Unable to find a service account key (SAK) file in: /home/csaybar/.config/earthengine//csaybar
#> Please, download and save the key manually on the path mentioned
#> before. A compressible tutorial to obtain their SAK file is available in:
#> > https://github.com/r-spatial/rgee/tree/help/gcs
#> > https://cloud.google.com/iam/docs/creating-managing-service-account-keys
#> > https://console.cloud.google.com/apis/credentials/serviceaccountkey
#> Until you do not save a SKA file, the following functions will not work:
#> - rgee::ee_gcs_to_local()
#> - ee_as_raster(..., via = "gcs")
#> - ee_as_stars(..., via = "gcs")
#> - ee_as_sf(..., via = "gcs")
#> - sf_as_ee(..., via = "gcs_to_asset")
#> - gcs_to_ee_image
#> - raster_as_ee
#> - local_to_gcs
#> - stars_as_ee
本指南说明了如何生成 SAK,然后,您需要将其保存在:
rgee::ee_get_earthengine_path()
#> [1] "/home/csaybar/.config/earthengine//csaybar/"
出现此特定错误 ( Error in value[[3L]](cond): The data bucket was not found.
) 是因为googleCloudStorageR无法识别您的 SAK(因此无法识别您的 GCS 存储桶名称)。
library(googleCloudStorageR)
gcs_get_bucket('rgee_dev') # I have privileges to modify the bucket (rgee will work!)
#> ==Google Cloud Storage Bucket==
#> Bucket: rgee_dev
#> Project Number: XXXXXXXXXXXXXX
#> Location: US
#> Class: STANDARD
#> Created: 2020-02-08 01:00:23
#> Updated: 2020-12-10 15:00:47
#> Meta-generation: 8
#> eTag: XXX
gcs_get_bucket('tempfiles') # I do not have privileges privileges to modify the bucket (rgee will not work!)
#> ℹ 2020-12-23 16:16:22 > Request Status Code: 403
#> Error: API returned: gcs-auth-file@rgee-267600.iam.gserviceaccount.com does not
#> have storage.buckets.get access to the Google Cloud Storage bucket.