Operaciones, consultas
# imporar libreria
require(raster)
## Loading required package: raster
## Loading required package: sp
library(readr)
# Temprattura promedio
img_temp=list.files("D:/ESPECIALIZACION/SEMESTRE 1/1. Tratamiento de datos/Clase 5 Raster/Img_col_temp/", full.names = TRUE)
print(img_temp) # solo es una lista
## [1] "D:/ESPECIALIZACION/SEMESTRE 1/1. Tratamiento de datos/Clase 5 Raster/Img_col_temp/wc2.1_10m_colom_01.tif"
## [2] "D:/ESPECIALIZACION/SEMESTRE 1/1. Tratamiento de datos/Clase 5 Raster/Img_col_temp/wc2.1_10m_colom_02.tif"
## [3] "D:/ESPECIALIZACION/SEMESTRE 1/1. Tratamiento de datos/Clase 5 Raster/Img_col_temp/wc2.1_10m_colom_03.tif"
## [4] "D:/ESPECIALIZACION/SEMESTRE 1/1. Tratamiento de datos/Clase 5 Raster/Img_col_temp/wc2.1_10m_colom_04.tif"
## [5] "D:/ESPECIALIZACION/SEMESTRE 1/1. Tratamiento de datos/Clase 5 Raster/Img_col_temp/wc2.1_10m_colom_05.tif"
## [6] "D:/ESPECIALIZACION/SEMESTRE 1/1. Tratamiento de datos/Clase 5 Raster/Img_col_temp/wc2.1_10m_colom_06.tif"
## [7] "D:/ESPECIALIZACION/SEMESTRE 1/1. Tratamiento de datos/Clase 5 Raster/Img_col_temp/wc2.1_10m_colom_07.tif"
## [8] "D:/ESPECIALIZACION/SEMESTRE 1/1. Tratamiento de datos/Clase 5 Raster/Img_col_temp/wc2.1_10m_colom_08.tif"
## [9] "D:/ESPECIALIZACION/SEMESTRE 1/1. Tratamiento de datos/Clase 5 Raster/Img_col_temp/wc2.1_10m_colom_09.tif"
## [10] "D:/ESPECIALIZACION/SEMESTRE 1/1. Tratamiento de datos/Clase 5 Raster/Img_col_temp/wc2.1_10m_colom_10.tif"
## [11] "D:/ESPECIALIZACION/SEMESTRE 1/1. Tratamiento de datos/Clase 5 Raster/Img_col_temp/wc2.1_10m_colom_11.tif"
## [12] "D:/ESPECIALIZACION/SEMESTRE 1/1. Tratamiento de datos/Clase 5 Raster/Img_col_temp/wc2.1_10m_colom_12.tif"
temp_anual=stack(img_temp) # crea varios raster
names(temp_anual)=month.name
plot(temp_anual)

promedio_temp = mean(temp_anual) # saca raster de la temp promedio
plot(promedio_temp)

# Precipitacion anual
img_precip=list.files("D:/ESPECIALIZACION/SEMESTRE 1/1. Tratamiento de datos/Clase 5 Raster/Img_col_precip/", full.names = TRUE)
print(img_precip)
## [1] "D:/ESPECIALIZACION/SEMESTRE 1/1. Tratamiento de datos/Clase 5 Raster/Img_col_precip/wc2.1_10m_colo_prec_01.tif"
## [2] "D:/ESPECIALIZACION/SEMESTRE 1/1. Tratamiento de datos/Clase 5 Raster/Img_col_precip/wc2.1_10m_colo_prec_02.tif"
## [3] "D:/ESPECIALIZACION/SEMESTRE 1/1. Tratamiento de datos/Clase 5 Raster/Img_col_precip/wc2.1_10m_colo_prec_03.tif"
## [4] "D:/ESPECIALIZACION/SEMESTRE 1/1. Tratamiento de datos/Clase 5 Raster/Img_col_precip/wc2.1_10m_colo_prec_04.tif"
## [5] "D:/ESPECIALIZACION/SEMESTRE 1/1. Tratamiento de datos/Clase 5 Raster/Img_col_precip/wc2.1_10m_colo_prec_05.tif"
## [6] "D:/ESPECIALIZACION/SEMESTRE 1/1. Tratamiento de datos/Clase 5 Raster/Img_col_precip/wc2.1_10m_colo_prec_06.tif"
## [7] "D:/ESPECIALIZACION/SEMESTRE 1/1. Tratamiento de datos/Clase 5 Raster/Img_col_precip/wc2.1_10m_colo_prec_07.tif"
## [8] "D:/ESPECIALIZACION/SEMESTRE 1/1. Tratamiento de datos/Clase 5 Raster/Img_col_precip/wc2.1_10m_colo_prec_08.tif"
## [9] "D:/ESPECIALIZACION/SEMESTRE 1/1. Tratamiento de datos/Clase 5 Raster/Img_col_precip/wc2.1_10m_colo_prec_09.tif"
## [10] "D:/ESPECIALIZACION/SEMESTRE 1/1. Tratamiento de datos/Clase 5 Raster/Img_col_precip/wc2.1_10m_colo_prec_10.tif"
## [11] "D:/ESPECIALIZACION/SEMESTRE 1/1. Tratamiento de datos/Clase 5 Raster/Img_col_precip/wc2.1_10m_colo_prec_11.tif"
## [12] "D:/ESPECIALIZACION/SEMESTRE 1/1. Tratamiento de datos/Clase 5 Raster/Img_col_precip/wc2.1_10m_colo_prec_12.tif"
precipitacion=stack(img_precip) # crea varias raster
precip_anual=sum(precipitacion) # suma todos los raster del stack en una solo raster
plot(precip_anual)

# Altitud
altitud= raster("D:/ESPECIALIZACION/SEMESTRE 1/1. Tratamiento de datos/Clase 5 Raster/Img_col_altitud/wc2.1_10m_col_elev.tif")
plot(altitud)

# Consulta: muestre de temp entre 17°y 23°C
temp_cafe=promedio_temp>17&promedio_temp<23 # mapa de 0 y 1
plot(temp_cafe)

# Consulta: muestre las precipitaciones entre 1800 y 2000 mm
precip_cafe=precip_anual>1800&precip_anual<2000 # mapa de 0 y 1
plot(precip_cafe)

# Consulta:muestre altitud entre 1200 y 1800 msnm
alt_cafe=altitud>1200&altitud<1800 # mapa de 0 y 1
plot(alt_cafe)

# Consulta: muestre zonas aptas cultivo cafe en temperatura y precipitacion
zonas_op_cafe= precip_cafe + temp_cafe # suma tres condiciones
plot(zonas_op_cafe, xlab="Longuitud", ylab = "Latitud", main="Zonas aptas de temperatura y precipitacion para el cultivo de café")

# Consulta: muestre zonas aptas cultivo cafe en temperatura, precipitacion y altitud
zonas_op_cafe= precip_cafe + temp_cafe + alt_cafe # suma tres condiciones
plot(zonas_op_cafe, xlab="Longuitud", ylab = "Latitud", main="Zonas aptas de temperatura y precipitacion y altitud para el cultivo de café")
