-
Notifications
You must be signed in to change notification settings - Fork 0
/
pensez_spatial.R
55 lines (33 loc) · 1.11 KB
/
pensez_spatial.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
library(raster)
library(magrittr)
library(here)
library(dplyr)
## raster
base.rast <- list.files(here("data/landsat/nord"),
pattern = ".TIF$",
full.names = T) %>%
grep("B2|B3|B4|B5",., value = T)
ras.brut.ras <- stack(base.rast)
rasterOptions(maxmemory=5e+06) # pour forcer le raster sur disque
pryr::mem_change({
NDVI <- (ras.brut.ras[[3]] - ras.brut.ras[[2]]) / (ras.brut.ras[[3]] + ras.brut.ras[[2]])
#rs4 <- calc(ras.brut.ras, fun=function(x){(x[3]-x[4])/(x[3]+x[4])})
#summary(NDVI)
clas_mat <- cbind(from = seq(-1, 0.8, .2),
to = seq(-0.8, 1, .2),
become = 1:10)
cla_NDVI <- reclassify(NDVI, clas_mat)
})
plot(cla_NDVI, main = "raster")
## DF
pryr::mem_change({
df_ras <- values(ras.brut.ras[[2:3]]) %>%
as.data.frame() %>%
setNames(c("B3", "B4"))
df_NDVI <- mutate(df_ras, ndvi = (B4-B3)/(B4+B3))
df_cla_NDVI <- mutate(df_NDVI, cla = cut(ndvi, seq(-1,1,0.2)),
cla = as.numeric(cla))
})
cla_NDVI_dplyr <- NDVI
values(cla_NDVI_dplyr) <- df_cla_NDVI$cla
plot(cla_NDVI_dplyr, main = "dplyr")