lundi 20 août 2018

conditional statemets for raster in R

Im trying to calculate Land surface temperature estimating with Landsat 8 images, but i stucked in one place and i cant move on. I m following split window algorithm.
I calculated NDVI but and I have to apply criteria to calculate land surface emmisivity. here my script in R studio :
##Ndvi
NDVI=(Palfa.B5-Palfa.B4)/(Palfa.B4+Palfa.B5)
NDVI <- NDVI@data@values
#vegetation fraction
NDVImin=0.2 #pre set value
NDVImax=0.5 #pre set value
Pv <- ((NDVI-NDVImin)/(NDVImax-NDVImin))^2
#roughness of the surface
F=0.55 #pre set value of geometric factor
C10 <- (1-es10) * ev10 * (1-Pv) * F
C11 <- (1-es11) * ev11 * (1-Pv) * F
#LSE for band 10
e10 <- if (NDVI<=0.2) {
-0.047 * Palfa.B4+0.973
} else if (NDVI>0.2 && NDVI<=0.5) {
ev10 * Pv+es10 * (1-Pv)+C10
} else (NDVI>0.5)
ev10+C10
#LSE for band 11
e11 <- if (NDVI<=0.2) {
-0.026 * Palfa.B5+0.984
} else if (NDVI>0.2 && NDVI<=0.5) {
ev11 * Pv+es11 * (1-Pv)+C11
} else (NDVI>0.5)
ev11+C11
something is wrong but i got this :
Warning message:
In if (NDVI <= 0.2) { :
the condition has length > 1 and only the first element will be used ev11+C11
I also tried with ifelse but then my result is vector but i need to export raster
have u got any ideas how can i solve it?
Attched you will find criteria : enter image description here

Aucun commentaire:

Enregistrer un commentaire