rgee
rgee copied to clipboard
How to make a regular grid to extract information of vegetal index
I want to extract the values of a stack of images with vegetal index (IV) in a regular grid (10m X 10m). I need a data frame with the coorditates, date and values of IV. Can i do that?
The next code that i wrote, i can download a table with only 263 values for diferent images and i cant take all the values for all the images and data for each point (10m X 10m).
library(sf)
library(tidyverse)
library(rgee)
##ee_check()
##_Authenticate(auth_mode = "notebook")
ee_Initialize(drive = T)
archivo <- choose.files(caption = "Seleccione archivo a estandatizar (shp, gpkg)",
multi = FALSE)
file_name <- paste0(tools::file_path_sans_ext(archivo),
'_AMBIENTADO_GCI.',
tools::file_ext(archivo))
roi <- st_read(archivo)%>%
st_geometry()%>%
sf_as_ee()
##grid <- st_make_grid(roi,what = "centers",n = c(20, 20))
##plot(roi)
##plot(grid)
collection_imag<- ee$ImageCollection("COPERNICUS/S2_SR_HARMONIZED")$
filterBounds(roi)$
filter(ee$Filter$lt("CLOUD_COVERAGE_ASSESSMENT", 10))
##func_gci<- this is a function to calculate satellite index
func_gci <-function(image){
gcvi =image$expression(
expression = 'NIR/GREEN-1',
opt_map = list(
'NIR' = image$select('B8'),
'GREEN' = image$select('B3')
)
)
return(image$addBands(image$addBands(gcvi$rename('GCI')))
)
}
collection_gci<- collection_imag$map(func_gci)$
select("GCI")$
map(function(image) {
image$clip(roi)
}
)
resacale_rename<- function(image){
date<- ee$Date(image$get("system:time_start"))$format("%m_%d_%y")
return(image$rename(date))
}
gci_rescaled<- collection_gci$map(resacale_rename)
gci_rescaled$size()$getInfo()
values<- ee_extract(
gci_rescaled,
ee_as_sf(roi),
scale= 10,
sf= F
)