library(raster)
## Loading required package: sp
library(rgdal)
## rgdal: version: 1.5-16, (SVN revision 1050)
## Geospatial Data Abstraction Library extensions to R successfully loaded
## Loaded GDAL runtime: GDAL 3.0.4, released 2020/01/28
## Path to GDAL shared files: C:/Users/Mauricio/Documents/R/win-library/3.6/rgdal/gdal
## GDAL binary built with GEOS: TRUE 
## Loaded PROJ runtime: Rel. 6.3.1, February 10th, 2020, [PJ_VERSION: 631]
## Path to PROJ shared files: C:\Program Files (x86)\MapWindow\PROJ_NAD
## Linking to sp version:1.4-2
## To mute warnings of possible GDAL/OSR exportToProj4() degradation,
## use options("rgdal_show_exportToProj4_warnings"="none") before loading rgdal.
## Overwritten PROJ_LIB was C:\Program Files (x86)\MapWindow\PROJ_NAD
library(tidyverse)
## -- Attaching packages ------------------------------- tidyverse 1.3.0 --
## v ggplot2 3.3.2     v purrr   0.3.4
## v tibble  3.0.3     v dplyr   1.0.2
## v tidyr   1.1.2     v stringr 1.4.0
## v readr   1.3.1     v forcats 0.5.0
## -- Conflicts ---------------------------------- tidyverse_conflicts() --
## x tidyr::extract() masks raster::extract()
## x dplyr::filter()  masks stats::filter()
## x dplyr::lag()     masks stats::lag()
## x dplyr::select()  masks raster::select()
library(gtools)
library(rgeos)
## rgeos version: 0.5-5, (SVN revision 640)
##  GEOS runtime version: 3.8.0-CAPI-1.13.1 
##  Linking to sp version: 1.4-2 
##  Polygon checking: TRUE
## cargamos el raster de alturas muindiales
altura_col= raster("~/Especializacion_geomatica/Tratamiento_de_datos_espaciales/Clase5/Elevacion/Col_elev.tif")
plot(altura_col, main= "Altura Colombia", xlab = "Longitud (°)", ylab = "Latitud (°)")

##cargamos el shapefile
Colombia=shapefile("~/Especializacion_geomatica/Tratamiento_de_datos_espaciales/Clase5/Colombia.shp")
plot(Colombia)

## Realizamos la condición de alturas para zonas de paramo
alt_paramo=altura_col>2800&altura_col<4600
## Plot para variable altura
plot(alt_paramo, main= "Altura Páramos msnm", xlab = "Longitud (°)", ylab = "Latitud (°)")

##Importar datos de temperatura
getwd()
## [1] "C:/Users/Mauricio/Documents/Especializacion_geomatica/Tratamiento_de_datos_espaciales/Clase5"
setwd("~/Especializacion_geomatica/Tratamiento_de_datos_espaciales/Clase5/")

ctemp1= raster("col_temp1.tif")
ctemp2= raster("col_temp2.tif")
ctemp3= raster("col_temp3.tif")
ctemp4= raster("col_temp4.tif")
ctemp5= raster("col_temp5.tif")
ctemp6= raster("col_temp6.tif")
ctemp7= raster("col_temp7.tif")
ctemp8= raster("col_temp8.tif")
ctemp9= raster("col_temp9.tif")
ctemp10= raster("col_temp10.tif")
ctemp11= raster("col_temp11.tif")
ctemp12= raster("col_temp12.tif")

##realizar el promedio de Temperatura multianual

Col_tem_all= ((ctemp1+ctemp2+ctemp3+ctemp4+ctemp5+ctemp6+ctemp7+ctemp8+ctemp9+ctemp10+ctemp11+ctemp12)/12)
Col_tem_all
## class      : RasterLayer 
## dimensions : 101, 89, 8989  (nrow, ncol, ncell)
## resolution : 0.1666667, 0.1666667  (x, y)
## extent     : -81.72015, -66.88681, -4.236874, 12.59646  (xmin, xmax, ymin, ymax)
## crs        : +proj=longlat +datum=WGS84 +no_defs 
## source     : memory
## names      : layer 
## values     : 3.913625, 29.38944  (min, max)
plot(Col_tem_all, main= "Temp promedio multianual °C", xlab = "Longitud (°)", ylab = "Latitud (°)")

# Ejecutamos la condicion de temperatura
temparamo=Col_tem_all>3&Col_tem_all<13
# plot para la variable temperatura
plot(temparamo, main= "Temperatura °C Páramos", xlab = "Longitud (°)", ylab = "Latitud (°)")

#Condicion sumatoria entre 2 variables

aptitud_par = (alt_paramo+temparamo)
plot(aptitud_par, ,main= "Aptitud Biofísica Para Zonas de Páramos Alt+Temp", xlab = "Longitud (°)", ylab = "Latitud (°)")
plot(Colombia, add=TRUE, border = "blue", lwd = 2,  axes = TRUE)

# plor en el resulado integrado y configuramos el color