require(raster)
## Loading required package: raster
## Loading required package: sp
comunas=shapefile("C:/Users/Andres/Desktop/ESPECIALIZACION/1ER SEMESTRE/TRATAMIENTO DE DATOS ESPACIALES/CLASE12/YDRAY-Comuna.shp")
plot(comunas)

temp_1=raster("C:/Users/Andres/Desktop/ESPECIALIZACION/1ER SEMESTRE/TRATAMIENTO DE DATOS ESPACIALES/CLASE5/wc2.1_10m_tavg_01.tif")
temp_1
## class : RasterLayer
## dimensions : 1080, 2160, 2332800 (nrow, ncol, ncell)
## resolution : 0.1666667, 0.1666667 (x, y)
## extent : -180, 180, -90, 90 (xmin, xmax, ymin, ymax)
## crs : +proj=longlat +datum=WGS84 +no_defs
## source : C:/Users/Andres/Desktop/ESPECIALIZACION/1ER SEMESTRE/TRATAMIENTO DE DATOS ESPACIALES/CLASE5/wc2.1_10m_tavg_01.tif
## names : wc2.1_10m_tavg_01
## values : -45.884, 34.0095 (min, max)
plot(temp_1)

x=data.frame(temp_1[])
hist(x$temp_1..)

temp1_cana=temp_1>20&temp_1<30
plot(temp1_cana)

temp_7=raster("C:/Users/Andres/Desktop/ESPECIALIZACION/1ER SEMESTRE/TRATAMIENTO DE DATOS ESPACIALES/CLASE5/wc2.1_10m_tavg_07.tif")
plot(temp_7)

temp_all=stack(temp_1,temp_7)
plot(temp_all)

temp_all_cana=temp_all>20&temp_all<30
plot(temp_all_cana)

coord=cbind(-104.451925,47.899845)
plot(comunas)
points(coord,col="red")

extract(temp_1,coord)
##
## -11.09975
extract(temp_all,coord)
## wc2.1_10m_tavg_01 wc2.1_10m_tavg_07
## [1,] -11.09975 21.989
extract(temp_all_cana,coord)
## wc2.1_10m_tavg_01 wc2.1_10m_tavg_07
## [1,] FALSE TRUE
plot(temp_all_cana)

temp_all_cana=temp_all>20&temp_all<30
temp_all_suma=sum(temp_all_cana)
plot(temp_all_suma)

archivos=list.files("C:/Users/Andres/Desktop/ESPECIALIZACION/1ER SEMESTRE/TRATAMIENTO DE DATOS ESPACIALES/CLASE5/",full.names = TRUE,pattern = ".tif")
temp_year=stack(archivos)
plot(temp_year)

temp_all2=temp_year>20&temp_year<30
names(temp_all2)=month.name
plot(temp_all2)

indicador=sum(temp_all2)
indicador
## class : RasterLayer
## dimensions : 1080, 2160, 2332800 (nrow, ncol, ncell)
## resolution : 0.1666667, 0.1666667 (x, y)
## extent : -180, 180, -90, 90 (xmin, xmax, ymin, ymax)
## crs : +proj=longlat +datum=WGS84 +no_defs
## source : C:/Users/Andres/AppData/Local/Temp/RtmpeowkjH/raster/r_tmp_2020-12-07_190214_1504_62248.grd
## names : layer
## values : 0, 12 (min, max)
plot(indicador)
