r-spatial / rgee

Google Earth Engine for R
https://r-spatial.github.io/rgee/
Other
677 stars 146 forks source link

RGB loadGeoTIFF in GCP Storage #184

Closed Tartomas closed 3 years ago

Tartomas commented 3 years ago

Description

Hello Cesar, gracias por tu aporte a la comunidad de GEE en R, realmente has hecho un tremendo trabajo y no cabe duda que seguiras aportando por muchos años más !

Issue or question

I'm trying to get a Sentinel RGB image that I have exported previously into GoogleStorage as RGB.tif. It's an options? or this functions is only for single band calling?

When I try to use loadGeoTIFF function to grab it, it's appear that only get one band.

  uriRGB = paste0("gs://bucket/RGB/RGB_S2SR_T18GXA_2021-08-31_mask.tif")
  imageRGB <- ee$Image$loadGeoTIFF(uri)

> print(imageRGB$bandNames()$getInfo())
[1] "B0"
> print(imageRGB$bandTypes()$getInfo())
$B0
$B0$type
[1] "PixelType"

$B0$precision
[1] "double"
  print(imageRGB$bandTypes()$getInfo())

When I use raster package and "vsicurl" I'm able to grab it, like:

   rst = raster::brick(paste0("/vsicurl/", res_file$link)) 

When I download from bucket and drag it to QGIS I can see this image

Thanks you very much !

csaybar commented 3 years ago

Hola @Tartomas muchas gracias por tus palabras :D! . Can u give me access to read your bucket? csaybar@gmail.com Thanks!

Tartomas commented 3 years ago

Hi @csaybar I make public this file access to the tif. and also make you Storage Object viewer Let me know if you are able to go through this issue.

What I'm really into is to use ee$Image$loadGeoTIFF(uri) to rendered in leaflet with addTiles()

# rgee Map$addLayer
uri = paste0("gs://rgee-test/raster_NDVI_S2SR_T18GXA_",last_date,"_mask.tif")
imageas <- ee$Image$loadGeoTIFF(uri)
# This work properly
Map$centerObject(imageas, zoom = 15)
palette <- c("FF0000", "00FF00", "0000FF")
vizParams <- list(min = 0, max = 1, palette = palette)
Map$addLayer(imageas, vizParams, "Landsat NDVI")

# This doesn't work
leaflet() %>% 
  addTiles() %>% 
  setView(-72.99389,-40.39703, 12) %>% 
  addTiles(
    urlTemplate = imageas$rgee$tokens,
    layerId = "leaflet_false_color",
    options = leaflet::tileOptions(opacity = 1)
  )

Error in py_get_attr_impl(x, name, silent) : 
  AttributeError: 'Image' object has no attribute 'rgee'

Tell me what you think Thanks !

csaybar commented 3 years ago

Hi @Tartomas the problem is that their resource is not a COG (https://www.cogeo.org/).

library(httr)

resource  <- "gs://rgee-test/raster_NDVI_S2SR_T18GXA_2021-08-31_mask.tif"
titiler_server_service <- "https://api.cogeo.xyz//cog/tilejson.json"

response <- httr::GET(
  url = titiler_server_service,
  config = httr::accept_json(),
  query = list(
    "url" = resource
  )
)

response$status_code
# 500 Internal Server Error

You can use GDAL > 3.1 to convert it running:

gdalwarp src1.tif src2.tif out.tif -of COG
Tartomas commented 3 years ago

Hi Cesar Thanks you very much, I was able to load RGB from a bucket as a COG files. Best, thank again !