rgee + rgeeExtra

In this post, you going to learn how to integrate rgeeExtra with rgee. The philosophy of rgeeExtra is to make availablea functional programming type, more friendly with R users, also rgee extends the following Earth Engine classes:

  • ee.Feature
  • ee.FeatureCollection
  • ee.Geometry
  • ee.Image
  • ee.ImageCollection

In this we will calculate the Normalized Difference Vegetation Index, (NDVI) from a Landsat 8 image.


Information:

  • rgeeExtra due is official in CRAN, but you can install using the remote package.
  • For this section is neccesary to hace install rgee, rgeeExtra,sf ,cptcity and tidyverse

1. Requeriments

1remotes::install_github("r-earthengine/rgeeExtra")
2library(tidyverse)
3library(rgee)
4library(rgeeExtra)
5library(sf)
6library(cptcity)
7ee_Initialize()
1> ee_Initialize()
2── rgee 1.1.2 ──────────────────── earthengine-api 0.1.292 ──
3 ✓ user: not_defined
4 ✓ Initializing Google Earth Engine:  DONE!
5 ✓ Earth Engine account: users/ambarja
6─────────────────────────────────────────────────────────────

2. Vector layer reading of our study area

1hcyo <- st_read(
2  "https://github.com/ambarja/gpkg-pe/raw/main/prov_huancayo.gpkg",
3  quiet = TRUE) %>%
4  summarise()

3. Cooking with dataset with rgee

1landsat <-ee$ImageCollection("LANDSAT/LC08/C02/T1_TOA")$
2  select(sprintf("B%s",c(1:7)))$
3  filterDate("2021-01-01","2021-12-31")$
4  filterBounds(hcyo_ee)$
5  filterMetadata("CLOUD_COVER","less_than",30)$
6  first()$
7  clip(hcyo_ee)

4. Calculate of NDVI index with rgee

1ndvi <- landsat$
2  normalizedDifference(c("B5", "B4"))

5. Indentifying min and max value of index

1(minmax <- ndvi$reduceRegion(
2  reducer = ee$Reducer$minMax(),
3  geometry = hcyo_ee,
4  scale = 1000)$
5    getInfo()
6    )
1$nd_max
2[1] 0.7902563
3$nd_min
4[1] -0.07480448
6. Parameter of visualization
1viz <- list(
2  min = -0.08,
3  max = 0.63,
4  palette = cpt("grass_ndvi")
5)
6Map$centerObject(ndvi,zoom=9)
7. NDVI map wih rgee
1m1 <- Map$addLayer(ndvi,visParams = viz) +
2  Map$addLegend(visParams = viz,name = "ndvi")
8. Calculate of NDVI index with rgeeExtra
1ndvi <- (landsat[["B5"]] - landsat[["B4"]])/(landsat[["B5"]] + landsat[["B4"]])
9. NDVI map wih rgeeExtra
1m2 <- Map$addLayer(ndvi,visParams = viz) +
2  Map$addLegend(visParams = viz,name = "ndvi_ee")

10. Two map in only display

1m1 | m2