r-spatial / rgee

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

How display imageCollection one to one in the map view #172

Closed luisdiazc closed 3 years ago

luisdiazc commented 3 years ago

I have consulted a collection of Sentinel 1 images for a specific ROI and a given time window. I want to visualize these one by one in the map view. I would appreciate some help on this as I am totally new to using rgee.

# Librerias 

library(rgee)
library(googledrive)
library(reticulate)
library(raster)
library(sf)
library(mapedit)
library(mapview)
library(tidyverse)

ee_Initialize(email = "cienciacondatoss", drive = TRUE)
ee_users()

RR <- read_sf("F:/INESAG/Propuestas de extensión/SIG con R - Basico/Datos/shp/Cuenca_rio_Rancheria.shp") %>% 
  sf_as_ee()

S1RRVV <- ee$ImageCollection('COPERNICUS/S1_GRD')$
  filterBounds(RR)$
  filter(ee$Filter$eq('instrumentMode', 'IW'))$
  filter(ee$Filter$eq('orbitProperties_pass', 'ASCENDING'))$
  filterMetadata('resolution_meters', 'equals', 10)$ 
  filterDate('2021-07-01', '2021-07-22')$
  select('VV')

ee_print(S1RRVV)

S1RRVH <- ee$ImageCollection('COPERNICUS/S1_GRD')$
  filterBounds(RR)$
  filter(ee$Filter$eq('instrumentMode', 'IW'))$
  filter(ee$Filter$eq('orbitProperties_pass', 'ASCENDING'))$
  filterMetadata('resolution_meters', 'equals', 10)$ 
  filterDate('2021-07-01', '2021-07-22')$
  select('VH')

ee_print(S1RRVV)
ee_print(S1RRVH)
ambarja commented 3 years ago

Hi @luisdiazc thanks for open this issue, for visualization multiple layers with rgee is using the Map$addLayers() function, however, is necessary to install rgeeExtra. Here you can check more documentation :next_track_button: more info

luisdiazc commented 3 years ago

Hi @ambarja, How can I access the names of the images (layers) within a imageColeection. Thank you, very much!

ambarja commented 3 years ago

You can access to band names using the next code.

> S1RRVH$toBands()$bandNames()$getInfo()
[1] "S1B_IW_GRDH_1SDV_20210704T230850_20210704T230915_027650_034CD6_4D62_VH"
[2] "S1B_IW_GRDH_1SDV_20210716T230851_20210716T230916_027825_035204_8D8C_VH"
luisdiazc commented 3 years ago

Great!

I triying use addLayers function for display a imageCollection, but jump the next error:

Map$centerObject(eeObject = RR, zoom = 9)
Map$addLayers(eeObject = RRS1RRVV)
Error: tentativa de aplicar una no-función

I installed the rgeeExtra package using remotes::install_github("r-earthengine/rgeeExtra") and load with library(rgeeExtra).

Than you for you answers!

ambarja commented 3 years ago

@luisdiazc here a reproducible example :arrow_down:

# Librerias 
library(rgee)
library(rgeeExtra)
library(raster)
library(sf)
library(mapedit)
library(tidyverse)

ee_Initialize()

RR <- ee$Geometry$
  Polygon(
    list(
      -70.05, -13.04,-69.93, -13.04,
      -69.93, -12.90,-70.05, -12.90,
      -70.05, -13.04
      )
    )

S1RRVV <- ee$ImageCollection('COPERNICUS/S1_GRD')$
  filterBounds(RR)$
  filter(ee$Filter$eq('instrumentMode', 'IW'))$
  filter(ee$Filter$eq('orbitProperties_pass', 'ASCENDING'))$
  filterMetadata('resolution_meters', 'equals', 10)$ 
  filterDate('2021-07-01', '2021-07-22')$
  select('VV')

Map$centerObject(eeObject = RR,zoom = 8)
Map$addLayers(eeObject = S1RRVV,visParams = list(min=-25,max=5))

Captura de pantalla de 2021-07-24 09-55-38

luisdiazc commented 3 years ago

@ambarja , I think that my problem is that R is not recognizing the Map $ addLayers method, therefore the error that I indicated before jumps🤔

Also, the comparison between layers with the operator | does not work. I think that rgeeExtra is bad installed.

ambarja commented 3 years ago

Hi @luisdiazc you can update your rgee package with the dependencies and after to use the last code. If you have the same problem Would you mind attached us your sessionInfo?

sessionInfo()
luisdiazc commented 3 years ago

Hi @ambarja , i managed to do it. Thank you very much for you suport. I consider this issue closed. Good bye🥳