-- rgee 1.0.9 --------------------------------------- earthengine-api 0.1.275 -- 
 v email: gflorezc 
 v Google Drive credentials:
 v Google Drive credentials:  FOUND
 v Initializing Google Earth Engine:
 v Initializing Google Earth Engine:  DONE!

 v Earth Engine user: users/gflorezc 
-------------------------------------------------------------------------------- 

Google Earth Engine en RStudio

Column

Map

Column

Mapa de Ubicacion de Yungay

Reading layer `Yungay' from data source `E:\01 Aprende R desde Cero\05 Aprende R desde Cero para SIG (Avanza I)\SHP\Yungay.shp' using driver `ESRI Shapefile'
Simple feature collection with 1 feature and 39 fields
Geometry type: POLYGON
Dimension:     XY
Bounding box:  xmin: -77.78294 ymin: -9.17868 xmax: -77.57379 ymax: -8.993813
Geodetic CRS:  WGS 84

Mapa de NDVI de Yungay

---
title: "Mapa de NDVI de yungay"
author: "Gorky Florez Castillo"
date: "31/7/2021"
output:  
  flexdashboard::flex_dashboard:
    theme: paper
    source_code: embed
---
```{r setup, include=FALSE}
# setting up R Markdown options

# We want to hide the code and only see the results
knitr::opts_chunk$set(echo = F)

# We don't want to see any warnings from our code
knitr::opts_chunk$set(warning = F)

# We don't want to see any messages
knitr::opts_chunk$set(message = F)

```

```{r install_packages}
library(tidyverse)
library(flexdashboard)
library(crosstalk)  
library(leaflet)   
library(DT)
library(leaflet)
library(dplyr)
library(leaflet.extras)
library(htmltools)
library(htmlwidgets)
library(crosstalk)
library(rgdal)
library(openxlsx)
library(png)  
library(broom)
library(tidyverse)
library(leaflet.providers)
library(leafem)
library(sp)
library(sf)#Manejo de informacion espacial
library(mapview)#Para visualizacion de datos espaciales
library(RColorBrewer) #Paleta de Colores
library(viridis)
library(Rgb)
library(ggplot2)#Para distintos graficos incluso mapas
library(raster)#Para leer archivos raster
library(rmarkdown)
library(googledrive)
library(rgee)
library(mapedit)
library(tibble)
library(sf)
library(cptcity)
```

```{r cargar_limpiar_datos}
# Instalar rtools---------------------------------------------------------
# rtools
# Sys.which("make")
# Paquete de rgee
#ee_install()

# Nos pedira si queremos instalar miniconda dareos Y
# Creara un nuevo entorn Python
# Nos pedira reiniciar la consola daremos 1
# Instalar rtools---------------------------------------------------------
# Iniciamos nuestra cuenta de Rgee
ee_Initialize("gflorezc", drive = T)
```


Google Earth Engine en RStudio
===================================== 

Column {data-width=550}
-----------------------------------------------------------------------

### Map

```{r map}
#  https://developers.google.com/earth-engine/datasets/catalog/LANDSAT_LT05_C01_T1_SR

coll <- ee$ImageCollection("LANDSAT/LC08/C01/T1_TOA")$                # Seleccionamos el satelite
           filterDate("2019-04-01", "2020-06-30")$                    # Filtramos por fecha
           filterBounds(ee$Geometry$Point(-76.68, -8.65))$            # Filtramos mediante puntos
           filterMetadata("CLOUD_COVER", "less_than", 10)             # Filtramos por nueves
#ee_get_date_ic(coll)                                                  # Leemos las imagenes disponibles
# Cargamos la imgamen a escojer 
L8   <- 'LANDSAT/LC08/C01/T1_TOA/LC08_008066_20200610'%>%             # Cargamos la imagen a descargar 
           ee$Image() %>%                                             # La naturaleza
           ee$Image$select(c("B6","B5", "B4"))                        # Realizamos una conbinacion de bandas
# Llamamos al objeto creado
Map$centerObject(L8)                                                  # Centramos el mapa para vizualizacion
Map$addLayer(L8)                                                      # Llamamos el objeto 

```

Column {data-width=450}
-----------------------------------------------------------------------

### Mapa de Ubicacion de Yungay

```{r map1}
Yungay<- st_read ("SHP/Yungay.shp")%>%                                # Subimos de nuestro repositorio al shp de yungay
           sf_as_ee()                                                 # Lo convertimos en Sf pero de ee

Map$addLayer(Yungay)                                                  # Vizualizamos yungay
```

### Mapa de NDVI de Yungay

```{r fig.width=8, fig.height=6}
# Realizamos el corte con sus combinaciones 
yun   <- ee$Image('LANDSAT/LC08/C01/T1_TOA/LC08_008066_20200610')$    # Cargamos la imagen a descargar 
         clip(Yungay)%>%                                              # Cortamos la imagen con el sho de yungay
         ee$Image$select(c("B6","B5", "B4"))                          # Realizamos la combinacion de bandas 
# Llamamos al objeto creado
NDVI <- yun$normalizedDifference(c("B5", "B4"))                       # Realizamos el indice de NDVI para yungay

Map$centerObject(NDVI)                                                # Centramos el mapa para vizualizacion
Map$addLayer(eeObject =NDVI, visParams = list(                        # LLamamos a NDVI y ponemos un parametro de colores
  min=0.2,                                                            # Realizamos valores minimos de 0.2
  max=0.8,                                                            # Realizamos valores maximos de 0.8
  palette= cpt("grass_ndvi", 10)))                                    # utilizamos la paleta de colores de grass

```