问题描述
我正在尝试将一些大型几何图形上传到谷歌地球引擎。
这是 ?sf_as_ee
描述中给出的示例代码:
# # 3. Upload large geometries to EE asset
# ee_Initialize(gcs = TRUE)
# assetId <- sprintf("%s/%s",ee_get_assethome(),'toy_poly_gcs')
# eex <- sf_as_ee(
# x = toy_poly,# overwrite = TRUE,# assetId = assetId,# bucket = 'rgee_dev',# monitoring = FALSE,# via = 'gcs_to_asset'
# )
我只需要知道如何设置 bucket
?
来自描述:
桶 - 字符。用于保存中间文件的存储桶 (GCS) 的名称(如果 via 未定义为“gcs_to_asset”,则忽略)。
我认为它是用于保存中间文件的本地空间,但我无法让它与我通常用于临时文件的文件夹 (bucket = 'tempfiles'
) 一起使用。
它在我的工作目录中,但抛出此错误:
Error in value[[3L]](cond) : The data bucket was not found.
参考文件结构:(在 MacOS 上)
-R 项目(工作目录)
-- 脚本
--- 脚本
--临时文件
我尝试将其设置为谷歌驱动器文件夹名称,并认为它可能会要求这样做,但它也不起作用。任何帮助将不胜感激!
谢谢!
解决方法
sf_as_ee(...,via = "gcs_to_asset") 是一个两步函数。首先,几何被上传到 Google Cloud Storage (GCS),然后使用 manifests upload 从 GCS 移动到 Earth Engine。
使用 sf_as_ee(...,via = "gcs_to_asset") 是保存具有写入/读取 GCS 资源权限的 service account key (SAK) 所必需的。 无法通过 Google 云端硬盘上传文件。
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
这个guide解释了如何生成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.