Skip to contents

Install R packages

pkgs_cran <- c("rgee", "reticulate")
pkgs_runiverse <- "kwb.python"
pkgs <- c(pkgs_cran, pkgs_runiverse)
install.packages(pkgs, repos = c("https://cloud.r-project.org",
                                 "https://kwb-r.r-universe.dev"))


### Downgrade to last one supplied by R package "rgee"
kwb.python::conda_py_install("ad4gd", pkgs = list(conda = c("python=3.12.2",
                                                            "numpy"),
                                                  py = "earthengine-api==0.1.370"))

Use

reticulate::use_condaenv("ad4gd")


library(rgee)

rgee::ee_Initialize()

createTimeBand <-function(img) {
  year <- ee$Date(img$get('system:time_start'))$get('year')$subtract(1991L)
  ee$Image(year)$byte()$addBands(img)
}

img <- ee$ImageCollection('COPERNICUS/S2_SR_HARMONIZED')$
  filterBounds(ee$Geometry$Point(52, 12))$
  select('B2')$
  first()


vizParams <- list(
  bands = 'B2',
  min = 0,
  max = 0.0000005,
  gamma = 0.01
)

Map$setCenter(117, 40, 10)

# You can see it
m1 <- Map$addLayer(img, vizParams, 'first')
m1