Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gcs_upload - object raster - S4 objects not supported by gcs_upload #161

Open
josemanuelgis opened this issue Jun 8, 2022 · 4 comments
Open

Comments

@josemanuelgis
Copy link

Usecase:
I am trying to save a raster object as a .tif file in gcs, with these lines of code:

f <- function(input, output){
raster::writeRaster(input, filename = output, format="GTiff", overwrite=TRUE)
}

gcs_upload(ndvi, name = "raster.tif", object_function = f, predefinedAcl = "bucketLevel")

Error:

Warning message in class(file) <- c("gcs_cf", class(file)):
“Setting class(x) to multiple strings ("gcs_cf", "RasterBrick", ...); result will no longer be an S4 object”.

@MarkEdmondson1234
Copy link
Collaborator

Hmm the issue here is that I assume the nvdi object is S3 compatible, whereas the raster object is S4. A workaround is to write the object to a file yourself and pass in the file name. A longer term solution is to handle S4 objects in the function.

@MarkEdmondson1234 MarkEdmondson1234 changed the title gcs_upload - object raster gcs_upload - object raster - S4 objects not supported by gcs_upload Jun 8, 2022
@josemanuelgis
Copy link
Author

Thanks for your answer. Could you please specify what you mean when you comment on the function to handle S4 objects.

The lines of code that I have commented have guided me from this issues:

#91

I have a loop that generates RasterLayer objects and I need to save them as "GTiff" format in a bucket

@MarkEdmondson1234
Copy link
Collaborator

If your loop writes to a temporary local file, uploads that filepath via gcs_upload() then deletes the temporary local file it should work.

@josemanuelgis
Copy link
Author

Great thank so much. Your suggestion works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants